ngx-translate-messageformat-compiler
ngx-translate-messageformat-compiler copied to clipboard
Adding ngx-translate-messageformat-compiler breaks all translations
Hello,
I'm currently have ngx-translate working well, and I'm now attempting to pluralise a string using ngx-translate-messageformat-compiler; however, as soon as I add it as a compiler to the translate module, all translations site-wide fail.
If I use the debug compiler, it prints to the console [TranslateMessageFormatCompiler] COMPILE (en)
plus the correct JSON data for all the sitewide translations, but doesn't do any compilation.
If I override the prototype to add additional logging, it errors on compile()
, and the MissingTranslationHandler
is triggered:
TranslateMessageFormatDebugCompiler.prototype.compileTranslations = function (translations, lang) {
console.log("compiling... (" + lang + ")");
console.log(translations);
var result = this.messageFormat.compile(translations, lang);
console.log("compilation result... (" + lang + ")", result);
return result;
};
This is on a fresh Ionic project:
angular: 8.1.3
@ngx-translate/core: 11.0.1
@ngx-translate/http-loader: 4.0.0
ngx-translate-messageformat-compiler: 4.5.0
messageformat: 2.3.0
Any help in further debugging would be greatly appreciated.
Cheers, Adam
Hello, I have the same problem. i lose all translations when i just add configuration for TranslateCompiler to my TranslateModule. I'm using angular 7.2 any help please ?
did you try to add "multi: true" in the provider provide: MESSAGE_FORMAT_CONFIG, useValue: { multi: true }
did you try to add "multi: true" in the provider provide: MESSAGE_FORMAT_CONFIG, useValue: { multi: true }
Hi @oharmali, I tried that thanks, but it still doesn't work.
@arctican I changed the method through the pipe I18nPluralPipe of angular, I invite you to watch it
Hi @mkhadiri-obconsulting i had the same issue and the cause was that I still had double curly brace placeholder in my translation JSON files, such as "sayHello": "Hello {{name}}"
. When you add ngx-translate-messageformat-compiler you need to convert them all to single curly brace "sayHello": "Hello {name}"
Thanks @markoivanovski , that's work for me too.
The fix suggested by @markoivanovski worked for me. Please consider that you have to ensure that all translations have the single curly brace notation. A single mistake in an unused translation breaks the entire compiler.
I would consider this being a critical issue because the translations are usually created by non-technicians and thus broken translations may occur on daily base. It is usually not a problem if a single translation is not working. However, it is a huge problem if all translations stop working because of that.
@lephyrus
Thank you very much for your work with the library.
I have a small question... Would it be possible to add a parameter in the settings so as not to need to replace all the strings already translated?
Or any other solution?! 🙃
"Is there a solution other than converting double brace to single? We started using MessageFormat after the implementation of ngx-translate. We have almost 4,000 references of the double brace {{}}." (ref.: last comment issue 45)
@rabraganca Version 7.0.0 now catches and logs errors by default, rather than breaking all translations if there is a syntax error in any message. You can now also configure a fallbackPrefix
, which allows still using the default syntax for messages that start with that prefix.