theoooo-i18n 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: version 0.0.1\n"
10
+ "POT-Creation-Date: 2009-02-26 19:50+0100\n"
11
+ "PO-Revision-Date: 2009-02-18 14:53+0100\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ # #: app/helpers/translation_helper.rb:3
20
+ # msgid "%{relative_time} ago"
21
+ # msgstr "vor %{relative_time}"
22
+
23
+ #: app/views/cars/show.html.erb:5
24
+ msgid "Axis"
25
+ msgid_plural "Axis"
26
+ msgstr[0] "Achse"
27
+ msgstr[1] "Achsen"
28
+
29
+ #: app/controllers/cars_controller.rb:47
30
+ msgid "Car was successfully created."
31
+ msgstr "Auto wurde erfolgreich gespeichert"
32
+
33
+ #: app/controllers/cars_controller.rb:64
34
+ msgid "Car was successfully updated."
35
+ msgstr "Auto wurde erfolgreich aktualisiert"
36
+
37
+ #: app/views/cars/show.html.erb:1 locale/model_attributes.rb:3
38
+ msgid "Car|Model"
39
+ msgstr "Modell"
40
+
41
+ #: app/views/cars/show.html.erb:3 locale/model_attributes.rb:4
42
+ msgid "Car|Wheels count"
43
+ msgstr "Räderzahl"
44
+
45
+ #: app/views/cars/show.html.erb:7
46
+ msgid "Created"
47
+ msgstr "Erstellt"
48
+
49
+ #: app/views/cars/show.html.erb:9
50
+ msgid "Month"
51
+ msgstr "Monat"
52
+
53
+ #: locale/model_attributes.rb:2
54
+ msgid "car"
55
+ msgstr "Auto"
56
+
57
+ #: locale/testlog_phrases.rb:2
58
+ msgid "this is a dynamic translation which was found thorugh gettext_test_log!"
59
+ msgstr ""
60
+ "Dies ist eine dynamische Übersetzung, die durch gettext_test_log "
61
+ "gefunden wurde!"
@@ -0,0 +1,110 @@
1
+ {
2
+ :af => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
3
+ :am => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
4
+ :ar => { :i18n => { :pluralize => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : (3..10).include?(n % 100) ? :few : (11..99).include?(n % 100) ? :many : :other } } },
5
+ :az => { :i18n => { :pluralize => lambda { |n| :other } } },
6
+ :be => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
7
+ :bg => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
8
+ :bh => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
9
+ :bn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
10
+ :bo => { :i18n => { :pluralize => lambda { |n| :other } } },
11
+ :bs => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
12
+ :ca => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
13
+ :cs => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n) ? :few : :other } } },
14
+ :cy => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } },
15
+ :da => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
16
+ :de => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
17
+ :dz => { :i18n => { :pluralize => lambda { |n| :other } } },
18
+ :el => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
19
+ :en => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
20
+ :eo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
21
+ :es => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
22
+ :et => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
23
+ :eu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
24
+ :fa => { :i18n => { :pluralize => lambda { |n| :other } } },
25
+ :fi => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
26
+ :fil => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
27
+ :fo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
28
+ :fr => { :i18n => { :pluralize => lambda { |n| n && n != 2 ? :one : :other } } },
29
+ :fur => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
30
+ :fy => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
31
+ :ga => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
32
+ :gl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
33
+ :gu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
34
+ :guw => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
35
+ :ha => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
36
+ :he => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
37
+ :hi => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
38
+ :hr => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
39
+ :hu => { :i18n => { :pluralize => lambda { |n| :other } } },
40
+ :id => { :i18n => { :pluralize => lambda { |n| :other } } },
41
+ :is => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
42
+ :it => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
43
+ :iw => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
44
+ :ja => { :i18n => { :pluralize => lambda { |n| :other } } },
45
+ :jv => { :i18n => { :pluralize => lambda { |n| :other } } },
46
+ :ka => { :i18n => { :pluralize => lambda { |n| :other } } },
47
+ :km => { :i18n => { :pluralize => lambda { |n| :other } } },
48
+ :kn => { :i18n => { :pluralize => lambda { |n| :other } } },
49
+ :ko => { :i18n => { :pluralize => lambda { |n| :other } } },
50
+ :ku => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
51
+ :lb => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
52
+ :ln => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
53
+ :lt => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && !(11..19).include?(n % 100) ? :one : (2..9).include?(n % 10) && !(11..19).include?(n % 100) ? :few : :other } } },
54
+ :lv => { :i18n => { :pluralize => lambda { |n| n == 0 ? :zero : n % 10 == 1 && n % 100 != 11 ? :one : :other } } },
55
+ :mg => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
56
+ :mk => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 ? :one : :other } } },
57
+ :ml => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
58
+ :mn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
59
+ :mo => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } },
60
+ :mr => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
61
+ :ms => { :i18n => { :pluralize => lambda { |n| :other } } },
62
+ :mt => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other } } },
63
+ :my => { :i18n => { :pluralize => lambda { |n| :other } } },
64
+ :nah => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
65
+ :nb => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
66
+ :ne => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
67
+ :nl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
68
+ :nn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
69
+ :no => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
70
+ :nso => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
71
+ :om => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
72
+ :or => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
73
+ :pa => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
74
+ :pap => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
75
+ :pl => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) && !(22..24).include?(n % 100) ? :few : :other } } },
76
+ :ps => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
77
+ :pt => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
78
+ :"pt-PT" => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
79
+ :ro => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 0 ? :few : :other } } },
80
+ :ru => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
81
+ :se => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
82
+ :sh => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
83
+ :sk => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : (2..4).include?(n) ? :few : :other } } },
84
+ :sl => { :i18n => { :pluralize => lambda { |n| n % 100 == 1 ? :one : n % 100 == 2 ? :two : (3..4).include?(n % 100) ? :few : :other } } },
85
+ :sma => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
86
+ :smi => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
87
+ :smj => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
88
+ :smn => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
89
+ :sms => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : n == 2 ? :two : :other } } },
90
+ :so => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
91
+ :sq => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
92
+ :sr => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
93
+ :sv => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
94
+ :sw => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
95
+ :ta => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
96
+ :te => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
97
+ :th => { :i18n => { :pluralize => lambda { |n| :other } } },
98
+ :ti => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
99
+ :tk => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
100
+ :tl => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
101
+ :to => { :i18n => { :pluralize => lambda { |n| :other } } },
102
+ :tr => { :i18n => { :pluralize => lambda { |n| :other } } },
103
+ :uk => { :i18n => { :pluralize => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } } },
104
+ :ur => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } },
105
+ :vi => { :i18n => { :pluralize => lambda { |n| :other } } },
106
+ :wa => { :i18n => { :pluralize => lambda { |n| (0..1).include?(n) ? :one : :other } } },
107
+ :yo => { :i18n => { :pluralize => lambda { |n| :other } } },
108
+ :zh => { :i18n => { :pluralize => lambda { |n| :other } } },
109
+ :zu => { :i18n => { :pluralize => lambda { |n| n == 1 ? :one : :other } } }
110
+ }
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'i18n/backend/gettext'
3
+ require 'i18n/helpers/gettext'
4
+
5
+ include I18n::Helpers::Gettext
6
+
7
+ class I18nGettextApiTest < Test::Unit::TestCase
8
+ def setup
9
+ I18n.locale = :en
10
+ I18n.backend.store_translations :de, {
11
+ 'Hi Gettext!' => 'Hallo Gettext!',
12
+ 'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
13
+ "An apple#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} apples" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
14
+ :special => { 'An apple' => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
15
+ :foo => { :bar => { :baz => 'baz-de' } }
16
+ }
17
+ end
18
+
19
+ def test_helper_uses_msg_as_default
20
+ assert_equal 'Hi Gettext!', _('Hi Gettext!')
21
+ end
22
+
23
+ def test_helper_uses_msg_as_key
24
+ I18n.locale = :de
25
+ assert_equal 'Hallo Gettext!', _('Hi Gettext!')
26
+ end
27
+
28
+ def test_helper_uses_msg_containing_dots_as_default
29
+ assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
30
+ end
31
+
32
+ def test_helper_uses_msg_containing_dots_as_key
33
+ I18n.locale = :de
34
+ assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
35
+ end
36
+
37
+ def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
38
+ assert_equal 'baz', sgettext('foo|bar|baz')
39
+ end
40
+
41
+ def test_sgettext_looks_up_a_scoped_translation
42
+ I18n.locale = :de
43
+ assert_equal 'baz-de', sgettext('foo|bar|baz')
44
+ end
45
+
46
+ def test_pgettext_defaults_to_msgid
47
+ assert_equal 'baz', pgettext('foo|bar', 'baz', '|')
48
+ end
49
+
50
+ def test_pgettext_looks_up_a_scoped_translation
51
+ I18n.locale = :de
52
+ assert_equal 'baz-de', pgettext('foo|bar', 'baz', '|')
53
+ end
54
+
55
+ def test_ngettext_looks_up_msg_id_as_default_singular
56
+ assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
57
+ end
58
+
59
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural
60
+ assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
61
+ end
62
+
63
+ def test_ngettext_looks_up_msg_id_as_singular
64
+ I18n.locale = :de
65
+ assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
66
+ end
67
+
68
+ def test_ngettext_looks_up_msg_id_as_singular
69
+ I18n.locale = :de
70
+ assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
71
+ end
72
+
73
+ def test_nsgettext_looks_up_msg_id_as_default_singular
74
+ assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1, '|')
75
+ end
76
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+ require 'i18n/backend/gettext'
3
+ require 'i18n/helpers/gettext'
4
+
5
+ include I18n::Helpers::Gettext
6
+
7
+ class I18nGettextBackendTest < Test::Unit::TestCase
8
+ def setup
9
+ I18n.locale = :en
10
+ I18n.load_path = [locales_dir + '/de.po']
11
+ I18n.backend.meta_class.send(:include, I18n::Backend::Gettext)
12
+ end
13
+
14
+ def teardown
15
+ I18n.load_path = nil
16
+ I18n.backend = nil
17
+ end
18
+
19
+ def test_backend_loads_po_file
20
+ I18n.backend.send(:init_translations)
21
+ assert I18n.backend.send(:translations)[:de][:"Axis\001Axis"]
22
+ end
23
+
24
+ def test_looks_up_translation
25
+ I18n.locale = :de
26
+ assert_equal 'Auto', _('car')
27
+ end
28
+
29
+ def test_pluralizes_entry
30
+ I18n.locale = :de
31
+ assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
32
+ end
33
+ end
@@ -0,0 +1,126 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+ require 'i18n/locale/fallbacks'
3
+ require 'i18n/locale/tag'
4
+
5
+ include I18n::Locale
6
+
7
+ class I18nFallbacksDefaultsTest < Test::Unit::TestCase
8
+ def teardown
9
+ I18n.default_locale = :en
10
+ end
11
+
12
+ test "defaults reflect the I18n.default_locale if no default has been set manually" do
13
+ I18n.default_locale = :'en-US'
14
+ I18n.fallbacks = Fallbacks.new
15
+ assert_equal [:'en-US', :en], I18n.fallbacks.defaults
16
+ end
17
+
18
+ test "defaults reflect a manually passed default locale if any" do
19
+ I18n.fallbacks = Fallbacks.new(:'fi-FI')
20
+ assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
21
+ I18n.default_locale = :'de-DE'
22
+ assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
23
+ end
24
+
25
+ test "defaults allows to set multiple defaults" do
26
+ I18n.fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
27
+ assert_equal [:'fi-FI', :fi, :'se-FI', :se], I18n.fallbacks.defaults
28
+ end
29
+ end
30
+
31
+ class I18nFallbacksComputationTest < Test::Unit::TestCase
32
+ def setup
33
+ @fallbacks = Fallbacks.new(:'en-US')
34
+ end
35
+
36
+ test "with no mappings defined it returns [:es, :en-US] for :es" do
37
+ assert_equal [:es, :"en-US", :en], @fallbacks[:es]
38
+ end
39
+
40
+ test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
41
+ assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
42
+ end
43
+
44
+ test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
45
+ assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
46
+ end
47
+
48
+ test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
49
+ assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
50
+ end
51
+
52
+ test "with no mappings defined it returns [:en, :en-US] for :en" do
53
+ assert_equal [:en, :"en-US"], @fallbacks[:en]
54
+ end
55
+
56
+ test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
57
+ assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
58
+ end
59
+
60
+ # Most people who speak Catalan also live in Spain, so it is safe to assume
61
+ # that they also speak Spanish as spoken in Spain.
62
+ test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
63
+ @fallbacks.map(:ca => :"es-ES")
64
+ assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
65
+ end
66
+
67
+ test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
68
+ @fallbacks.map(:ca => :"es-ES")
69
+ assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
70
+ end
71
+
72
+ # People who speak Arabic as spoken in Palestine often times also speak
73
+ # Hebrew as spoken in Israel. However it is in no way safe to assume that
74
+ # everybody who speaks Arabic also speaks Hebrew.
75
+
76
+ test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
77
+ @fallbacks.map(:"ar-PS" => :"he-IL")
78
+ assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
79
+ end
80
+
81
+ test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
82
+ @fallbacks.map(:"ar-PS" => :"he-IL")
83
+ assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
84
+ end
85
+
86
+ test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
87
+ @fallbacks.map(:"ar-PS" => :"he-IL")
88
+ assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
89
+ end
90
+
91
+ # Sami people live in several scandinavian countries. In Finnland many people
92
+ # know Swedish and Finnish. Thus, it can be assumed that Sami living in
93
+ # Finnland also speak Swedish and Finnish.
94
+
95
+ test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
96
+ @fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
97
+ assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
98
+ end
99
+
100
+ # Austrian people understand German as spoken in Germany
101
+
102
+ test "with a German mapping defined it returns [:de, :en-US] for de" do
103
+ @fallbacks.map(:"de-AT" => :"de-DE")
104
+ assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
105
+ end
106
+
107
+ test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
108
+ @fallbacks.map(:"de-AT" => :"de-DE")
109
+ assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
110
+ end
111
+
112
+ test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
113
+ @fallbacks.map(:"de-AT" => :"de-DE")
114
+ assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
115
+ end
116
+
117
+ # Mapping :de => :en, :he => :en
118
+
119
+ test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
120
+ assert_equal [:de, :"en-US", :en], @fallbacks[:de]
121
+ end
122
+
123
+ test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
124
+ assert_equal [:he, :"en-US", :en], @fallbacks[:he]
125
+ end
126
+ end
@@ -0,0 +1,145 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
+ require 'i18n/locale/tag'
3
+ require 'i18n/locale/tag/rfc4646'
4
+
5
+ # Rfc4646::Parser
6
+
7
+ class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
8
+ include I18n::Locale
9
+
10
+ test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
11
+ assert_equal ['de', nil, nil, nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de')
12
+ end
13
+
14
+ test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
15
+ assert_equal ['de', nil, 'DE', nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de-DE')
16
+ end
17
+
18
+ test "Rfc4646::Parser given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do
19
+ assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], Tag::Rfc4646::Parser.match('de-latn-de-variant-x-phonebk')
20
+ end
21
+
22
+ test "Rfc4646::Parser given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do
23
+ assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], Tag::Rfc4646::Parser.match('DE-LATN-DE-VARIANT-X-PHONEBK')
24
+ end
25
+
26
+ test "Rfc4646::Parser given an invalid tag 'a-DE' it returns false" do
27
+ assert_equal false, Tag::Rfc4646::Parser.match('a-DE')
28
+ end
29
+
30
+ test "Rfc4646::Parser given an invalid tag 'de-419-DE' it returns false" do
31
+ assert_equal false, Tag::Rfc4646::Parser.match('de-419-DE')
32
+ end
33
+ end
34
+
35
+ # Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'
36
+
37
+ class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
38
+ include I18n::Locale
39
+
40
+ def setup
41
+ subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon)
42
+ @tag = Tag::Rfc4646.new *subtags
43
+ end
44
+
45
+ test "returns 'de' as the language subtag in lowercase" do
46
+ assert_equal 'de', @tag.language
47
+ end
48
+
49
+ test "returns 'Latn' as the script subtag in titlecase" do
50
+ assert_equal 'Latn', @tag.script
51
+ end
52
+
53
+ test "returns 'DE' as the region subtag in uppercase" do
54
+ assert_equal 'DE', @tag.region
55
+ end
56
+
57
+ test "returns 'variant' as the variant subtag in lowercase" do
58
+ assert_equal 'variant', @tag.variant
59
+ end
60
+
61
+ test "returns 'a-ext' as the extension subtag" do
62
+ assert_equal 'a-ext', @tag.extension
63
+ end
64
+
65
+ test "returns 'x-phonebk' as the privateuse subtag" do
66
+ assert_equal 'x-phonebk', @tag.privateuse
67
+ end
68
+
69
+ test "returns 'i-klingon' as the grandfathered subtag" do
70
+ assert_equal 'i-klingon', @tag.grandfathered
71
+ end
72
+
73
+ test "returns a formatted tag string from #to_s" do
74
+ assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s
75
+ end
76
+
77
+ test "returns an array containing the formatted subtags from #to_a" do
78
+ assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a
79
+ end
80
+ end
81
+
82
+ # Tag inheritance
83
+
84
+ class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
85
+ test "#parent returns 'de-Latn-DE-variant-a-ext-x-phonebk' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
86
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
87
+ assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
88
+ end
89
+
90
+ test "#parent returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do
91
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk)
92
+ assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s
93
+ end
94
+
95
+ test "#parent returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do
96
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext)
97
+ assert_equal 'de-Latn-DE-variant', tag.parent.to_s
98
+ end
99
+
100
+ test "#parent returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do
101
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant)
102
+ assert_equal 'de-Latn-DE', tag.parent.to_s
103
+ end
104
+
105
+ test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
106
+ tag = Tag::Rfc4646.new *%w(de Latn DE)
107
+ assert_equal 'de-Latn', tag.parent.to_s
108
+ end
109
+
110
+ test "#parent returns 'de' as the parent of 'de-Latn'" do
111
+ tag = Tag::Rfc4646.new *%w(de Latn)
112
+ assert_equal 'de', tag.parent.to_s
113
+ end
114
+
115
+ # TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned."
116
+ # where should we set the default language?
117
+ # test "#parent returns '' as the parent of 'de'" do
118
+ # tag = Tag::Rfc4646.new *%w(de)
119
+ # assert_equal '', tag.parent.to_s
120
+ # end
121
+
122
+ test "#parent returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
123
+ parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
124
+ de-Latn-DE-variant-a-ext-x-phonebk
125
+ de-Latn-DE-variant-a-ext
126
+ de-Latn-DE-variant
127
+ de-Latn-DE
128
+ de-Latn
129
+ de)
130
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
131
+ assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
132
+ end
133
+
134
+ test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
135
+ parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
136
+ de-Latn-DE-variant-a-ext-x-phonebk
137
+ de-Latn-DE-variant-a-ext
138
+ de-Latn-DE-variant
139
+ de-Latn-DE
140
+ de-Latn
141
+ de)
142
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
143
+ assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
144
+ end
145
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
+ require 'i18n/locale/tag'
3
+ require 'i18n/locale/tag/simple'
4
+
5
+ class I18nLocaleTagSimpleTest < Test::Unit::TestCase
6
+ include I18n::Locale
7
+
8
+ test "returns 'de' as the language subtag in lowercase" do
9
+ assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').subtags
10
+ end
11
+
12
+ test "returns a formatted tag string from #to_s" do
13
+ assert_equal 'de-Latn-DE', Tag::Simple.new('de-Latn-DE').to_s
14
+ end
15
+
16
+ test "returns an array containing the formatted subtags from #to_a" do
17
+ assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').to_a
18
+ end
19
+
20
+ # Tag inheritance
21
+
22
+ test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
23
+ assert_equal 'de-Latn', Tag::Simple.new('de-Latn-DE').parent.to_s
24
+ end
25
+
26
+ test "#parent returns 'de' as the parent of 'de-Latn'" do
27
+ assert_equal 'de', Tag::Simple.new('de-Latn').parent.to_s
28
+ end
29
+
30
+ test "#self_and_parents returns an array of 3 tags for 'de-Latn-DE'" do
31
+ assert_equal %w(de-Latn-DE de-Latn de), Tag::Simple.new('de-Latn-DE').self_and_parents.map { |tag| tag.to_s}
32
+ end
33
+ end