Skip to content

[Translator] How to properly use UX Translator from a Bundle? #1034

@asdfMaciej

Description

@asdfMaciej

Hello,

I'm creating a bundle with the following assets/ directory structure:
image

I have manually copied translator.js from existing application code, and modified it to use different relative paths:

import { localeFallbacks } from '../../../var/translations/configuration';
import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';

setLocaleFallbacks(localeFallbacks);

export { trans };

export * from '../../../var/translations';

The paths are relative to the node_modules directory, as during yarn build the file resides in /node_modules/@company-name/bundle-name/translator.js. The path isn't relative to the vendor/ directory, autocomplete gets it wrong.

Is this the correct approach to use UX Translator within a bundle? Or is there a better approach? Depending on the directory structure feels brittle to me and I wasn't able to find an answer regarding this topic.

I'm creating an Issue instead asking on Stack Overflow, as I would love to see this in the official documentation.

Thanks in advance :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions