-
Notifications
You must be signed in to change notification settings - Fork 29
msginit: Replace charset in Content-type with charset in locale #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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/po_parser.rb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this?
lib/gettext/tools/msginit.rb
Outdated
@@ -325,6 +332,14 @@ def replace_plural_forms | |||
end | |||
end | |||
|
|||
CONTENT_TYPE_CHARSET = /(Content-Type: .+ charset=)CHARSET/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if CONTENT_TYPE_CHARSET =~ @entry | |
@entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}") | |
end | |
@entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}") |
test/po/ja/_.po
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this?
test/tools/test_msginit.rb
Outdated
@@ -196,8 +198,8 @@ def test_specify_option | |||
end | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need them?
It seems that existing tests cover these cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if @locale.nil? | |
language_tag = Locale.current | |
else | |
language_tag = Locale::Tag.parse(@locale) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
getext
is generated withcharset=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.