lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 29 forks source link

Fix if language not "en". #29

Closed alonstar closed 6 years ago

alonstar commented 6 years ago

If lang is not "en" ("en" is messageformat default language), messageformat will throw errors.

So, I add a languages property in MessageFormatConfig to configure messageformat.

santialbo-actimo commented 6 years ago

Hi @lephyrus could we get this merged and released? This is the real fix to issues like #25 and #26.

tmell004 commented 6 years ago

Hi Guys,

Could you help me in this on :

when i make delete button , i got this error message :

core.js:1624 ERROR TypeError: Cannot read property 'id' of undefined at SafeSubscriber._next (my-form.component.ts:40) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:195) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:133) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:77) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:41) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at XMLHttpRequest.onLoad (http.js:1055) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:3748)

here is my code of delete button :

---- html ---

  • {{item.id}} | {{item.name}} | {{item.email}}
-------- ts file --------- deleteItem(id){ this.dataService.deletePerson(id).subscribe(res => { console.log(res); for(let i=0; i < this.users.length; i++){ if(this.user[i].id == id){ this.users.splice(i,1); } } }); } Thanks in advance;
alonstar commented 6 years ago

@lephyrus how about this question? Angular is already 6.1 .

lephyrus commented 6 years ago

@alonstar Sorry for the late reply, I took a longer vacation. Thanks a lot for finding this solution and writing a test as well. I would like to better understand the exact problem that is being solved here. Is passing the languages to MessageFormat at instantiation time only necessary when using "detailed" language codes ("en-US" vs "en", "de-CH", vs "de")? I know for sure that this is not a general problem that happens always, so I'd like to understand WHEN (and ideally WHY) it occurs. This will help explain to users of the library when and if they need to use the configuration option you've added. Do you know more about this?

eemeli commented 6 years ago

Essentially, instantiating MessageFormat without any locales means that it loads all locales for potential later use, and ends up hard-coding them to their base language name. In the constructor, strings passed in as locale names are assumed to be valid BCP47 tags and hence decomposable into their base names that can be matched to locales. In compile(src, lc), no such assumption is made. This means that e.g. fi_FI would not match fi, and the locale would go to the fallback, which is English by default.

So yeah, we should probably fix this upstream as well, but this fix would also have other benefits for you.

lephyrus commented 6 years ago

Well, if that isn't as clear and authoritative an answer as I could have hoped for... Thanks for chiming in, and thanks for developing messageformat, @eemeli. Adding an option for specifying the required languages definitely makes sense then. Any chance you already have an "official" explanation of the default behaviour I could link to in the README?

lephyrus commented 6 years ago

Never mind, it's easy to find, sorry (https://messageformat.github.io/messageformat/MessageFormat). I guess the ensuing problem when using composed locales is what's not intuitive. I'll add a note about it to the README, since people seem to encounter this more often than I would have thought.

sinedied commented 6 years ago

Can this be merged then?

santialbo-actimo commented 6 years ago

Hi @lephyrus could you please merge this and release a new version? Thanks a lot.