msginit: Replace charset in Content-type with charset in locale#113
msginit: Replace charset in Content-type with charset in locale#113kou merged 5 commits intoruby-gettext:masterfrom
Conversation
`getext` is generated with `charset=CHARSET`. Translation as is will result in an error because `CHARSET` is an invalid value. Changed so that `charset=CHARSET` is replaced by the locale's charset.
lib/gettext/tools/msginit.rb
Outdated
| end | ||
| end | ||
|
|
||
| CONTENT_TYPE_CHARSET = /(Content-Type: .+ charset=)CHARSET/ |
There was a problem hiding this comment.
| CONTENT_TYPE_CHARSET = /(Content-Type: .+ charset=)CHARSET/ | |
| CONTENT_TYPE_CHARSET = /^(Content-Type:.+ charset=)CHARSET/ |
lib/gettext/tools/msginit.rb
Outdated
| if CONTENT_TYPE_CHARSET =~ @entry | ||
| @entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}") | ||
| end |
There was a problem hiding this comment.
| if CONTENT_TYPE_CHARSET =~ @entry | |
| @entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}") | |
| end | |
| @entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}") |
test/tools/test_msginit.rb
Outdated
| class TestLocale < self | ||
| def run_msginit(locale) | ||
| create_pot_file("test.pot") | ||
| def run_msginit(locale, charset = "UTF-8") |
There was a problem hiding this comment.
| def run_msginit(locale, charset = "UTF-8") | |
| def run_msginit(locale, charset=nil) |
test/tools/test_msginit.rb
Outdated
| def test_language_charset_with_replace_content_type | ||
| locale = "en" | ||
| assert_equal(po_header(locale, locale), | ||
| run_msginit(locale, "CHARSET")) | ||
| end | ||
|
|
||
| def test_language_region_with_replace_content_type | ||
| locale = "en_US" | ||
| language = "en" | ||
| assert_equal(po_header(locale, language), | ||
| run_msginit(locale, "CHARSET")) | ||
| end | ||
|
|
||
| def test_language_region_charset_with_replace_content_type | ||
| locale = "en_US" | ||
| language = "en" | ||
| charset = "UTF-8" | ||
| assert_equal(po_header(locale, language), | ||
| run_msginit("#{locale}.#{charset}", "CHARSET")) | ||
| end |
There was a problem hiding this comment.
Why do we need them?
It seems that existing tests cover these cases.
There was a problem hiding this comment.
The test was to check that charset is replaced as expected, even when --locale is specified.
This is because the value of language_tag changes with or without its option.
gettext/lib/gettext/tools/msginit.rb
Lines 169 to 173 in 17ad4cd
There was a problem hiding this comment.
OK.
Let's clarify it by test name and variable name:
-test_XXX_with_replace_content_type
+test_XXX_with_template_charset-run_msginit("XXX", "CHARSET")
+template_charset = "CHARSET"
+run_msginit("XXX", template_charset)
test/tools/test_msginit.rb
Outdated
|
|
||
| class TestCurrentCharset < self | ||
| def run_msginit(charset) | ||
| create_pot_file("test.pot", :charset => charset) |
There was a problem hiding this comment.
| create_pot_file("test.pot", :charset => charset) | |
| create_pot_file("test.pot", charset: charset) |
test/tools/test_msginit.rb
Outdated
| end | ||
|
|
||
| class TestCurrentCharset < self | ||
| def run_msginit(charset) |
There was a problem hiding this comment.
| def run_msginit(charset) | |
| def run_msginit(pot_charset) |
test/tools/test_msginit.rb
Outdated
| assert_equal(po_header(:charset => "UTF-8"), | ||
| run_msginit("CHARSET")) |
There was a problem hiding this comment.
| assert_equal(po_header(:charset => "UTF-8"), | |
| run_msginit("CHARSET")) | |
| assert_equal(po_header(charset: "UTF-8"), | |
| run_msginit("CHARSET")) |
test/tools/test_msginit.rb
Outdated
| assert_equal(po_header(:charset => "ASCII"), | ||
| run_msginit("ASCII")) |
There was a problem hiding this comment.
| assert_equal(po_header(:charset => "ASCII"), | |
| run_msginit("ASCII")) | |
| assert_equal(po_header(charset: "ASCII"), | |
| run_msginit("ASCII")) |
test/tools/test_msginit.rb
Outdated
| super(current_locale, current_language, options) | ||
| end | ||
|
|
||
| def test_change |
There was a problem hiding this comment.
| def test_change | |
| def test_template_charset |
test/tools/test_msginit.rb
Outdated
| run_msginit("CHARSET")) | ||
| end | ||
|
|
||
| def test_not_change |
There was a problem hiding this comment.
| def test_not_change | |
| def test_not_template_charset |
test/tools/test_msginit.rb
Outdated
| end | ||
|
|
||
| def test_change | ||
| assert_equal(po_header(charset: "UTF-8"), |
There was a problem hiding this comment.
| assert_equal(po_header(charset: "UTF-8"), | |
| assert_equal(po_header(charset: Locale.current.charset), |
We may want to define current_charset like other current_* methods.
getextis generated withcharset=CHARSET.Translation as is will result in an error because
CHARSETis an invalid value.Changed so that
charset=CHARSETis replaced by the locale's charset.