-
Notifications
You must be signed in to change notification settings - Fork 30
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,6 +77,7 @@ def pot_header(options) | |||||
| options = default_po_header_options.merge(options) | ||||||
| package_name = options[:package_name] || default_package_name | ||||||
| have_plural_forms = options[:have_plural_forms] || true | ||||||
| charset = options[:charset] || "UTF-8" | ||||||
| header = <<EOF | ||||||
| # SOME DESCRIPTIVE TITLE. | ||||||
| # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||||||
|
|
@@ -93,7 +94,7 @@ def pot_header(options) | |||||
| "Language: \\n" | ||||||
| "Language-Team: LANGUAGE <LL@li.org>\\n" | ||||||
| "MIME-Version: 1.0\\n" | ||||||
| "Content-Type: text/plain; charset=UTF-8\\n" | ||||||
| "Content-Type: text/plain; charset=#{charset}\\n" | ||||||
| "Content-Transfer-Encoding: 8bit\\n" | ||||||
| EOF | ||||||
| if have_plural_forms | ||||||
|
|
@@ -109,6 +110,7 @@ def po_header(locale, language, options={}) | |||||
| name = options[:translator_name] || "FULL NAME" | ||||||
| email = options[:translator_email] || "EMAIL@ADDRESS" | ||||||
| language_name = Locale::Info.get_language(language).name | ||||||
| charset = options[:charset] || "UTF-8" | ||||||
| plural_forms = @msginit.send(:plural_forms, language) | ||||||
|
|
||||||
| <<EOF | ||||||
|
|
@@ -126,7 +128,7 @@ def po_header(locale, language, options={}) | |||||
| "Language: #{locale}\\n" | ||||||
| "Language-Team: #{language_name}\\n" | ||||||
| "MIME-Version: 1.0\\n" | ||||||
| "Content-Type: text/plain; charset=UTF-8\\n" | ||||||
| "Content-Type: text/plain; charset=#{charset}\\n" | ||||||
| "Content-Transfer-Encoding: 8bit\\n" | ||||||
| "Plural-Forms: #{plural_forms}\\n" | ||||||
| EOF | ||||||
|
|
@@ -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, pot_charset=nil) | ||||||
| create_pot_file("test.pot", charset: pot_charset) | ||||||
| po_file_path = "output.po" | ||||||
| @msginit.run("--output", po_file_path, | ||||||
| "--locale", locale) | ||||||
|
|
@@ -224,6 +226,50 @@ def test_language_region_charset | |||||
| assert_equal(po_header(locale, language), | ||||||
| run_msginit("#{locale}.#{charset}")) | ||||||
| end | ||||||
|
|
||||||
| 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 | ||||||
| end | ||||||
|
|
||||||
| class TestCurrentCharset < self | ||||||
| def run_msginit(pot_charset) | ||||||
| create_pot_file("test.pot", charset: pot_charset) | ||||||
| po_file_path = "output.po" | ||||||
| @msginit.run("--output", po_file_path) | ||||||
| File.read(po_file_path) | ||||||
| end | ||||||
|
|
||||||
| def po_header(options) | ||||||
| super(current_locale, current_language, options) | ||||||
| end | ||||||
|
|
||||||
| def test_change | ||||||
|
||||||
| def test_change | |
| def test_template_charset |
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.
| 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.
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.
| def test_not_change | |
| def test_not_template_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.
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
charsetis replaced as expected, even when--localeis specified.This is because the value of
language_tagchanges with or without its option.gettext/lib/gettext/tools/msginit.rb
Lines 169 to 173 in 17ad4cd
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: