A bundle that extracts translations
This bundle provides several helpers for working with translations.
First install this package:
composer require becklyn/translations
Then import the routing:
_import.becklyn_translations: resource: '@BecklynTranslationsBundle/Resources/config/routes.yaml' prefix: /_v/translations/
becklyn_translations: extract: frontend: messages: - test - abc.* backend: - *.error admin: messages: - admin.test.* cache_version: 1
It is a nested array, where the first level key is the namespace (more on that below). The second level key is the
translation domain and the values are the message keys. You can use
* as a placeholder for the message keys.
The translations dumps are separated into namespaces, so that there can be for example one dump for frontend translations and one for the backend translations. The namespaces are just labels and are passed to the init function (see the next chapter).
This bundle exposes an endpoint that can be used to load translations in JS. Include it in your Twig using the twig function:
It will automatically use the locale of the current master request. To override this behaviour a custom locale can be passed:
The dumped translations will be added to a global
window.TranslatorInit.data object. These are nested maps, the
outer map has the domain as key, the inner value is a mapping from key → translation.