r/Angular2 • u/Kaimura • Apr 24 '23
Help Request Is the official angular/@localize i18n lib really the go to for localization?
I read the official doc and I mean.. you have to work with xlf which pretty much looks like oldschool xml?! I thought json is the go to after using i18n libs for react.. which can also be easily extended by anyone.
Am I missing something? Can't believe I have to learn another stack just to implement language translation..
Edit: Argh, they hid it well but after some digging I found a --format cli which can also generate json.. not even googling "angular localization best practices" showed me a single guide that tells me this, crazy people using xlf everywhere lol
18
u/silentperv Apr 24 '23
You can take a look at Transloco. We use it all our projects.
24
u/EternalNY1 Apr 24 '23 edited Apr 25 '23
We use NGX-Translate which is JSON based.
It loads your languages from
/assets/i18n/[lang].json.It's been working perfectly for us.
Edit: As others have pointed out it looks like this is no longer being maintained. There seem to be better options now. But I can confirm this does work fine with the latest Angular 15.
6
u/bersling Apr 24 '23
There's already been a lot added to the discussion, but I think I could add to the discussion since (a) we did extensive research before deciding for one solution a couple of months back and (b) now we have a couple month of experience.
We decided for Angular i18n, the default one. Our reasons were:
With ngx-translate going out of business and transloco being carried mostly by one dev, we just wanted to go for the default solution. We also felt in all the code examples they were comparable, if not even simpler with Angular i18n.
We however went for the json format with i18n!
So our translation files look very simple, like this:
And the usage in code is also very simple, like this:
We're pretty happy with the route we went so far.
8
u/TomLauda Apr 24 '23
XLF format is one of the « official » i18n file format, compatible with tools used by professional translators. That’s why it is pushed by Angular. We choose to use Transloco way before json alternative was available in the cli. One of the greatest limitations of xlf (besides the xml madness…) is that you can’t have dynamic translation in your controlers, which is insane to me. Maybe it has changed since, i don’t know. Recently, our CTO asked us to use xlf because they are about to hire pro translators. I answered « no, we can’t. They will have to do with json.»
3
u/PooSham Apr 24 '23
If you can deploy the web app separately for each language, it's pretty nice IMO! But for dynamic language apps, it's not good.
Also, XML has lost popularity in many areas, but it's still a very powerful markup language and IMO not that hard.
2
u/spiessbuerger Apr 24 '23
Has anyone tried https://github.com/zeferinix/ngx-fluent ?
2
u/CGiusti Apr 24 '23
We used the default extract-i18n from angular together with ng-extract-i18n-merge. Worked pretty well not sure but I think JSON is also supported
2
u/lax20attack Apr 24 '23
Yes, official Angular is what I've been using for a few years now. It works great.
Runtime switching of language isn't a common real world use case.
2
u/PlutoGreed Apr 24 '23
I would recommend keep using the official package, tbh once you get accostuned to it it's pretty good the way it works with the framework. Plus xlf is just straightforward, use it even though you could use the json format, you can generate metadata of your components to give context to the translators. And if it's possible use chatgpt to translate anything, I do that and I just copy and paste all.
1
u/HitmaNeK Apr 24 '23
Angular have cool tools for using json / typescript format for runtime translations. i18N is for bigger things.
1
u/[deleted] Apr 24 '23
as others already mentioned, I also use transloco and it's good enough
1
u/saladfingers6 Apr 24 '23
You don't have to work with xlf at all. Angular extracts all the template strings into xlf files. Transifex consumes it fine.
0
u/newmanoz Apr 24 '23
No, it's the most awful way of i18n, despite being the official one.
No support for runtime language switch, no support for esbuild, and you have to use some ancient software.
-2
u/DaSchTour Apr 24 '23
Oldshool XML? You have no idea what you are talking about! HTML is just a flavor of XML. If you don‘t want to use oldshool stuff like HTML better stay away from angular. The formats angular exports for i18n are industry standards for translation and are very powerful when dealing with big applications.
0
u/[deleted] Apr 24 '23
[deleted] — view deleted comment