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

[Intl] Intl does not return region specific language #35309

Closed
alexander-schranz opened this issue Jan 11, 2020 · 8 comments
Closed

[Intl] Intl does not return region specific language #35309

alexander-schranz opened this issue Jan 11, 2020 · 8 comments

Comments

@alexander-schranz
Copy link
Contributor

alexander-schranz commented Jan 11, 2020

Symfony version(s) affected: >= 4.4.0 (4.3.9 works)

Description

The Intl::getLanguageBundle()->getLanguageName('de, 'AT', 'en'); does not longer return the region specific language. Expected Austrian German got German same for en, GB expect British English got English.

also getLanguages seems not longer contain Austrian German and the other region specific values.

How to reproduce

Intl::getLanguageBundle()->getLanguageName('de, 'AT', 'en'); // should return `Austrian German` does return `German`
Intl::getLanguageBundle()->getLanguages('en'); // does not longer contain `Austrian German`

Additional context

Think it has something todo with @ro0NL changes in #33148 I always landing in the exception case with

Couldn't read the indices [Names][en_GB] for the locale "en" in "sulu/web-twig/vendor/symfony/intl/Resources/data/languages". The indices also couldn't be found for the fallback locale(s) "root".

@ro0NL
Copy link
Contributor

ro0NL commented Jan 11, 2020

Hi @alexander-schranz, that's correct and intended from my side :)

We excluded locales (or localized languages / or region specific languages) from the dedicated list of "language codes", which is ISO standard and shouldnt include locales but only pure language codes.

From the example code, it seems you are using the deprecated API in 4.4. Indeed, this lead to the exception case as both the old and new API read from the same data source.

For the new API, localized language names can be obtained using Languages::getName(). See docs:

* Gets the language name from its alpha2 code.
*
* A full locale may be passed to obtain a more localized language name, e.g. "American English" for "en_US".
*
* @throws MissingResourceException if the language code does not exist
*/
public static function getName(string $language, string $displayLocale = null): string

:}

@ro0NL
Copy link
Contributor

ro0NL commented Jan 11, 2020

Alternatively, to fix the legacy API in 4.4, we could check the LocalizedNames indice here:

return $this->reader->readEntry($this->path, $displayLocale, ['Names', $language]);

so similar like the new API in 4.4:

public static function getName(string $language, string $displayLocale = null): string
{
try {
return self::readEntry(['Names', $language], $displayLocale);
} catch (MissingResourceException $e) {
try {
return self::readEntry(['LocalizedNames', $language], $displayLocale);
} catch (MissingResourceException $e) {
if (false !== $i = strrpos($language, '_')) {
return self::getName(substr($language, 0, $i), $displayLocale);
}
throw $e;
}
}
}

i agree we effectively broke the old API as of 4.4, as these indices became unavailable:

// Some languages are translated together with their region,
// i.e. "en_GB" is translated as "British English"
if (null !== $region) {
try {
return $this->getName($language.'_'.$region, $displayLocale);
} catch (MissingResourceException $e) {
}
}

but im not sure sure it's worth fixing :)

@alexander-schranz
Copy link
Contributor Author

@ro0NL Thank you for your fast response.

but im not sure sure it's worth fixing :)

Think if I did understand the code correctly I can replace getLanguage with getLocale and LanguageType form type with LocaleType and it should be fine. So from my case if I'm the only running into this issue we can close it and mark it as wontfix.

@ro0NL
Copy link
Contributor

ro0NL commented Jan 12, 2020

language codes and locales are 2 independent lists, that's why we excluded locales from language codes in #33148

you should replace the old API with the new API as of 4.3, and then all is good :)

@ro0NL
Copy link
Contributor

ro0NL commented Jan 12, 2020

I always landing in the exception case with

@alexander-schranz how did you get the exception actually?

// does not longer contain Austrian German

this is a bugfix :)

// should return Austrian German does return German

this is a side effect

@alexander-schranz
Copy link
Contributor Author

how did you get the exception actually?

@ro0NL its catched so don't worry the exception is not thrown out just did debug and saw that it always landed in the catched case.

} catch (MissingResourceException $e) {
}

@ro0NL
Copy link
Contributor

ro0NL commented Jan 12, 2020

ah, i see what you mean now :) i think we can close then. The bugfix/change was intended.

@fabpot fabpot closed this as completed Jan 12, 2020
@alexander-schranz
Copy link
Contributor Author

@ro0NL sure. Thank you for the clarification.

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

5 participants