Skip to content
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

__d() doesn't take the correct msgstr depending on the position of the msgstr inside the .po file #10730

Closed
burzum opened this issue Jun 7, 2017 · 8 comments
Milestone

Comments

@burzum
Copy link
Contributor

burzum commented Jun 7, 2017

Copy pasting the internal ticket from my workmate @antoniosergio-moreira here. @netstyler


Original Problem

In the website's - www.german-architects.com - main navigation and in the Profiles navigation, the translation for the word "Projects" is only displaying "Projekt" and not "Projekte" (plural)

bildschirmfoto-2017-06-06-um-15 22 17

What we did at first

We checked the .po file for the word "Projects" and did not find anything. That was issue n.1. Issue n.2 is a bit trickier.

in src/View/Helper/ProfileHelper.php, line 75

[
	'name' => __d('wa', 'Projects'),
	'link' => ['controller' => 'Profiles', 'action' => 'view', $profile->slug, 'projects'],
	'editLink' => ['controller' => 'Profiles', 'action' => 'edit', 'projects'],
	'counterField' => 'project_count',
],

We added this word - "Projects" - as a msgstr to the src/Locale/de/wa.pofile.
At first, we added it in lines 297-298. Note that in lines 306-309 there is the singular/plural translation for Project/Projects. Having done this and cleared the cache, we note that the translations are not working in the website.

Addind the msgstr in lines 297-298
screen shot 2017-06-07 at 10 16 00
In the website, translations are not accurate
screen shot 2017-06-07 at 10 17 38

What we did afterwards

Afterwards, we moved the msgstrs to the bottom of the src/Locale/de/wa.po file (lines 1934-1935). After clearing cache once again, we note that the translations in the frontend are now correct.
Addind the msgstr in lines 1935-1936
screen shot 2017-06-07 at 10 29 59
In the website, translations are accurate
screen shot 2017-06-07 at 10 20 31

Seems it has something to do with the fact that if the msgstr are set before the singular/plural strings, this causes an issue - the msgstr isn't triggered or active or whatever the hell - and if the msgstr is set after the singular/plural strings, then all is well and everyone is smiling and happy and depression-free.

@dereuromark
Copy link
Member

Is this related to #10597 ? Does the PR also fix this, or are those separate issues?

@burzum
Copy link
Contributor Author

burzum commented Jun 7, 2017

@dereuromark I haven't tested the PR but after reading the issues comment history I think this pretty much is the same.

@markstory markstory added this to the 3.4.8 milestone Jun 7, 2017
@markstory markstory modified the milestones: 3.4.8, 3.4.9, 3.4.10 Jun 20, 2017
@markstory markstory modified the milestones: 3.4.10, 3.4.11 Jul 10, 2017
@markstory markstory modified the milestones: 3.4.11, 3.4.12 Jul 19, 2017
@markstory markstory modified the milestones: 3.4.12, 3.4.13 Aug 2, 2017
@markstory
Copy link
Member

There have been a few po file parsing changes since this was reported. Is this still an issue.

@markstory markstory modified the milestones: 3.4.13, 3.5.0 Aug 17, 2017
@markstory markstory modified the milestones: 3.4.13, 3.5.0, 3.5.1 Aug 17, 2017
@markstory markstory modified the milestones: 3.5.1, 3.5.2 Aug 29, 2017
@markstory markstory modified the milestones: 3.5.2, 3.5.3 Sep 12, 2017
@markstory
Copy link
Member

Fixed in #11127

@burzum
Copy link
Contributor Author

burzum commented Dec 5, 2017

@markstory this is still an issue as reported today by @netstyler CakePHP 3.5.5.

@netstyler
Copy link

netstyler commented Dec 5, 2017

If I remove :

msgid "Project"
msgid_plural "Projects"
msgstr[0] "Projekt"
msgstr[1] "Projekte"

Then the following does take effect:

msgid "Projects"
msgstr "Projekte"

It shows then the plural version.

It does not matter in which order I set the plural translations. Before or after the normal translations.
The plural translation seam to overwrite the normal msgid "Projects" translations.

@burzum
Copy link
Contributor Author

burzum commented Dec 5, 2017

@markstory I've added a test in a new branch https://github.com/cakephp/cakephp/tree/bug/plural-issues Check it out and run vendor\bin\phpunit tests\TestCase\I18n\Parser\PoFileParserTest.php to see the problem.

If I debug the $messages variable when running the test case I get this:

###########################
\src\I18n\Parser\PoFileParser.php (line 175)
########## DEBUG ##########
[
        'Location' => [
                '_context' => [
                        '' => 'Standort'
                ]
        ],
        'Locations' => [
                '_context' => [
                        '' => [
                                (int) 0 => 'Standort',
                                (int) 1 => 'Standorte'
                        ]
                ]
        ]
]

Compare this to the wa.po file contents:

msgid "Location"
msgid_plural "Locations"
msgstr[0] "Standort"
msgstr[1] "Standorte"

msgid "Locations"
msgstr "Standorte"

It looks like the current implementation makes the translation including the plurals available under the "Locations" key while it actually is "Location" in the po file.

Also when debugging L115, the $item variable in parse(), I get this:

###########################
\src\I18n\Parser\PoFileParser.php (line 115)
########## DEBUG ##########
[
        'ids' => [
                'singular' => 'Locations'
        ],
        'translated' => 'Standorte'
]

Singular? It's the plural in both cases, the identifier string as the translated string as well are a plural.

I'm really surprised nobody else encounter (or at least reported) this before. It's IMHO a major issue if you have an application that relies a lot on translated content.

@burzum burzum reopened this Dec 5, 2017
@markstory
Copy link
Member

The message parsed on L115 is singular as it is a single message without plural forms attached. The parser can't look at the contents of message ids to guess whether they are singular or plural values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants