Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Gettext pgettext and msgctxt support
  • Loading branch information...
commit 89ea337f48562370988421e50caa7c2fe89452c7 2 parents da09d52 + 28cf411
Sven Fuchs svenfuchs authored
1  lib/i18n/backend/gettext.rb
@@ -40,6 +40,7 @@ def parse(filename)
40 40 def normalize(locale, data)
41 41 data.inject({}) do |result, (key, value)|
42 42 unless key.nil? || key.empty?
  43 + key = key.gsub(I18n::Gettext::CONTEXT_SEPARATOR, '|')
43 44 key, value = normalize_pluralization(locale, key, value) if key.index("\000")
44 45
45 46 parts = key.split('|').reverse
8 test/gettext/backend_test.rb
@@ -43,11 +43,13 @@ def test_looks_up_a_namespaced_translation
43 43 I18n.locale = :de
44 44 assert_equal 'Räderzahl', sgettext('Car|Wheels count')
45 45 assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
  46 + assert_equal 'Räderzahl!', pgettext('New car', 'Wheels count')
46 47 end
47 48
48 49 def test_uses_namespaced_default_translation
49 50 assert_equal 'Wheels count', sgettext('Car|Wheels count')
50 51 assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
  52 + assert_equal 'Wheels count', pgettext('New car', 'Wheels count')
51 53 end
52 54
53 55 def test_pluralizes_entry
@@ -67,6 +69,8 @@ def test_pluralizes_namespaced_entry
67 69 assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
68 70 assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
69 71 assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
  72 + assert_equal 'Rad!', npgettext('New car', 'wheel', 'wheels', 1)
  73 + assert_equal 'Räder!', npgettext('New car', 'wheel', 'wheels', 2)
70 74 end
71 75
72 76 def test_pluralizes_namespaced_default_entry
@@ -74,6 +78,8 @@ def test_pluralizes_namespaced_default_entry
74 78 assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
75 79 assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
76 80 assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
  81 + assert_equal 'wheel', npgettext('New car', 'wheel', 'wheels', 1)
  82 + assert_equal 'wheels', npgettext('New car', 'wheel', 'wheels', 2)
77 83 end
78 84
79 85 def test_pluralizes_namespaced_entry_with_alternative_syntax
@@ -82,6 +88,8 @@ def test_pluralizes_namespaced_entry_with_alternative_syntax
82 88 assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
83 89 assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
84 90 assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
  91 + assert_equal 'Rad!', npgettext('New car', ['wheel', 'wheels'], 1)
  92 + assert_equal 'Räder!', npgettext('New car', ['wheel', 'wheels'], 2)
85 93 end
86 94
87 95 def test_ngettextpluralizes_entry_with_dots
10 test/test_data/locales/de.po
@@ -42,6 +42,10 @@ msgstr "Modell"
42 42 msgid "Car|Wheels count"
43 43 msgstr "Räderzahl"
44 44
  45 +msgctxt "New car"
  46 +msgid "Wheels count"
  47 +msgstr "Räderzahl!"
  48 +
45 49 #: app/views/cars/show.html.erb:7
46 50 msgid "Created"
47 51 msgstr "Erstellt"
@@ -66,6 +70,12 @@ msgid_plural "Car|wheels"
66 70 msgstr[0] "Rad"
67 71 msgstr[1] "Räder"
68 72
  73 +msgctxt "New car"
  74 +msgid "wheel"
  75 +msgid_plural "wheels"
  76 +msgstr[0] "Rad!"
  77 +msgstr[1] "Räder!"
  78 +
69 79 msgid "On %{count} wheel."
70 80 msgid_plural "On %{count} wheels."
71 81 msgstr[0] "Auf %{count} Achse."

0 comments on commit 89ea337

Please sign in to comment.
Something went wrong with that request. Please try again.