Skip to content

[Translator] TranslationsDumper generates duplicate keys in JS translation files  #938

Closed
@jkgroupe

Description

@jkgroupe

When I generate JS translation files, I cannot use it because I have duplicate keys.

For instance, if I have 2 different translations ids like Error and Error. in my translation files, it generates the same key in JS file as ERROR so I have it twice in my translation file and I cannot build my JS files

Capture d’écran 2023-06-13 à 16 09 55

The problem comes from the TranslationsDumper class which using translation id instead of constant name in getTranslations method

The id should be the final constant name to exclude duplicate keys instead of the translation id like below

$constantName = s($id)->ascii()->snake()->upper()->toString();

$translations[$constantName] ??= [];
$translations[$constantName][$realDomain] ??= [];
$translations[$constantName][$realDomain][$locale] = $message;

Hope this is clear for everyone

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions