-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[intl] Get all language names with the country language #31562
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
Comments
I tend to believe the current API allows to built such a list already. Using forms it's simply as $form = $this->createForm(LanguageType::class, null, [
'choice_label' => function ($lng) {
return Intl::getLanguageBundle()->getLanguageName($lng, null, $lng);
},
]); |
I'm not sure this feature is common enough to provide it as a feature. Moreover, when the alternative is only a couple of lines of code. I'm 👎 about the proposal unless someone comes with some compelling reasons. |
Since I published the above comment I've changed my mind around this. The feature proposed is not that uncommon. In fact, even the Symfony Demo app now displays each language into its own language: So, I've created #32388 to implement this feature. |
…age in LanguageType (javiereguiluz) This PR was squashed before being merged into the 5.1-dev branch (closes #32388). Discussion ---------- [Form] Allow to translate each language into its language in LanguageType | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #31562 | License | MIT | Doc PR | I'll do it if this is approved This would allow to set this option: ```php ->add('language', LanguageType::class, [ 'choice_self_translation' => true, ]) ``` To display each language translated into its own language:  @ro0NL if this proposal is approved, could you please tell me why I must `try ... catch` with `\Exception`? * First, I need the try..catch because of a special language with the code "root" which triggers exceptions (*The resource bundle "symfony-code/src/Symfony/Component/Intl/Resources/data/languages/root.json" does not exist*) * Second, I must catch \Exception because when I try to catch the exact exception (`Symfony\Component\Intl\Exception\ResourceBundleNotFoundException`) the exception is not caught. Why? Commits ------- 138200c [Form] Allow to translate each language into its language in LanguageType
Description
Lets say you have a language selector, now you are on the english site, so all the languages are in english fx
Now you select Russian, now the dropdown will look something like this
Instead it would be lovely to have a dropdown that always look something like this
Example
It would be exactly like doing this
\Locale::setDefault('fr');
$locales = Intl::getLocaleBundle()->getLocaleNames();
$french = $locales['fr'];
\Locale::setDefault('ru');
$locales = Intl::getLocaleBundle()->getLocaleNames();
$russian = $locales['ru'];
\Locale::setDefault('da');
$locales = Intl::getLocaleBundle()->getLocaleNames();
$danish = $locales['da'];
The text was updated successfully, but these errors were encountered: