, (*1)
Symfony Bundle to format and sort translation files, (*2)
Have you ever been fed up about keeping the content of your Symfony translation files organized, well structured and sorted? Yeah, me too. That's why I developed this little bundle to make things easier., (*3)
What it does:
* structures your translation files by a given template (which you can override of course)
* alphabetically sorts your entries by the source key
* checks for duplicate trans-unit id's in your xlf files
* optionally validates your xlf files against a xsd schema, (*4)
Limitations:
* only works for xlf/xliff files at the moment, (*5)
Get the bundle using composer
To install the bundle, require it using composer by running the following command at the root of your application:, (*6)
composer require decline/transformat-bundle
Enable the bundle
Register the bundle in your application's kernel class:, (*7)
// app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Decline\TransformatBundle\DeclineTransformatBundle(),
// ...
];
}
}
This could be a possible configuration for the bundle:, (*8)
decline_transformat:
directory: "%kernel.root_dir%/Resources/translations" # The directory where the translation files are located.
xliff:
extension: xlf # The extension of the translation files which should be formatted. Default value is 'xlf', can be one of ['xlf', 'xliff']
sourceLanguage: en # The source language of the translation files. Default value is 'en'
namespace: urn:oasis:names:tc:xliff:document:1.2 # The xml namespace for translation files. Default value is 'urn:oasis:names:tc:xliff:document:1.2'
validation: false # If set, your xlf files will be validated against either a transitional or strict xsd schema. Default value is 'false', can be one of [false, 'transitional', 'strict']
Usage
Format all files in the directory which was configured in the settings:, (*9)
bin/console transformat:format
Format a single file in the directory which was configured in the settings:, (*10)
bin/console transformat:format foobar.en.xlf
Override template
If you wish to override the twig template which is used for generating the formatted xlf-files, no problem! Just copy the twig template from, (*11)
vendor/decline/transformat-bundle/Resources/views/format.xml.twig
to this location (for example) in your application, (*12)
app/Resources/DeclineTransformatBundle/views/format.xml.twig
and make your desired adjustments., (*13)