Skip to content

Remove BazingaJsTranslationBundle #528

Description

@marien-probesys

This bundle allows to use the Symfony translations directly in Javascript. But it also adds a lot of complexity to our setup, while we don't really need it. Luckily, it is not used widely.

In dashboard/stats-by-days.html.twig and dashboard/stats-by-status.html.twig templates, replace the calls to Translator.trans by their Twig equivalent (e.g. Translator.trans('Navigation.untreated') by {{ 'Navigation.untreated' | trans }}).

In app/assets/controllers/add_ip_address_controller.js, replace the calls to Translator.trans by Stimulus values (e.g. Translator.trans('Message.Actions.Delete') by this.deleteLabelValue). Then, pass the values to the add-ip-address Stimulus controller in the domain/_form.html.twig template (data-add-ip-address-delete-label-value="{{ 'Message.Actions.Delete' | trans }}")

Now, the last but hardest part. In public/js/agentj.js, add a JS function:

function trans (key) {
    const translation = window.jsTranslations[key];
    if (translation) {
        return translation;
    } else {
        return key;
    }
};

In the same file, replace the calls to Translator.trans by the new trans function (e.g. Translator.trans('Message.Actions.massiveActionContent') by trans('Message.Actions.massiveActionContent')). Now, in base.html.twig (and only there!) add a new tag in <head> (didn't tested, but it should work):

<script id="jsTranslations" type="application/json">
    {{ {
        'Message.Actions.massiveActionContent': 'Message.Actions.massiveActionContent' | trans,
        'Generics.flash.editSuccess': 'Generics.flash.editSuccess' | trans,
        'Generics.labels.yes': 'Generics.labels.yes' | trans,
        'Generics.labels.cancel': 'Generics.labels.cancel' | trans,
    } | json_encode }}
</script>

BazingaJsTranslationBundle shouldn't be used anymore, so let remove the willdurand/js-translation-bundle dependency in composer.json (adapt where it's needed in the Symfony config).

Remove the following files and folders:

  • public/bundles/
  • public/js/translations/
  • public/js/intl-messageformat-9.0.2.min.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions