mova-i18n 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +47 -0
- data/Gemfile +26 -0
- data/LICENSE.txt +22 -0
- data/README.md +93 -0
- data/Rakefile +24 -0
- data/lib/mova-i18n.rb +77 -0
- data/lib/mova-i18n/bridge.rb +69 -0
- data/lib/mova-i18n/config.rb +36 -0
- data/mova-i18n.gemspec +21 -0
- data/test/exists_test.rb +29 -0
- data/test/locale/en.yml +2 -0
- data/test/localize_test.rb +58 -0
- data/test/mova_config_test.rb +17 -0
- data/test/test_helper.rb +61 -0
- data/test/transfer_translations_test.rb +27 -0
- data/test/translate/default_test.rb +45 -0
- data/test/translate/pluralization_test.rb +62 -0
- data/test/translate/scope_test.rb +26 -0
- data/test/translate_test.rb +61 -0
- data/test/transliterate_test.rb +28 -0
- data/test_rails/dummy/.gitignore +15 -0
- data/test_rails/dummy/app/controllers/hello_controller.rb +2 -0
- data/test_rails/dummy/app/views/hello/html_safe_key.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/html_safe_underscored.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/html_unsafe.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/locale_option.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/missing_translation.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/partial_scope.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/raise_error.html.erb +1 -0
- data/test_rails/dummy/app/views/hello/translate.html.erb +1 -0
- data/test_rails/dummy/config.ru +4 -0
- data/test_rails/dummy/config/application.rb +13 -0
- data/test_rails/dummy/config/environment.rb +5 -0
- data/test_rails/dummy/config/environments/test.rb +10 -0
- data/test_rails/dummy/config/locales/uk.rb +20 -0
- data/test_rails/dummy/config/locales/uk.yml +252 -0
- data/test_rails/dummy/config/locales/views.yml +11 -0
- data/test_rails/helpers_test.rb +37 -0
- data/test_rails/test_helper.rb +11 -0
- data/test_rails/view_test.rb +55 -0
- metadata +154 -0
data/test/exists_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class ExistsTest < I18nTest
|
5
|
+
def test_existing_key
|
6
|
+
assert I18n.exists?(:foo)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_existing_key_with_explisit_locale
|
10
|
+
assert I18n.exists?(:foo, :en)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_non_existing_key
|
14
|
+
refute I18n.exists?(:bar)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_locale_fallbacks
|
18
|
+
fallback_resolver = double
|
19
|
+
expect(fallback_resolver).to receive(:[]).with(:ru).and_return([:ru, :en])
|
20
|
+
expect(I18n).to receive(:fallbacks).and_return(fallback_resolver)
|
21
|
+
assert I18n.exists?(:foo, :ru)
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup
|
25
|
+
super
|
26
|
+
I18n.mova.translator.put(en: {foo: "foo in en"})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/locale/en.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class LocalizeTest < I18nTest
|
5
|
+
def date
|
6
|
+
Date.new(2014, 6, 3)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_implicit_format
|
10
|
+
assert_equal "2014-06-03", I18n.l(date)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_explicit_symbol_format
|
14
|
+
assert_equal "Jun 03", I18n.l(date, format: :short)
|
15
|
+
assert_equal "June 03, 2014", I18n.l(date, format: :long)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_explicit_string_format
|
19
|
+
assert_equal "3 June 2014", I18n.l(date, format: "%-d %B %Y")
|
20
|
+
end
|
21
|
+
|
22
|
+
def time
|
23
|
+
Time.utc(2014, 6, 3, 13, 15, 30)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_implicit_format_time
|
27
|
+
assert_equal "Tue, 03 Jun 2014 13:15:30 +0000", I18n.l(time)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_explicit_symbol_format_time
|
31
|
+
assert_equal "03 Jun 13:15", I18n.l(time, format: :short)
|
32
|
+
assert_equal "June 03, 2014 13:15", I18n.l(time, format: :long)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_explicit_string_format_time
|
36
|
+
assert_equal "3 June 2014", I18n.l(time, format: "%-d %B %Y")
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
super
|
41
|
+
I18n.mova.translator.put(en: {
|
42
|
+
date: {
|
43
|
+
formats: {default: "%Y-%m-%d", short: "%b %d", long: "%B %d, %Y"},
|
44
|
+
day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
45
|
+
abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
46
|
+
month_names: [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
47
|
+
abbr_month_names: [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
48
|
+
order: [:year, :month, :day]
|
49
|
+
},
|
50
|
+
time: {
|
51
|
+
formats: {default: "%a, %d %b %Y %H:%M:%S %z", short: "%d %b %H:%M", long: "%B %d, %Y %H:%M"},
|
52
|
+
am: "am",
|
53
|
+
pm: "pm"
|
54
|
+
}
|
55
|
+
})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class MovaConfigTest < I18nTest
|
5
|
+
def test_assigns_translator
|
6
|
+
translator = double
|
7
|
+
I18n.mova.translator = translator
|
8
|
+
assert_equal translator, I18n.mova.translator
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_assigns_interpolator
|
12
|
+
interpolator = double
|
13
|
+
I18n.mova.interpolator = interpolator
|
14
|
+
assert_equal interpolator, I18n.mova.interpolator
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "mova-i18n"
|
3
|
+
|
4
|
+
require "minitest"
|
5
|
+
Minitest.autorun
|
6
|
+
|
7
|
+
require "rspec/mocks"
|
8
|
+
|
9
|
+
RSpec::Mocks.configuration.syntax = :expect
|
10
|
+
|
11
|
+
module RSpec::Mocks
|
12
|
+
remove_const :MockExpectationError
|
13
|
+
# treat as Minitest failure, not an exception
|
14
|
+
MockExpectationError = Class.new(Minitest::Assertion)
|
15
|
+
end
|
16
|
+
|
17
|
+
module I18n
|
18
|
+
module Test
|
19
|
+
module RSpecMocksForMinitest
|
20
|
+
include RSpec::Mocks::ExampleMethods
|
21
|
+
|
22
|
+
def before_setup
|
23
|
+
RSpec::Mocks.setup
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_teardown
|
28
|
+
begin
|
29
|
+
RSpec::Mocks.verify
|
30
|
+
ensure
|
31
|
+
RSpec::Mocks.teardown
|
32
|
+
end
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class I18nTest < Minitest::Test
|
39
|
+
include I18n::Test::RSpecMocksForMinitest
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@default_translator = I18n.mova.translator.clone
|
43
|
+
@default_interpolator = I18n.mova.interpolator.clone
|
44
|
+
@default_i18n_backend = I18n.backend.clone
|
45
|
+
@default_load_path = I18n.load_path.dup
|
46
|
+
|
47
|
+
I18n.enforce_available_locales = false
|
48
|
+
@default_locale = I18n.locale
|
49
|
+
I18n.locale = :en
|
50
|
+
end
|
51
|
+
|
52
|
+
def teardown
|
53
|
+
I18n.mova.translator = @default_translator
|
54
|
+
I18n.mova.interpolator = @default_interpolator
|
55
|
+
I18n.backend = @default_i18n_backend
|
56
|
+
I18n.load_path = @default_load_path
|
57
|
+
I18n.locale = @default_locale
|
58
|
+
I18n.reload!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class TransferTranslationsTest < I18nTest
|
5
|
+
def test_transfer_translations
|
6
|
+
I18n.backend.store_translations(:en, hello: "hi")
|
7
|
+
I18n.backend.store_translations(:de, hello: "Hallo")
|
8
|
+
I18n.mova.transfer_translations!
|
9
|
+
assert_equal "hi", I18n.t(:hello)
|
10
|
+
assert_equal "Hallo", I18n.t(:hello, locale: :de)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_reload
|
14
|
+
I18n.backend.store_translations(:en, hello: "hi")
|
15
|
+
I18n.reload!
|
16
|
+
assert_equal "missing translation: en.hello", I18n.t(:hello)
|
17
|
+
|
18
|
+
I18n.load_path << File.expand_path("../locale/en.yml", __FILE__)
|
19
|
+
I18n.reload!
|
20
|
+
assert_equal "Hi!", I18n.t(:hello)
|
21
|
+
|
22
|
+
I18n.load_path = []
|
23
|
+
I18n.reload!
|
24
|
+
assert_equal "missing translation: en.hello", I18n.t(:hello)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class DefaultTest < I18nTest
|
5
|
+
def test_string_default
|
6
|
+
assert_equal "my default", I18n.t(:missing, default: "my default")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_symbol_default
|
10
|
+
assert_equal "foo in en", I18n.t(:missing, default: :foo)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty_hash_default
|
14
|
+
assert_equal({}, I18n.t(:missing, default: {}))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_symbol_default_with_scope
|
18
|
+
assert_equal "qux in en", I18n.t(:missing, scope: "bar.baz", default: :qux)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_array_symbol_default
|
22
|
+
assert_equal "foo in en", I18n.t(:missing, default: [:missing2, :foo])
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_array_symbol_default_missing
|
26
|
+
assert_equal "missing translation: en.missing", I18n.t(:missing, default: [:missing2, :missing3])
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_array_symbol_default_with_scope
|
30
|
+
assert_equal "qux in en", I18n.t(:missing, scope: "bar.baz", default: [:missing2, :qux])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_array_symbol_trailing_string_default
|
34
|
+
assert_equal "my default", I18n.t(:missing, default: [:missing2, "my default"])
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
super
|
39
|
+
I18n.mova.translator.put(
|
40
|
+
en: {foo: "foo in en", bar: {baz: {qux: "qux in en"}}},
|
41
|
+
de: {foo: "foo in de", bar: "my %{bar}"}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class PluralizationTest < I18nTest
|
5
|
+
def test_default_pluralizer
|
6
|
+
assert_equal "22 bars", I18n.t(:bar, count: 22)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_pluralizer_from_load_path
|
10
|
+
assert_equal "24 столи", I18n.t(:table, locale: :uk, count: 24)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_zero
|
14
|
+
assert_equal "Нема нікого", I18n.t(:people, locale: :uk, count: 0)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_zero_fallback_to_others_plural_key
|
18
|
+
assert_equal "0 bars", I18n.t(:bar, count: 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_fallback_to_non_plural_key
|
22
|
+
assert_equal "foo", I18n.t(:foo, count: 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_with_default
|
26
|
+
assert_equal "5 bars", I18n.t(:baz, count: 5, default: :bar)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_scope
|
30
|
+
assert_equal "5 Tasten", I18n.t(:key, locale: :de, count: 5, scope: :nested)
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup
|
34
|
+
super
|
35
|
+
I18n.mova.translator.put(
|
36
|
+
en: {foo: "foo", bar: {one: "bar", other: "%{count} bars"}},
|
37
|
+
uk: {table: {one: "%{count} стіл", few: "%{count} столи", many: "%{count} столів"},
|
38
|
+
people: {zero: "Нема нікого", one: "%{count} людина", few: "%{count} людини", many: "%{count} людей"},
|
39
|
+
i18n: {
|
40
|
+
plural: {
|
41
|
+
rule: lambda do |n|
|
42
|
+
mod10 = n % 10
|
43
|
+
mod100 = n % 100
|
44
|
+
|
45
|
+
if mod10 == 1 && mod100 != 11
|
46
|
+
:one
|
47
|
+
elsif [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100)
|
48
|
+
:few
|
49
|
+
elsif mod10 == 0 || (5..9).to_a.include?(mod10) || (11..14).to_a.include?(mod100)
|
50
|
+
:many
|
51
|
+
else
|
52
|
+
:other
|
53
|
+
end
|
54
|
+
end
|
55
|
+
}
|
56
|
+
}
|
57
|
+
},
|
58
|
+
de: {nested: {key: {one: "1 Schlüssel", other: "%{count} Tasten"}}}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class ScopeTest < I18nTest
|
5
|
+
def test_simple_scope
|
6
|
+
assert_equal "qux in en", I18n.t("baz.qux", scope: "bar")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_dot_separated_scope
|
10
|
+
assert_equal "qux in en", I18n.t("qux", scope: "bar.baz")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_scope_array
|
14
|
+
assert_equal "qux in en", I18n.t("qux", scope: %w(bar baz))
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
I18n.mova.translator.put(
|
20
|
+
en: {foo: "foo in en", bar: {baz: {qux: "qux in en"}}},
|
21
|
+
de: {foo: "foo in de", bar: "my %{bar}"},
|
22
|
+
uk: {table: {one: "%{count} стіл", few: "%{count} столи", many: "%{count} столів"}}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class TranslateTest < I18nTest
|
5
|
+
def test_current_locale
|
6
|
+
assert_equal "foo in en", I18n.t(:foo)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_option_locale
|
10
|
+
assert_equal "foo in de", I18n.t(:foo, locale: "de")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_string_key
|
14
|
+
assert_equal "foo in en", I18n.t("foo")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_dot_separated_key
|
18
|
+
assert_equal "qux in en", I18n.t(:"bar.baz.qux")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_missing_translation
|
22
|
+
assert_equal "missing translation: en.missing", I18n.t(:missing)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_raise_on_missing_translation
|
26
|
+
assert_raises(I18n::MissingTranslationData) { I18n.t(:missing, raise: true) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_throws_on_missing_translation
|
30
|
+
assert_throws(:exception) { I18n.t(:missing, throw: true) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_interpolation
|
34
|
+
assert_equal "my foobar", I18n.t(:bar, locale: :de, bar: "foobar")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_interpolation_with_missing_placeholder
|
38
|
+
assert_raises(I18n::MissingInterpolationArgument) { I18n.t(:bar, locale: :de) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_locale_fallbacks
|
42
|
+
fallback_resolver = double
|
43
|
+
expect(fallback_resolver).to receive(:[]).with(:ru).and_return([:ru, :en])
|
44
|
+
expect(I18n).to receive(:fallbacks).and_return(fallback_resolver)
|
45
|
+
assert_equal "foo in en", I18n.t(:foo, locale: :ru)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_locale_fallbacks_suppressed
|
49
|
+
expect(I18n).not_to receive(:fallbacks)
|
50
|
+
assert_equal "missing translation: ru.foo", I18n.t(:foo, locale: :ru, fallback: true)
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup
|
54
|
+
super
|
55
|
+
I18n.mova.translator.put(
|
56
|
+
en: {foo: "foo in en", bar: {baz: {qux: "qux in en"}}},
|
57
|
+
de: {foo: "foo in de", bar: "my %{bar}"}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class TransliterateTest < I18nTest
|
5
|
+
def test_default_transliterator
|
6
|
+
assert_equal "AEroskobing", I18n.transliterate("Ærøskøbing")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_hash_transliterator
|
10
|
+
assert_equal "leto", I18n.transliterate("лeто", locale: :ru)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_proc_transliterator
|
14
|
+
assert_equal "mova", I18n.transliterate("мова", locale: :uk)
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
I18n.mova.translator.put({
|
20
|
+
ru: {i18n: {transliterate: {rule: {"л" => "l", "е" => "e", "т" => "t", "о" => "o"}}}},
|
21
|
+
uk: {i18n: {transliterate: {rule: ->(string) do
|
22
|
+
map = {"м" => "m", "о" => "o", "в" => "v", "а" => "a"}
|
23
|
+
string.each_char.map { |char| map[char] }.join
|
24
|
+
end}}}
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|