Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Issue in gettext file load, when plural part from one phrase exists as singular part in another #6762

Closed
deny opened this issue Oct 14, 2014 · 6 comments
Assignees
Milestone

Comments

@deny
Copy link
Contributor

deny commented Oct 14, 2014

When i use translations with gettext .mo files, and use translatePlural as below:

echo $this->translatePlural('a', 'c', $num);
echo $this->translatePlural('b', 'a', $num2);

the second line return untranslated string. Textdomain created by I18n\Translator\Loader\Gettext should contains:

'a' =>  array (
    0 => 'translate-a-0',
    1 => 'translate-a-1',
),
'b' =>  array (
    0 => 'translate-b-0',
    1 => 'translate-b-1',
),

Loader process entries in alphabetical order, and fist read translate for ('a', 'c'), then for ('b', 'a'). When it add plural form it clears all original strings (https://github.com/zendframework/zf2/blob/master/library/Zend/I18n/Translator/Loader/Gettext.php#L131). In this case it's clear translation for ('a', 'c'), and text domain looks like

'a' => '',
'c' => '',
'b' =>  array (
    0 => 'translate-b-0',
    1 => 'translate-b-1',
),

Replace problematic line

$textDomain[$string] = '';

to

if(!isset($textDomain[$string])) {
    $textDomain[$string] = '';
}

should fix this problem.

Sorry for my English :)

@DASPRiD
Copy link
Member

DASPRiD commented Oct 14, 2014

Could you add the .po file contents to illustrate the problem a bit more?

@deny
Copy link
Contributor Author

deny commented Oct 14, 2014

of course, here is sample .po file

msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2014-10-14 12:50+0100\n"
"PO-Revision-Date: 2014-10-14 12:55+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: en_EN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "a"
msgid_plural "c"
msgstr[0] "singular1"
msgstr[1] "plural1"

msgid "b"
msgid_plural "a"
msgstr[0] "singular2"
msgstr[1] "plural2"

@DASPRiD
Copy link
Member

DASPRiD commented Oct 14, 2014

I see. Would you mind writing up a (failing) unit test for that?

@deny
Copy link
Contributor Author

deny commented Oct 14, 2014

I prepare test and proposed hotfix on my fork of zf2. https://github.com/deny/zf2/commit/9e2c8a399db888c628c6a2d55fec48e079020162 Should i send pull request?

@DASPRiD
Copy link
Member

DASPRiD commented Oct 14, 2014

Yes please :)

Ocramius added a commit that referenced this issue Dec 30, 2014
Ocramius added a commit that referenced this issue Dec 30, 2014
@Ocramius Ocramius self-assigned this Dec 30, 2014
@Ocramius Ocramius added this to the 2.3.4 milestone Dec 30, 2014
@Ocramius
Copy link
Member

Handled in #6765

gianarb pushed a commit to zendframework/zend-i18n that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-i18n that referenced this issue May 15, 2015
…dding `@group` annotations for newly introduced tests
gianarb pushed a commit to zendframework/zend-i18n that referenced this issue May 15, 2015
…inor cs fixes (one argument per line in multiline function calls, spacing)
gianarb pushed a commit to zendframework/zend-i18n that referenced this issue May 15, 2015
gianarb pushed a commit to zendframework/zend-i18n that referenced this issue May 15, 2015
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants