1

To compile a translated app, I do:

ng build -bh=fr --i18nFile=src/i18n/messages.fr.xlf --locale=fr --output-path=dist/fr

If I have a third-party component with messages that have been localized in French, is there a way to include its translations in the final output as well? Or do I need to ensure that they're translated in the consuming application and pass them into the component.

In particular, if I have my-app-1 and my-app-2, can I readily import @my/component-module along with its own messages (/node_modules/@my/component-module/i18n/messages.fr.xlf)?

Simply adding the strings to my-app-1/src/i18n/messages.fr.xlf and my-app-2/src/i18n/messages.fr.xlf and passing them as inputs to @my/component-module is less than ideal, as it means I now have to maintain those strings in 3 separate places.

jameslafferty
  • 2,152
  • 2
  • 21
  • 25
  • what is `-bh` for? are you sure its not deprecated? – Night Train Jan 16 '18 at 10:59
  • 1
    @NightTrain: It's the short form of --base-href. It's there because in theory we'd be serving French from /fr, Spanish from /es, German from /de, etc, and redirecting to the correct build based on the user's language. – jameslafferty Jan 16 '18 at 15:49
  • You have a typo in your command. it's `--i18nFile`. I dont understand what you are trying to do, or where you are stuck. thats the command I used to build my app `ng build --prod --i18nFile src/i18n/messages.fr.xlf --i18nFormat xlf --locale fr --output-path=./dist/fr --base-href "https://USERNAME.github.io/REPO/"` – Night Train Jan 17 '18 at 10:03
  • I'll fix the typo in the example. The issue is that I've got a component in its own node_module, let's say @my/component, that I want to use in my application and that I'd like to provide its own localized strings. There doesn't seem to be any mechanism for it to provide its own strings to the consuming app. – jameslafferty Jan 17 '18 at 22:33
  • 1
    I'm not sure if that feature is even planned in Angular. I wrote an answer to another i18n question here: https://stackoverflow.com/questions/41824611/angular-internationalization-i18n-and-ngfor/47957171#47957171 there are two interesting Github Issues, that inform about the progress in with the i18n feature: https://github.com/angular/angular/issues/16477 https://github.com/angular/angular/issues/21578 so maybe in Angular 6 your requested feature might be available.. Otherwise just create an Issue :) – Night Train Jan 19 '18 at 09:24

0 Answers0