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

Improve locale on multi-language setups #13

Open
andrepimpao opened this issue Nov 22, 2024 · 1 comment
Open

Improve locale on multi-language setups #13

andrepimpao opened this issue Nov 22, 2024 · 1 comment

Comments

@andrepimpao
Copy link
Contributor

Currently, when a website has a multi-language setup, the plugin finds the locale based on the active language code, but I believe it should get the language locale instead, to be coherent with how Kirby handles translations too.

For example, I am from Portugal, and the code we use is pt (for the URL) but out locale is pt_PT (Portuguese from Portugal, different from pt_BR (Brazil), pt_AO (Angola), and so on).

So right now, if I have the Portuguese language with code pt and locale pt_PT, the popup will be in German, instead of the pt_PT translation that currently exists in the plugin, because it is trying to find the pt.php translation file instead of the pt_PT.php.

This can be solved by changing the following line code:

private static function getTranslations()
{
    $translations = kirby()->option('zephir.cookieconsent.translations');
    $locale = kirby()->option('zephir.cookieconsent.language.locale', 'en');

    if (option('languages')) {
        // change this line
        // $locale = kirby()->language()->code();
        $locale = kirby()->language->locale(LC_ALL);
    }

    if (empty($translations[$locale])) {
        return $translations[array_key_first($translations)];
    }

    return $translations[$locale];
}

I can create a PR if you want.

Thank you.

@TheMaaarc
Copy link
Member

Hi @andrepimpao

Feel free to create a PR, I will merge it asap.

My response times are a bit long as we have moved from Kirby to Statamic, which suits our needs better.
I will still maintain the plugin by merging PRs and releasing them, but it will take some time for me to respond.

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

No branches or pull requests

2 participants