New in Symfony 5.3: Translation Providers

Symfony 5.3 is backed by JoliCode. JoliCode is a team of passionate developers and open-source lovers, with a strong expertise in PHP & Symfony technologies. They can help you build your projects using state-of-the-art practices.

Contributed by
Mathieu Santostefano
in #38475.

The process of translating Symfony applications requires extracting all translatable contents from templates and code. This task is boring and error-prone; that’s why Symfony provides a translation:update command to extract contents and update catalogs automatically.

This works great, unless your application uses external translation services with their own local or SaaS-based translation tools. Then you need to send them the translation catalogs from time to time to translate the new contents and then merge the returned catalog back into your application.

In Symfony 5.3 we’ve improved this workflow thanks to the integration of external translation providers. You can now upload/download translations to services like Crowdin, Loco and Lokalise and merge the new translations automatically into your application.

Let’s imagine that you hire a translation company that uses Crowdin to share their work with you. First, configure the access to this provider:

1
2
3
4
5
6
7
8
# config/packages/translation.yaml
framework:
    translator:
        providers:
            crowdin:
                dsn: 'crowdin://PROJECT_ID:[email protected]_DOMAIN.default'
                domains: ['messages']
                locales: ['en', 'ja']

Now you can upload the current application translations with this command:

1
2
3
4
5
6
7
8
# upload all translations for all locales
$ php bin/console translation:push crowdin --force

# or upload translations only for some locale(s)
$ php bin/console translation:push crowdin --locales ja

# or just upload the translations of a particular domain
$ php bin/console translation:push crowdin --domain admin

Similarly, you can download the translations from the external service and let Symfony merge them automatically with the existing translations:

1
2
3
4
5
6
# download all translations for all locales
$ php bin/console translation:pull crowdin --force

# download all translations for 'ja' locale and add the new
# translations into the existing file
$ php bin/console translation:pull crowdin --locales ja

Both commands define more flags and options. Run them with the --help option to learn about those options.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

Comments

Great
very cool
Thank you for this cool feature 😎👍🏻
YES!!
Nice Functionality
Very great feature

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.