i18n-polyfill icon indicating copy to clipboard operation
i18n-polyfill copied to clipboard

Missing translation error on JIT

Open carlos-ferras opened this issue 6 years ago • 6 comments

The thing is that I have configure this:

{
  provide: MISSING_TRANSLATION_STRATEGY,
  useValue: MissingTranslationStrategy.Ignore
}

in my app.module.ts

and this:

platformBrowserDynamic().bootstrapModule(
  AppModule,
  {
    missingTranslation: MissingTranslationStrategy.Ignore,
  }
)

in my main.ts

The error is triggered here:

function xliffLoadToI18n(content) {
    // xliff to xml nodes
    var /** @type {?} */ xliffParser = new XliffParser();
    var _a = xliffParser.parse(content), msgIdToHtml = _a.msgIdToHtml, errors = _a.errors;
    // xml nodes to i18n messages
    var /** @type {?} */ i18nMessagesById = {};
    var /** @type {?} */ converter = new XmlToI18n();
    Object.keys(msgIdToHtml).forEach(function (msgId) {
        var _a = converter.convert(msgIdToHtml[msgId]), i18nNodes = _a.i18nNodes, e = _a.errors;
        errors.push.apply(errors, e);
        i18nMessagesById[msgId] = i18nNodes;
    });
    if (errors.length) {
        throw new Error("xliff parse errors:\n" + errors.join("\n")); // HERE IS TRIGGERED
    }
    return i18nMessagesById;
}

carlos-ferras avatar Jan 09 '18 15:01 carlos-ferras

Is the error saying that you have missing translations? If it's throwing in the xliff parser, it looks more like your xliff file has errors

What's the error message, and what's the content of your xliff file?

ocombe avatar Jan 09 '18 16:01 ocombe

Yes, I know what it say, but I want to ignore it, not an error when it happen, anyway thanks for your work, I've been waiting a long time for this.

carlos-ferras avatar Jan 10 '18 20:01 carlos-ferras

If it's not an error, then the warning is an error :D Do you know what's causing this?

ocombe avatar Jan 10 '18 21:01 ocombe

Yes, it 's because I have not a target translation tag for the source text, normally angular ignore this an use as target the value in source.

carlos-ferras avatar Jan 10 '18 21:01 carlos-ferras

I believe that this behavior was changed in Angular, I'll check

ocombe avatar Jan 11 '18 07:01 ocombe

I already managed to avoid the error, just doing this:

package.json:

"scripts": {
    "start": "ng serve --open --locale es",
    "build": "for lang in en es; do ng build --aot --prod --bh /$lang/ --output-path=dist/$lang --i18n-file=src/locale/messages.$lang.xlf --i18n-format=xlf --missing-translation=ignore --locale=$lang; done",
    "i18n": "npm run i18n-templates && npm run i18n-ts && npm run i18n-merge",
    "i18n-templates": "ng xi18n -f xlf --output-path src/locale --outFile=messages.xlf --locale es",
    "i18n-ts": "ngx-extractor -i \"src/**/*.ts\" -f xlf -o src/locale/messages.xlf",
    "i18n-merge": "for lang in en es; do xliffmerge --profile xliffmerge.json es $lang; done"
  }

xliffmerge.json:

{
  "xliffmergeOptions": {
    "srcDir": "src/locale",
    "genDir": "src/locale",
    "defaultLanguage": "es",
    "i18nFile": "messages.xlf",
    "useSourceAsTarget": true
  }
}

what I did was generate the translation files with the translations initialized in the source. Clarify that if the translations are not generated with the target, the error persists, that should be checked anyway.

carlos-ferras avatar Jan 11 '18 21:01 carlos-ferras