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

Extraction fails with split strings (concatenation of 2 strings)

Open sChupin opened this issue 5 years ago • 4 comments

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.

sChupin avatar Nov 08 '18 10:11 sChupin

The problem also happens for invocations with strings (not I18nDef):

this.i18n('My ' + 'value');

I propose a simple fix at #50.

adrienverge avatar Feb 18 '19 15:02 adrienverge

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 avatar Mar 25 '19 14:03 DanielHabenicht

@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

SurienDG avatar Nov 01 '19 14:11 SurienDG

@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' });

SurienDG avatar Nov 01 '19 14:11 SurienDG