question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use translation file for en-US: "An i18n locale ('en-US') cannot both be a source locale and provide a translation"

See original GitHub issue

🐞 bug report

I can’t use a translation file for en-US:

i18n": {
    "locales": {
      "en-US": {
        "baseHref": "delete/us/en_us",
        "translation": "messages.en-us.xlf"
      }
    }
}

Description

  • Our app is translated into 40+ languages
  • We want our translation department to be responsible for all strings
  • We want to ignore the strings our developers have written in the HTML files
  • Therefore we need one build per messages.xlf file and no build for the “sourceLocale”
  • At the moment we are forced to manually copy the strings from the messages.en-us.xlf file back into our HTML every time our translation department makes a change to en-US

Possible solutions:

  • Allow "translation" as a property of "sourceLocale"
"sourceLocale": {
  "code": "en-US",
  "translation": "messages.en-us.xlf"
}
  • Add option to prevent the build of the source locale

🔬 Minimal Reproduction

https://github.com/MartinJaskulla/angular-issue-38316

🔥 Exception or Error


An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation.

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.7
Node: 12.13.1
OS: darwin x64

Angular: 9.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.7
@angular-devkit/build-angular     0.900.7
@angular-devkit/build-optimizer   0.900.7
@angular-devkit/build-webpack     0.900.7
@angular-devkit/core              9.0.7
@angular-devkit/schematics        9.0.7
@angular/localize                 9.1.12
@ngtools/webpack                  9.0.7
@schematics/angular               9.0.7
@schematics/update                0.900.7
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant? I know that there are several workarounds. For example we could provide a non-existent source locale "sourceLocale": "aa-aa" and delete the build afterwards. However our app is very big and we want to save the build time. Furthermore our actual setup is more complex than the example provided above. For example the translations for the same locale e.g. my-app.com/de/en-US and my-app.com/us/en-US can be different. It would be useful for angular.json to provide some sort of nesting of the locales.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:25
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
simonpeterscommented, Dec 2, 2020

Same issue here, we only have one language but would like to use i18n so we can use translation tools to have non developers change the strings we use.

2reactions
doliGcommented, Feb 9, 2021

I use the same workaround as @nelisbijl with aa-AA as ISO code and it works.

But this is not a correct solution, can maintainer have a look at this ticket and give us a status ?

poke @alan-agius4 @clydin @filipesilva @hansl and so on…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration to the angular v9. i18n breaking changes
An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation. See "...my local logs path.....
Read more >
React localization with i18next - LogRocket Blog
To localize a React application using the i18next, ... i18next through the i18n instance provides a translation function called t() .
Read more >
Process/Translate Blender - Blender Developer Wiki
Sometimes you may see some text in the UI, but no matching message exists in the translation files. This probably means that the...
Read more >
Internationalization - MDN Web Docs - Mozilla
json, then the correct translation of the string will be displayed to the user, based on the current locale, like so. To internationalize ......
Read more >
Internationalization (i18n) - grammY
Finding the proper translation is done using a locale negotiator. ... bot might not be able to see the user's preferred language provided...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found