mashpie / i18n-node

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
3.09k stars 421 forks source link

Use translation from default locale if provided locale is `undefined` or `null` #502

Open longdoan7421 opened 2 years ago

longdoan7421 commented 2 years ago

Close #501.

coveralls commented 2 years ago

Coverage Status

coverage: 98.175%. remained the same when pulling c1b5d7a1498d36cf57bf04faaa28df60faab0fc6 on longdoan7421:master into 41b88011bcf7def492d8107473d3c8e6ef4ddada on mashpie:master.

mashpie commented 2 years ago

thanks @longdoan7421 for submitting this PR. Did you plan to also complete any other methods?

longdoan7421 commented 2 years ago

Hi @mashpie, I'm gonna continue working on the plural method __n later today. My plan was that I will change the method getLocaleFromObject to return the defaultLocale instead of undefined as default value. Then, use that method to get locale config from the input in method __n. Do you think whether it would affect anything?

For the other methods, I don't see they have option to pass locale like i18n.__ and i18n.__n (not sure if I am right, maybe you can correct me for this part).

longdoan7421 commented 2 years ago

Hi @mashpie, sorry for the delay. I added the fix for API i18n.__n. Please take a look if there is something need to be improved.

mashpie commented 1 year ago

Thanks @longdoan7421 - and sry for delay. LGTM!

Hope to review closer and of week.

EinfachHans commented 1 year ago

Any updates on this?

EinfachHans commented 1 year ago

@longdoan7421 can you fix __mf as well?

longdoan7421 commented 1 year ago

@EinfachHans I was not aware of __mf function. Could you point me the documentation for that function? I will look at it and see what I can do.

EinfachHans commented 1 year ago

I use it because it integrates with messageformat: https://github.com/mashpie/i18n-node#i18n__mf At the end of the day this patch should be applied to all functions i guess 🤔

longdoan7421 commented 1 year ago

Hi @mashpie, I added a similar fix for method i18n.__mf. When you have time could you check this PR? Thank you.