Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #117 from e-travel/gt-msgctxt

Gettext pgettext and msgctxt support
  • Loading branch information...
commit 89ea337f48562370988421e50caa7c2fe89452c7 2 parents da09d52 + 28cf411
@svenfuchs svenfuchs authored
View
1  lib/i18n/backend/gettext.rb
@@ -40,6 +40,7 @@ def parse(filename)
def normalize(locale, data)
data.inject({}) do |result, (key, value)|
unless key.nil? || key.empty?
+ key = key.gsub(I18n::Gettext::CONTEXT_SEPARATOR, '|')
key, value = normalize_pluralization(locale, key, value) if key.index("\000")
parts = key.split('|').reverse
View
8 test/gettext/backend_test.rb
@@ -43,11 +43,13 @@ def test_looks_up_a_namespaced_translation
I18n.locale = :de
assert_equal 'Räderzahl', sgettext('Car|Wheels count')
assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
+ assert_equal 'Räderzahl!', pgettext('New car', 'Wheels count')
end
def test_uses_namespaced_default_translation
assert_equal 'Wheels count', sgettext('Car|Wheels count')
assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
+ assert_equal 'Wheels count', pgettext('New car', 'Wheels count')
end
def test_pluralizes_entry
@@ -67,6 +69,8 @@ def test_pluralizes_namespaced_entry
assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
+ assert_equal 'Rad!', npgettext('New car', 'wheel', 'wheels', 1)
+ assert_equal 'Räder!', npgettext('New car', 'wheel', 'wheels', 2)
end
def test_pluralizes_namespaced_default_entry
@@ -74,6 +78,8 @@ def test_pluralizes_namespaced_default_entry
assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
+ assert_equal 'wheel', npgettext('New car', 'wheel', 'wheels', 1)
+ assert_equal 'wheels', npgettext('New car', 'wheel', 'wheels', 2)
end
def test_pluralizes_namespaced_entry_with_alternative_syntax
@@ -82,6 +88,8 @@ def test_pluralizes_namespaced_entry_with_alternative_syntax
assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
+ assert_equal 'Rad!', npgettext('New car', ['wheel', 'wheels'], 1)
+ assert_equal 'Räder!', npgettext('New car', ['wheel', 'wheels'], 2)
end
def test_ngettextpluralizes_entry_with_dots
View
10 test/test_data/locales/de.po
@@ -42,6 +42,10 @@ msgstr "Modell"
msgid "Car|Wheels count"
msgstr "Räderzahl"
+msgctxt "New car"
+msgid "Wheels count"
+msgstr "Räderzahl!"
+
#: app/views/cars/show.html.erb:7
msgid "Created"
msgstr "Erstellt"
@@ -66,6 +70,12 @@ msgid_plural "Car|wheels"
msgstr[0] "Rad"
msgstr[1] "Räder"
+msgctxt "New car"
+msgid "wheel"
+msgid_plural "wheels"
+msgstr[0] "Rad!"
+msgstr[1] "Räder!"
+
msgid "On %{count} wheel."
msgid_plural "On %{count} wheels."
msgstr[0] "Auf %{count} Achse."
Please sign in to comment.
Something went wrong with that request. Please try again.