-
-
Notifications
You must be signed in to change notification settings - Fork 202
Bug(messageformat): Plural translation starting and ending with a variables fails #621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
There is a conflict between transloco and messageformat patterns. For A workaround is to use another pattern for transloco by replacing the default configuration of The final solution may be to add forbidden characters for parameters name: export interface TranslocoConfig {
[...]
interpolation?: [start: string, end: string, forbiddenChars?: string];
} By default it may be It can also be nice to escape regex reserved characters: function resolveMatcher(userConfig?: TranslocoConfig): RegExp {
- const [start, end] =
+ const [start, end, forbiddenChars] =
userConfig && userConfig.interpolation
? userConfig.interpolation
: defaultConfig.interpolation!;
+ const matchingParamName = forbiddenChars !== undefined ? `[^${escapeForRegExp(forbiddenChars)}]` : '.';
+ return new RegExp(`${escapeForRegExp(start)}(${matchingParamName}*?)${escapeForRegExp(end)}`, 'g');
- return new RegExp(`${start}(.*?)${end}`, 'g');
}
+function escapeForRegExp(text: string) {
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+} What do you think about this ? |
@julpellat What's wrong with the workarounds you provided? |
Hi, sorry for the late response. To answer your question @shaharkazaz I can’t use the workarounds I provided because we use lokalize and lokalize generate the json file used by transloco. |
…acters and transloco-validation unit tests
Hi, the PR seems to be ready since late march. Is there still some work needed to merge ? Can I help in any way ? |
@julpellat I was looking since yesterday all day long and I found the solution I have on my file |
@julpellat I need to fully understand the use case and make sure this isn't adding a bunch of code to a very specific use case. (seeing @JMCelesti comment) |
…acters and transloco-validation unit tests
…r forbidden characters
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
@ngneat/transloco-messageformat
Is this a regression?
No
Current behavior
I have the following translation using plural in my en.json file :
"MONITORING_CALLOUT": "{count, plural, \none {{count} manager n’a pas réalisé sa déclaration de variables à la date d'échéance pour la période de {period}} \nother {{count} n'ont pas réalisé leur déclaration de variables à la date d'échéance pour la période de {period}}\n}"
The page load but nothing show on the screen. Nor the value, nor the translation key. And I have the following error in the console
After some testing my conclusion are :
Example :
"{count, plural, \none {bla bla} \nother {{var1} bla bla {var2}}"
Like this
"{count, plural, \none {bla bla} \nother {{var1} bla bla {var2} }"
or at the start"count, plural, \none {bla bla} \nother { {var1} bla bla {var2}}"
#
it also works fine"{count, plural, \none {bla bla} \nother {# bla bla {var2}}"
Expected behavior
The syntax
"KEY": "count, plural, \none {bla bla} \nother {{var1} bla bla {var2}}"
should not throws any error.Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/transloco-messageformat-giflos?file=src%2Fassets%2Fi18n%2Fen-US.json,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.module.ts,src%2Findex.html
Transloco Config
No response
Please provide the environment you discovered this bug in
Browser
Additional context
No response
I would like to make a pull request for this bug
No
The text was updated successfully, but these errors were encountered: