最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Migration to the angular v9. i18n breaking changes - Stack Overflow

programmeradmin4浏览0评论

I'm migrating an Angular project from 8.2.14 to the 9.0.0-rc.14. Using i18n for localization.

I followed the guide here .2:9.0 and it feels it went fine. After the upgrade, I'm trying to run the project, but

ng serve leads to the following error:

An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
See "...my local logs path...\angular-errors.log" for further details.

In the angular-errors.log the error is more detailed:

[error] Error: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
    at createI18nOptions (...my project path...\node_modules\@angular-devkit\build-angular\src\utils\i18n-options.js:69:23)
    at Object.configureI18nBuild (...my project path...\node_modules\@angular-devkit\build-angular\src\utils\i18n-options.js:100:18)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I have got more details about the error: opening the @angular-devkit\build-angular\src\utils\i18n-options.js:69:23 and I see the following logic:

if (locale === i18n.sourceLocale) {
    throw new Error(`An i18n locale ('${locale}') cannot both be a source locale and provide a translation.`);
}

I have en-US locale and I want to continue using it as both translation and source. So how to fix this breaking error?

I'm migrating an Angular project from 8.2.14 to the 9.0.0-rc.14. Using i18n for localization.

I followed the guide here https://update.angular.io/#8.2:9.0 and it feels it went fine. After the upgrade, I'm trying to run the project, but

ng serve leads to the following error:

An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
See "...my local logs path...\angular-errors.log" for further details.

In the angular-errors.log the error is more detailed:

[error] Error: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
    at createI18nOptions (...my project path...\node_modules\@angular-devkit\build-angular\src\utils\i18n-options.js:69:23)
    at Object.configureI18nBuild (...my project path...\node_modules\@angular-devkit\build-angular\src\utils\i18n-options.js:100:18)
    at process._tickCallback (internal/process/next_tick.js:68:7)

I have got more details about the error: opening the @angular-devkit\build-angular\src\utils\i18n-options.js:69:23 and I see the following logic:

if (locale === i18n.sourceLocale) {
    throw new Error(`An i18n locale ('${locale}') cannot both be a source locale and provide a translation.`);
}

I have en-US locale and I want to continue using it as both translation and source. So how to fix this breaking error?

Share edited Feb 6, 2020 at 10:53 qiAlex asked Feb 6, 2020 at 10:39 qiAlexqiAlex 4,3562 gold badges21 silver badges35 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I assume your default language is different than English. Thus, you should have change the default source 'sourceLocale' as shown in the official docs.

So it would be like:

"projects": {
    "AngularApp": {
        "i18n": {
            "sourceLocale": "he-IL",
            "locales": {
                "en-US": "src/locale/messages.en.xlf"
            }
        },
...

simply open your angular.json file and remove the entry under locales which you have set under "sourceLocale". After the update locales only stores the translation not the language that you use in your source code.

Exactly, as @Markus said:

Your original language (developer) must not appear in '"locales": '.

Only in '"sourceLocale": '.

发布评论

评论列表(0)

  1. 暂无评论