-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Smarter default language detection (#26)
- Loading branch information
Showing
9 changed files
with
299 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
-- http://tools.ietf.org/html/rfc5646 | ||
|
||
return { | ||
"af", | ||
"af-ZA", | ||
"ar", | ||
"ar-AE", | ||
"ar-BH", | ||
"ar-DZ", | ||
"ar-EG", | ||
"ar-IQ", | ||
"ar-JO", | ||
"ar-KW", | ||
"ar-LB", | ||
"ar-LY", | ||
"ar-MA", | ||
"ar-OM", | ||
"ar-QA", | ||
"ar-SA", | ||
"ar-SY", | ||
"ar-TN", | ||
"ar-YE", | ||
"az", | ||
"az-AZ", | ||
"az-Cyrl-AZ", | ||
"be", | ||
"be-BY", | ||
"bg", | ||
"bg-BG", | ||
"bs-BA", | ||
"ca", | ||
"ca-ES", | ||
"cs", | ||
"cs-CZ", | ||
"cy", | ||
"cy-GB", | ||
"da", | ||
"da-DK", | ||
"de", | ||
"de-AT", | ||
"de-CH", | ||
"de-DE", | ||
"de-LI", | ||
"de-LU", | ||
"dv", | ||
"dv-MV", | ||
"el", | ||
"el-GR", | ||
"en", | ||
"en-AU", | ||
"en-BZ", | ||
"en-CA", | ||
"en-CB", | ||
"en-GB", | ||
"en-IE", | ||
"en-JM", | ||
"en-NZ", | ||
"en-PH", | ||
"en-TT", | ||
"en-US", | ||
"en-ZA", | ||
"en-ZW", | ||
"eo", | ||
"es", | ||
"es-AR", | ||
"es-BO", | ||
"es-CL", | ||
"es-CO", | ||
"es-CR", | ||
"es-DO", | ||
"es-EC", | ||
"es-ES", | ||
"es-GT", | ||
"es-HN", | ||
"es-MX", | ||
"es-NI", | ||
"es-PA", | ||
"es-PE", | ||
"es-PR", | ||
"es-PY", | ||
"es-SV", | ||
"es-UY", | ||
"es-VE", | ||
"et", | ||
"et-EE", | ||
"eu", | ||
"eu-ES", | ||
"fa", | ||
"fa-IR", | ||
"fi", | ||
"fi-FI", | ||
"fo", | ||
"fo-FO", | ||
"fr", | ||
"fr-BE", | ||
"fr-CA", | ||
"fr-CH", | ||
"fr-FR", | ||
"fr-LU", | ||
"fr-MC", | ||
"gl", | ||
"gl-ES", | ||
"gu", | ||
"gu-IN", | ||
"he", | ||
"he-IL", | ||
"hi", | ||
"hi-IN", | ||
"hr", | ||
"hr-BA", | ||
"hr-HR", | ||
"hu", | ||
"hu-HU", | ||
"hy", | ||
"hy-AM", | ||
"id", | ||
"id-ID", | ||
"is", | ||
"is-IS", | ||
"it", | ||
"it-CH", | ||
"it-IT", | ||
"ja", | ||
"ja-JP", | ||
"ka", | ||
"ka-GE", | ||
"kk", | ||
"kk-KZ", | ||
"kn", | ||
"kn-IN", | ||
"ko", | ||
"ko-KR", | ||
"kok", | ||
"kok-IN", | ||
"ky", | ||
"ky-KG", | ||
"lt", | ||
"lt-LT", | ||
"lv", | ||
"lv-LV", | ||
"mi", | ||
"mi-NZ", | ||
"mk", | ||
"mk-MK", | ||
"mn", | ||
"mn-MN", | ||
"mr", | ||
"mr-IN", | ||
"ms", | ||
"ms-BN", | ||
"ms-MY", | ||
"mt", | ||
"mt-MT", | ||
"nb", | ||
"nb-NO", | ||
"nl", | ||
"nl-BE", | ||
"nl-NL", | ||
"nn-NO", | ||
"ns", | ||
"ns-ZA", | ||
"pa", | ||
"pa-IN", | ||
"pl", | ||
"pl-PL", | ||
"ps", | ||
"ps-AR", | ||
"pt", | ||
"pt-BR", | ||
"pt-PT", | ||
"qu", | ||
"qu-BO", | ||
"qu-EC", | ||
"qu-PE", | ||
"ro", | ||
"ro-RO", | ||
"ru", | ||
"ru-RU", | ||
"sa", | ||
"sa-IN", | ||
"se", | ||
"se-FI", | ||
"se-NO", | ||
"se-SE", | ||
"sk", | ||
"sk-SK", | ||
"sl", | ||
"sl-SI", | ||
"sq", | ||
"sq-AL", | ||
"sr-BA", | ||
"sr-Cyrl-BA", | ||
"sr-SP", | ||
"sr-Cyrl-SP", | ||
"sv", | ||
"sv-FI", | ||
"sv-SE", | ||
"sw", | ||
"sw-KE", | ||
"syr", | ||
"syr-SY", | ||
"ta", | ||
"ta-IN", | ||
"te", | ||
"te-IN", | ||
"th", | ||
"th-TH", | ||
"tl", | ||
"tl-PH", | ||
"tn", | ||
"tn-ZA", | ||
"tr", | ||
"tr-TR", | ||
"tt", | ||
"tt-RU", | ||
"ts", | ||
"uk", | ||
"uk-UA", | ||
"ur", | ||
"ur-PK", | ||
"uz", | ||
"uz-UZ", | ||
"uz-Cyrl-UZ", | ||
"vi", | ||
"vi-VN", | ||
"xh", | ||
"xh-ZA", | ||
"zh", | ||
"zh-CN", | ||
"zh-HK", | ||
"zh-MO", | ||
"zh-SG", | ||
"zh-TW", | ||
"zu", | ||
"zu-ZA", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local config = require("js-i18n.config") | ||
|
||
describe("js-i18n.config", function() | ||
describe("default_detect_language", function() | ||
local tests = { | ||
{ path = "/path/to/locals/en/trans.json", expected = "en" }, | ||
{ path = "/path/to/locals/ja/trans.json", expected = "ja" }, | ||
{ path = "/path/to/locals/hoge/trans.json", expected = nil }, | ||
|
||
-- Test cases to verify that it is sufficient for the languagee name to be included somewhere. | ||
{ path = "/path/to/locals/sub/en.json", expected = "en" }, | ||
{ path = "/path/to/en/locals/trans.json", expected = "en" }, | ||
{ path = "/path/to/locals/en-trans.json", expected = nil }, | ||
|
||
-- Test cases for language names with any case and separating characters. | ||
{ path = "/path/to/locals/en-us/trans.json", expected = "en-us" }, | ||
{ path = "/path/to/locals/en_us/trans.json", expected = "en_us" }, | ||
{ path = "/path/to/locals/en-US/trans.json", expected = "en-US" }, | ||
|
||
-- Test cases where the last match is returned when multiple locale names are included. | ||
{ path = "/path/to/locals/en/ja.json", expected = "ja" }, | ||
} | ||
|
||
for _, test in ipairs(tests) do | ||
it( | ||
string.format("should return %q when detecting language from %q", test.expected, test.path), | ||
function() | ||
assert.are.equal(test.expected, config.default_detect_language(test.path)) | ||
end | ||
) | ||
end | ||
end) | ||
end) |
File renamed without changes.
File renamed without changes.