Skip to content

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

Merged
merged 5 commits into from
Jan 27, 2025

Conversation

abetomo
Copy link
Contributor

@abetomo abetomo commented Jan 22, 2025

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.

`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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert this?

@@ -325,6 +332,14 @@ def replace_plural_forms
end
end

CONTENT_TYPE_CHARSET = /(Content-Type: .+ charset=)CHARSET/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CONTENT_TYPE_CHARSET = /(Content-Type: .+ charset=)CHARSET/
CONTENT_TYPE_CHARSET = /^(Content-Type:.+ charset=)CHARSET/

Comment on lines 338 to 340
if CONTENT_TYPE_CHARSET =~ @entry
@entry = @entry.gsub(CONTENT_TYPE_CHARSET, "\\1#{@charset}")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert this?

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def run_msginit(locale, charset = "UTF-8")
def run_msginit(locale, charset=nil)

Comment on lines 230 to 249
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
Copy link
Member

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.

Copy link
Contributor Author

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.

if @locale.nil?
language_tag = Locale.current
else
language_tag = Locale::Tag.parse(@locale)
end

Copy link
Member

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)


class TestCurrentCharset < self
def run_msginit(charset)
create_pot_file("test.pot", :charset => charset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
create_pot_file("test.pot", :charset => charset)
create_pot_file("test.pot", charset: charset)

end

class TestCurrentCharset < self
def run_msginit(charset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def run_msginit(charset)
def run_msginit(pot_charset)

Comment on lines 265 to 266
assert_equal(po_header(:charset => "UTF-8"),
run_msginit("CHARSET"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal(po_header(:charset => "UTF-8"),
run_msginit("CHARSET"))
assert_equal(po_header(charset: "UTF-8"),
run_msginit("CHARSET"))

Comment on lines 270 to 271
assert_equal(po_header(:charset => "ASCII"),
run_msginit("ASCII"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal(po_header(:charset => "ASCII"),
run_msginit("ASCII"))
assert_equal(po_header(charset: "ASCII"),
run_msginit("ASCII"))

super(current_locale, current_language, options)
end

def test_change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_change
def test_template_charset

run_msginit("CHARSET"))
end

def test_not_change
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_not_change
def test_not_template_charset

end

def test_change
assert_equal(po_header(charset: "UTF-8"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@kou kou merged commit 8b183c3 into ruby-gettext:master Jan 27, 2025
22 checks passed
@abetomo abetomo deleted the replace-charset branch January 27, 2025 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants