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

Setting API locale does not work for many locales #2233

Closed
distantnative opened this issue Oct 20, 2019 · 6 comments

Comments

@distantnative
Copy link
Contributor

@distantnative distantnative commented Oct 20, 2019

This https://github.com/getkirby/kirby/blob/master/src/Api/Api.php#L178-L199 does not work for locales without _ where the first and second part are not equal, e.g. en_US from en.

Maybe we should add something like:
https://github.com/peterkahl/country-to-locale

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Oct 20, 2019

I just saw this component, maybe we can use it: Symfony Locale Component

https://github.com/symfony/Locale
https://symfony.com/doc/2.1/components/locale.html

@lukasbestle

This comment has been minimized.

Copy link
Contributor

@lukasbestle lukasbestle commented Oct 21, 2019

The Symfony component is long deprecated, we can‘t use that. It points to the “more capable” PHP Intl extension, but that one doesn’t provide this feature... 😫

@distantnative Doesn’t your suggestion convert the wrong way around? We’d need the opposite of “language to locale”.

Maybe a simple but manual solution could be to have a new locale key in our translation files that could then be manually filled with the correct locale for each Panel translation.

@afbora

This comment has been minimized.

Copy link
Contributor

@afbora afbora commented Oct 21, 2019

Maybe a simple but manual solution could be to have a new locale key in our translation files that could then be manually filled with the correct locale for each Panel translation.

I agree. How can I set the locale of our site as we want from the config file, the locale value of the user should also be updated. For example, there are dozens of locales in English.

To get all the locales, we could use ResourceBundle::getLocales(), a class like the following for the default locale.

And how about we create a new Locales class and get it from an array containing the default locale values of the languages? 🤔

<?php

class Locales {
    $locales = [
        ...
        'ar' => 'ar_SA',
        'en' => 'en_US',
        'de' => 'de_DE',
        'tr' => 'tr_TR',
        ...
    ];
    
    public function get(string $language) {
        ...
    }
    
    public function locales(string $language) {
        return $this->locales;
    }

    public function all(string $language) {
        return ResourceBundle::getLocales('');
    }
}
@lukasbestle

This comment has been minimized.

Copy link
Contributor

@lukasbestle lukasbestle commented Oct 21, 2019

As I said, I think we should manually include the locales in the i18n/translations files as a translation key.

The code in question works on the user language. The user language can only be one of the available Panel languages, so it's easy to map between the language and locale that way without having to guess.

@distantnative

This comment has been minimized.

Copy link
Contributor Author

@distantnative distantnative commented Oct 22, 2019

Sounds good, @lukasbestle

@lukasbestle lukasbestle self-assigned this Oct 22, 2019
lukasbestle added a commit that referenced this issue Nov 10, 2019
lukasbestle added a commit that referenced this issue Nov 10, 2019
lukasbestle added a commit that referenced this issue Nov 10, 2019
bastianallgeier added a commit that referenced this issue Nov 18, 2019
@bastianallgeier

This comment has been minimized.

Copy link
Contributor

@bastianallgeier bastianallgeier commented Nov 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.