GeezerVison is showing github.com — Can't use translation file for en-US: "An i18n locale ('en-US') cannot both be a source locale and provide a translation" · Issue #18422 · angular/angular-cli
Can't use translation file for en-US: "An i18n locale ('en-US') cannot both be a source locale and provide a translation" #18422Description🐞 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. Reacted by Guillaume, delrueba, PopePAF, dmrickey, Filip Šalda, Ben Sorohan, Aly Ahmed, Frank Mosca, multimike77, Andriy Doroshenko and 25 more Reacted by Timur Mishagin Reacted by Timur Mishagin and Tizian Roth ActivitydoliG commented on Aug 11, 2020 I have the same problem, and agree with the suggested solution
Allow translation as a property of sourceLocale
Reacted by Boyd and Camila E. Blanc Fick simonpeters commented on 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. Reacted by Frank Mosca, Boyd, lammas, praxem, nelisbijl, Oleksii and Kyle Bradshaw praxem commented on Jan 29, 2021 We have the same problem...
It is strange to think that in a huge complex application the main source of the language will be in HTML ... Reacted by Frank Mosca, Camila E. Blanc Fick and Timur Mishagin nelisbijl commented on Feb 9, 2021
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.
My workaround:
Configure a fake sourceLocale in angular.json. I used zxx, which is actually a valid ISO639-2 code (https://www.loc.gov/standards/iso639-2/php/code_list.php)
Only downside is a warning during ng extract-i18n:
Warning: AngularCompilerPlugin: Unable to load the locale data file "@angular/common/locales/zxx", please check that "zxx" is a valid locale id.
If needed, you can use "registerLocaleData" manually.
That will possibly disappear when you choose a different valid locale code not used by your application doliG commented on 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... Reacted by Stefan Schweiger, praxem, Timur Mishagin and Tim Gatzemeier stefan-schweiger commented on Apr 21, 2021 Any potential update on this issue? It's really annoying to manage all your text with a service like lokalise.com when you can't have the source locale as a translation target. Reacted by praxem and Timur Mishagin clydin commented on Apr 21, 2021 Private use subtags can be used to describe the unique nature of the source locale in these type of cases. For example, the following configuration section provides for a translated de locale while also describing the content within the source code as untranslated.
“i18n”: {
“sourceLocale”: “de-x-source”,
“locales”: {
“de”: “./locales/de.xliff2”,
“en”: “./locales/en.xliff2”,
“fr”: “./locales/fr.xliff2”
}
}
stefan-schweiger commented on Apr 22, 2021 @clydin I needed to change a few things in my extraction and upload scripts but this works well. Thank you very much :) martijn19811 commented on Nov 14, 2021 @clydin Hi, I'm having the same issue here. Would like to use a default translations file for my sourceLocale. Although Im not sure how.
"i18n": {
"sourceLocale": "nl-x-source",
"locales": {
"nl": "src/locale/messages.nl.xlf"
}
}
The build works and the NL language is being used, but it does not use the translation file. what am I missing here?
Oh, and Im actually not using the --localize flag in the application. I just want the default build to have a few translations. That's it :). Thanks for your help in advance! changed the title [-]Can't user translation file for en-US: "An i18n locale ('en-US') cannot both be a source locale and provide a translation"[/-] [+]Can't use translation file for en-US: "An i18n locale ('en-US') cannot both be a source locale and provide a translation"[/+] on Feb 14, 2022t-mish commented on Jun 23, 2023 Angular team please pay attention to it because it's seems not so hard to do but can make developers' life much easier. Reacted by Lars Rye Jeppesen, karta571110, Wim Holvoet, joostgaren123, Badr Eddine ATTALBI ALAMI and Tim Gatzemeier createdbyjurand commented on Jan 24, 2024 doliG commented on Jan 25, 2024 attalbialami commented on May 16, 2024 adi-wtag commented on Jul 29, 2024 ahimik commented on Aug 10, 2024
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|