diff --git a/.changes/unreleased/Feature-20241118-150627.yaml b/.changes/unreleased/Feature-20241118-150627.yaml new file mode 100644 index 000000000..765d66f08 --- /dev/null +++ b/.changes/unreleased/Feature-20241118-150627.yaml @@ -0,0 +1,7 @@ +kind: Feature +body: "Implementation of new translation management with one source of truth for both + twig and vue component templates using YAML files. \nDuplicate translation keys + can also be detected with new command." +time: 2024-11-18T15:06:27.929549251+01:00 +custom: + Issue: "" diff --git a/composer.json b/composer.json index f72ad3135..c247e978d 100644 --- a/composer.json +++ b/composer.json @@ -67,10 +67,12 @@ "symfony/security-guard": "^5.4", "symfony/security-http": "^5.4", "symfony/serializer": "^5.4", + "symfony/stimulus-bundle": "^2.19", "symfony/string": "^5.4", "symfony/templating": "^5.4", "symfony/translation": "^5.4", "symfony/twig-bundle": "^5.4", + "symfony/ux-translator": "^2.19", "symfony/validator": "^5.4", "symfony/webpack-encore-bundle": "^1.11", "symfony/workflow": "^5.4", diff --git a/config/bundles.php b/config/bundles.php index 815c3e62d..2b02f90a9 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -36,4 +36,6 @@ return [ Chill\BudgetBundle\ChillBudgetBundle::class => ['all' => true], Chill\WopiBundle\ChillWopiBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true], + Symfony\UX\Translator\UxTranslatorBundle::class => ['all' => true], ]; diff --git a/config/packages/ux_translator.yaml b/config/packages/ux_translator.yaml new file mode 100644 index 000000000..1c1c70608 --- /dev/null +++ b/config/packages/ux_translator.yaml @@ -0,0 +1,3 @@ +ux_translator: + # The directory where the JavaScript translations are dumped + dump_directory: '%kernel.project_dir%/var/translations' diff --git a/docs/source/development/translations.rst b/docs/source/development/translations.rst new file mode 100644 index 000000000..818e7bd4b --- /dev/null +++ b/docs/source/development/translations.rst @@ -0,0 +1,31 @@ +Translations +************* + +Translator-UX: one source of truth +================================== + +The Translator-ux integration streamlines the process of managing and using translation keys dynamically in our views, whether they be in twig or vue components. The goal is to have one source of truth +for all translations and avoid having to add translation keys in the YAML files as well as in i18ns files. + +To add new translation keys, you can define them in your translation YAML files. Running `symfony console cache:clear` will subsequently update the compiled translation keys which can then also be imported and +used within any vue component. For use within a twig template they can be leveraged by using the |trans function. +Within vue components you will have to import the translation keys you require and then they can be used in the template with the trans() function. + +It is advisable, before adding a translation key to do a search on the existing translation keys of the translation you require. An IDE will allow you to do so easily. +However to avoid the creation of duplicate translation keys a command also exists to detect them. We also strongly advise you to use this command as explained below. + +Detect duplicates command +========================= + +The DetectTranslationDuplicatesCommand `chill:detect-duplicate-translations` is a Symfony console command designed to identify duplicate translations across YAML files in a project. +It checks for repeated translation values linked to different keys within a specified locale. +The command accepts two main options: + +1. `--locale`: to specify the language locale to check (defaulting to 'en') +2. `--exclude-namespaces`: to list namespaces to ignore during the check. +3. [optional] `--verify-hash`: can be used to ensure that the hash of current duplicates matches a given expected value, +aiding in maintaining translation integrity. + +When duplicates are detected, they are displayed in a table format, listing the repeated translations alongside the keys where they are found. +If a mismatch occurs between the computed and expected hash values, an error message is displayed to signal a potential issue in translation consistency. +This command is useful for maintaining clean and consistent translations, avoiding redundancy in your YAML files. diff --git a/package.json b/package.json index d4537d59b..eb45c1388 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,9 @@ "@ckeditor/ckeditor5-markdown-gfm": "^41.4.2", "@ckeditor/ckeditor5-theme-lark": "^41.4.2", "@ckeditor/ckeditor5-vue": "^5.1.0", + "@hotwired/stimulus": "^3.0.0", + "@symfony/stimulus-bridge": "^3.2.0", + "@symfony/ux-translator": "file:vendor/symfony/ux-translator/assets", "@symfony/webpack-encore": "^4.1.0", "@tsconfig/node14": "^1.0.1", "@types/dompurify": "^3.0.5", @@ -21,6 +24,7 @@ "chokidar": "^3.5.1", "dompurify": "^3.1.0", "fork-awesome": "^1.1.7", + "intl-messageformat": "^10.5.11", "jquery": "^3.6.0", "marked": "^12.0.1", "node-sass": "^8.0.0", diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/ConcernedGroups.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/ConcernedGroups.vue index 7ec62d07d..edd6434ca 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/ConcernedGroups.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/ConcernedGroups.vue @@ -22,8 +22,8 @@
- {{ $t('you_subscribed_to_all_steps') }} + {{ trans(WORKFLOW_YOU_DESCRIBED_TO_ALL_STEPS) }}
- {{ $t('you_subscribed_to_final_step') }} + {{ trans(WORKFLOW_YOU_SUBSCRIBED_TO_FINAL_STEP) }}