Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Translation fallback order error #42480

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

Closed
mboeck001 opened this issue Aug 11, 2021 Discussed in #42479 · 3 comments
Closed

Translation fallback order error #42480

mboeck001 opened this issue Aug 11, 2021 Discussed in #42479 · 3 comments

Comments

@mboeck001
Copy link

Discussed in #42479

Originally posted by mboeck001 August 11, 2021
Hi!

There seems to be a bug in Symfony\Component\Translation computing the fallbacks in method computeFallbackLocales. Perhapes someone can confirm or correct me?

  • We use a valid ICU language selector e.g de_AT_VIENNA and we have a message file for de, de_AT and de_AT_VIENNA containing a valid translation
  • locale is de_AT_VIENNA
  • the lookup ID is missing in de_AT_VIENNA, so fallback is triggered
  • the fallback is computed in the order first de, then de_AT, what is imo wrong, it has to be de_AT followed by de corresponding to ICU usage

I would just change the array_unshift to a normal append operation

Did I miss something? This seams to be since a long time ...

changed line arround line 441 of Translator.php to:

        if (null !== $locale) {
            // m.boeck: wrong order in fallback - bug in symfony
            $locales[] = $locale;
        }

removing the array_unshift operation. For me it works.

Thats also in the 4.x branch.

Martin

@ro0NL
Copy link
Contributor

ro0NL commented Aug 11, 2021

this looks odd. Can you invalidate this test?

public function testTransWithIcuVariantFallbackLocale()

my guess is nobody noticed yet :)

@mboeck001
Copy link
Author

mboeck001 commented Aug 12, 2021

this test is partly correct, but is missing the point a translation non-existing primary and is existing in all subsequent parts. I would rewrite this test by:

public function testTransWithIcuVariantFallbackLocale()
{
    $translator = new Translator('en_GB_scouse');
    $translator->addLoader('array', new ArrayLoader());
    $translator->addResource('array', ['foo' => 'foofoo'], 'en_GB_scouse');
    $translator->addResource('array', ['bar' => 'foobar'], 'en_GB');
    $translator->addResource('array', ['baz' => 'foobaz'], 'en_001');
    $translator->addResource('array', ['qux' => 'fooqux'], 'en');
    // added
    $translator->addResource('array', ['fb' => 'foofbgb'], 'en_GB');
    $translator->addResource('array', ['fb' => 'foofb001'], 'en_001');
    $translator->addResource('array', ['fb' => 'foofben'], 'en');**
    // --
    $this->assertSame('foofoo', $translator->trans('foo'));
    $this->assertSame('foobar', $translator->trans('bar'));
    $this->assertSame('foobaz', $translator->trans('baz'));
    $this->assertSame('fooqux', $translator->trans('qux'));
    // added
    $this->assertSame('fb', $translator->trans('foofbgb'));
    // --
}

@fabpot fabpot closed this as completed Aug 26, 2021
fabpot added a commit that referenced this issue Aug 26, 2021
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Translation] Reverse fallback locales

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #42480
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->
<!--

Commits
-------

7cc0c36 [Translation] Reverse fallback locales
@shyim
Copy link
Contributor

shyim commented Aug 31, 2021

Hey,

after this change, we have an issue with our application and we don't know if that new order is correct 🤔

That's like our current code:

$translator = new Translator('en_GB');
$translator->setFallbackLocales(['en_GB', 'en']);
$catalogue = $translator->getCatalogue('en_GB');

$this->assertEquals('en', $catalogue->getFallbackCatalogue()->getLocale());

After this issue en_001 (taken from ICU) is preferred over the configured fallback locales. I am not very experienced with the translation stuff and ICU. Is that correct so? I would expect that the ICU stuff is appended to the locales at end and not to the beginning.

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

6 participants