Grails: Organizing i18n Packages

I see that under grails-app/i18n there is a ton of messages*.properties packages. I would like to internationalize my application, but I have a β€œset of packages” per page. By the set of packages, I mean the set of bundle / property files that contain the same text, but for different languages. For example, if I want my site to support English, French and Spanish, then my About page can have a set of packages of 3 packages:

  • about.properties (in English)
  • about_fr.properties (French)
  • about_es.properties (Spanish)

If my application consists of 100 pages, and I have 3 properties files per page, then 300 properties files, which I end up getting under grails-app/i18n ! It could be a worm!

I am wondering if I can add subfolders under grails-app/i18n and organize it in a decentralized way:

 myapp/ grails-app/ i18n/ about/ about.properties about_fr.properties about_es.properties contact/ contact.properties contact_fr.properties contact_es.properties fizzbuzz/ fizzbuzz.properties fizzbuzz_fr.properties fizzbuzz_es.properties ... etc. 

This will provide much more convenient / cleaner / more organized code. If possible:

  • Am I just creating folders / packages in grails-app/ i18n, or is there a Grails CLI command that I can use (e.g. grails create-i18n-bundle about )?
  • How can I then refer to my nested packages from within the GSP? For example, in my about.gsp , I would just use: <g:message code="about/foo.bar" /> ?
+5
source share
1 answer

Grails takes all the packages under the grails-app / i18n folder. This way you can create a folder for each of your groups.

Referencing them is as simple as if it were in messages.properties. I mean, if you have:

Grails app / i18n / messages.properties

 foo.bar = foo bar 

Grails app / i18n / rev / about.properties

 bar.foo = bar foo 

You can do in your gsp:

 <g:message code="foo.bar"/> <g:message code="bar.foo"/> 

Here you have a brief documentation: https://grails.org/wiki/Internationalization

+1
source

All Articles