Suggested approach for i18n

Hi all,

based on your experience, how would you approach internationalization (i18n) for a full-stack project that needs to display the same contents translated in many different languages?

The project has a Play backend but mostly focused on API without localized content.
The bulk of the localization happens in the scala -> scala.js frontends.

I am familiar with and I quite like gettext, it has a good ecosystem, with tools and editors that can be used by non-coders as well. But I don’t seem to find rock-solid examples or libraries for plugging it effortlessly in Scala; found this https://github.com/xitrum-framework/scaposer and this https://github.com/makkarpov/scalingua but I wanted to have a check before taking a decision. Maybe there are overall better alternatives.

Any suggestion?

Thank you in advance,

Mario

You would probably want Play’s i18n support https://www.playframework.com/documentation/2.7.x/ScalaI18N, especially Messages and Lang.

As a rule of thumb, JavaScript libraries can usually be used pretty easily from Scala.js. You might have to create a “facade” – a strongly-typed description of the parts of the API that you are using – if one doesn’t already exist, but that’s not terribly hard (especially if you already know the library well), and then you can just use the stuff you already like

But in my case the Play solution would need to be extended also to the frontend code.

I have seen libraries that target the issue, like https://github.com/osinka/scala-i18n so I guess it is not straightforward. Or am I wrong?

And what is not clear to me: does the Play solution sits on top of the native Java internationalization mechanism, namely ResourceBundles?

Ok, just for context, gettext is not Javascript, I think it was originally developed in C and it comes with a Java implementation, see https://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Java.html#Java. Which is fine, I could use that.

But in my case the Play solution would need to be extended also to the frontend code.

In my company, we’ve used https://github.com/julienrf/play-jsmessages quite a lot for that, and it seems to work fine. It basically generates some Javascript code that exposes the same translation data available on the server. I don’t know if there is a Scala.js facade, but it should be trivial to write your own if needed.