ngx-translate-messageformat-compiler icon indicating copy to clipboard operation
ngx-translate-messageformat-compiler copied to clipboard

Adding ngx-translate-messageformat-compiler breaks all translations

Open arctican opened this issue 5 years ago • 7 comments

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

arctican avatar Sep 01 '19 21:09 arctican

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 ?

mkhadiri-obconsulting avatar Sep 02 '19 23:09 mkhadiri-obconsulting

did you try to add "multi: true" in the provider provide: MESSAGE_FORMAT_CONFIG, useValue: { multi: true }

oharmali avatar Sep 03 '19 10:09 oharmali

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 avatar Sep 04 '19 11:09 arctican

@arctican I changed the method through the pipe I18nPluralPipe of angular, I invite you to watch it

mkhadiri-obconsulting avatar Sep 04 '19 17:09 mkhadiri-obconsulting

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}"

markoivanovski avatar Oct 09 '19 06:10 markoivanovski

Thanks @markoivanovski , that's work for me too.

tidall87 avatar Jan 06 '20 11:01 tidall87

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.

dimw avatar Jan 31 '20 23:01 dimw

@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 avatar Feb 01 '24 20:02 rabraganca

@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.

lephyrus avatar Feb 09 '24 12:02 lephyrus