Wednesday, 7 October 2020

Specify source language, if the default_locale is not english

I am working on a website for a French customer. My translations.yml looks like this:

framework:
    default_locale: en
    translator:
        default_path: '%kernel.project_dir%/translations'
        fallbacks:
            - fr

I write everything in english, and then run this command:

php bin/console translation:update --force fr

It generates .xlf, files with these parameters:

source-language="en" target-language="fr"

It works as expected.

I would like to make the login page French as well. That page is visited, when the user is not logged in yet, so default_locale is used.

I changed default_locale to fr and fallbacks to en.

The login page is displayed in French as expected, but now the translation:update script is broken. If I run it, the resulting translation files have these incorrect parameters:

source-language="fr" target-language="fr"

How is it possible to use a different source language for translations and default locale for pages, where the user is not logged in? Or is it possible to use the locale from the user agent in that case?



from Specify source language, if the default_locale is not english

No comments:

Post a Comment