i18n-polyfill
i18n-polyfill copied to clipboard
Extraction fails with split strings (concatenation of 2 strings)
When a value is the result of the concatenation of 2 strings, I got the following error after running ng xi18n
and ngx-extractor
:
node_modules/@ngx-translate/i18n-polyfill/extractor/src/abstract-ast-parser.js:29
throw new Error(`An I18nDef requires a value property on '${this.syntaxKindToName(firstArg.kind)}' for ${firstArg}`);
^
Error: An I18nDef requires a value property on 'ObjectLiteralExpression' for [object Object]
Example of i18n-polyfill use that causes this issue:
this.i18n({ value: 'My ' + 'value', id: 'myId', description: 'myDescription' });
The reason why I have some split strings is that my editor wraps line at 120 characters.
The problem also happens for invocations with strings (not I18nDef
):
this.i18n('My ' + 'value');
I propose a simple fix at #50.
I get the same error message with this syntax:
this.i18n({
meaning: 'ChangeProfilePictureComponent',
description: 'Error Message if wrong File Type is supplied',
id: 'ChangeProfilePictureComponentErrorWrongFileType',
value: `The File Type '${file.type}' is not supported.`
})
@DanielHabenicht change `The File Type '${file.type}' is not supported.` to 'The File Type {{file.type}}
is not supported.' You need to use the interpolation syntax instead of ${file.type}
syntax
@sChupin a possible work around for long lines would be to use ` instead of ' for the string you need to split on different lines that way you don't need to use the plus operator:
Example:
this.i18n({ value: `My really really really really really really \
really really really really really really really really really \
really really really really really really really really really really really long string`,
id: 'myId', description: 'myDescription' });
rather than
this.i18n({ value: 'My really really really really really really' +
'really really really really really really really really really' +
'really really really really really really really really really really really long string',
id: 'myId', description: 'myDescription' });