Onward and upward

Compilation safety on Playframework's i18n with Scala Macros

Or how Scala Times describes it: “Leverage macros to make compilation fail for invalid key or invalid arguments.”

Playframework’s i18n mechanism isn’t very safe. Well, it’s not as safe as I’d like as a person who prefers Scala because of its safeness. A translation is defined in messages, for example, page.index.hello = Hello {0}. Then, somewhere in a template, we invoke @request.messages("page.index.helllo", "Tanin").

With the above way of doing things, we can easily make a few mistakes. We could misspell the key. We could forget to invoke the method with an appropriate number of arguments. To make the matter worse, Playframework will compile it successfully. You will only see the mistake(s) when you render the page. Your message will look like page.index.helllo (did you notice the three ls?) because the misspelled key isn’t defined. Avoiding mistakes when there are thousands of translations in a project is painful.

I made this exact mistake, and I’ve realised afterwards that there is a way to catch this kind of mistakes with Scala Macros!

Read more

i18n with Playframework and Vue

Playframework has its own internationalization mechanism, which use conf/messages for storing translations. The mechanism is great for server-side rendering. On Vue’s side, there are multiple libraries for internationalization in Vue.js, and it seems vue-i18n is the winner.

Now the question is: How do we use it with Vue.js?

It would be great if (1) vue-i18n uses the Playframework’s conf/messages and (2) the internationalization works well with local development (e.g. hot-reloading).

Read more

Vue.js with Playframework

We’ve finally extracted out our Vue.js plugin for Playframework, sbt-vuefy, and shared it with the world.

It has been quite an effort to make Vue.js work seamlessly well with Playframework. This is especially true when we want to avoid using Single-page application (SPA).

Read more