3 class LocaleTest < ActiveSupport::TestCase
5 EN_GB = Locale.new("en", nil, "GB")
7 ZH_HANS = Locale.new("zh", "Hans")
8 ZH_HANT_TW = Locale.new("zh", "Hant", "TW")
9 ZH_YUE = Locale.new("zh-yue")
10 BE_TARASK = Locale.new("be", nil, nil, "tarask")
13 assert_equal EN, Locale.tag("en")
14 assert_equal EN_GB, Locale.tag("en-GB")
15 assert_equal FR, Locale.tag("fr")
16 assert_equal ZH_HANS, Locale.tag("zh-Hans")
17 assert_equal ZH_HANT_TW, Locale.tag("zh-Hant-TW")
18 assert_equal ZH_YUE, Locale.tag("zh-yue")
19 assert_equal BE_TARASK, Locale.tag("be-tarask")
23 assert_equal EN.language, Locale.tag("en").language
24 assert_equal EN_GB.language, Locale.tag("en-GB").language
25 assert_equal FR.language, Locale.tag("fr").language
26 assert_equal ZH_HANS.language, Locale.tag("zh-Hans").language
27 assert_equal ZH_HANT_TW.language, Locale.tag("zh-Hant-TW").language
28 assert_equal ZH_YUE.language, Locale.tag("zh-yue").language
29 assert_equal ZH_YUE.language, Locale.tag("zh-YUE").language
30 assert_equal BE_TARASK.language, Locale.tag("be-tarask").language
31 assert_equal BE_TARASK.language, Locale.tag("be-Tarask").language
35 assert_equal_allowing_nil EN.script, Locale.tag("en").script
36 assert_equal_allowing_nil EN_GB.script, Locale.tag("en-GB").script
37 assert_equal_allowing_nil FR.script, Locale.tag("fr").script
38 assert_equal_allowing_nil ZH_HANS.script, Locale.tag("zh-Hans").script
39 assert_equal_allowing_nil ZH_HANT_TW.script, Locale.tag("zh-Hant-TW").script
40 assert_equal_allowing_nil ZH_YUE.script, Locale.tag("zh-yue").script
41 assert_equal_allowing_nil ZH_YUE.script, Locale.tag("zh-YUE").script
42 assert_equal_allowing_nil BE_TARASK.script, Locale.tag("be-tarask").script
43 assert_equal_allowing_nil BE_TARASK.script, Locale.tag("be-Tarask").script
47 assert_equal_allowing_nil EN.region, Locale.tag("en").region
48 assert_equal_allowing_nil EN_GB.region, Locale.tag("en-GB").region
49 assert_equal_allowing_nil FR.region, Locale.tag("fr").region
50 assert_equal_allowing_nil ZH_HANS.region, Locale.tag("zh-Hans").region
51 assert_equal_allowing_nil ZH_HANT_TW.region, Locale.tag("zh-Hant-TW").region
52 assert_equal_allowing_nil ZH_YUE.region, Locale.tag("zh-yue").region
53 assert_equal_allowing_nil ZH_YUE.region, Locale.tag("zh-YUE").region
54 assert_equal_allowing_nil BE_TARASK.region, Locale.tag("be-tarask").region
55 assert_equal_allowing_nil BE_TARASK.region, Locale.tag("be-Tarask").region
59 assert_equal_allowing_nil EN.variant, Locale.tag("en").variant
60 assert_equal_allowing_nil EN_GB.variant, Locale.tag("en-GB").variant
61 assert_equal_allowing_nil FR.variant, Locale.tag("fr").variant
62 assert_equal_allowing_nil ZH_HANS.variant, Locale.tag("zh-Hans").variant
63 assert_equal_allowing_nil ZH_HANT_TW.variant, Locale.tag("zh-Hant-TW").variant
64 assert_equal_allowing_nil ZH_YUE.variant, Locale.tag("zh-yue").variant
65 assert_equal_allowing_nil ZH_YUE.variant, Locale.tag("zh-YUE").variant
66 assert_equal_allowing_nil BE_TARASK.variant, Locale.tag("be-tarask").variant
67 assert_equal_allowing_nil BE_TARASK.variant, Locale.tag("be-Tarask").variant
71 assert_equal [], Locale.list
72 assert_equal [EN], Locale.list("en")
73 assert_equal [EN, ZH_YUE, ZH_HANT_TW], Locale.list("en", "zh-yue", "zh-Hant-TW")
74 assert_equal [ZH_YUE, ZH_HANT_TW], Locale.list("en;de", "zh-yue", "zh-Hant-TW")
75 assert_equal [ZH_YUE, ZH_HANT_TW], Locale.list(["en;de", "zh-yue", "zh-Hant-TW"])
79 assert_equal EN, Locale.default
83 assert Locale.available.count <= I18n.available_locales.count
87 assert_equal "en-GB", Locale.available.preferred(Locale.list("en-GB", "en")).to_s
88 assert_equal "en", Locale.available.preferred(Locale.list("en")).to_s
89 assert_equal "fr", Locale.available.preferred(Locale.list("fr-GB", "fr", "en")).to_s
90 assert_equal "fr", Locale.available.preferred(Locale.list("fr", "en")).to_s
91 assert_equal "de", Locale.available.preferred(Locale.list("zh-Hant", "de")).to_s
92 assert_equal "zh-TW", Locale.available.preferred(Locale.list("zh-Hant-TW", "de")).to_s
93 assert_equal "zh-TW", Locale.available.preferred(Locale.list("zh-TW", "de")).to_s
94 assert_equal "zh-HK", Locale.available.preferred(Locale.list("zh-HK", "zh-hk", "zh-Hant", "zh-hant", "zh-TW", "zh-tw", "zh", "zh-yue", "yue", "yue-Hant", "yue-HK", "yue-Hans", "zh-classical", "lzh", "ja-Hani", "ko-Hani", "ko_hanja", "vi-Hani", "ja-hani", "ko-hani", "vi-hani", "en-HK", "en-hk", "en-SG", "en-sg", "en-GB", "en-gb", "en-US", "en-us", "en", "ja")).to_s
95 assert_equal "en", Locale.available.preferred(Locale.list("yue")).to_s