Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: Organizing i18n bundles

I see under grails-app/i18n there are a ton of messages*.properties bundles. I would like to internationalize my app, but have 1 "bundle set" per page. By bundle set I mean, a set bundles/properties files that contain the same text but for different languages. For instance, if I want my site to support English, French and Spanish, then my "About" page might have a bundle set of 3 bundles:

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

If my app consists of 100 pages, and I have 3 properties files per page, that's 300 properties files I'll eventually have under grails-app/i18n! Thats a can o' worms!

I'm wondering if I can added subfolders under grails-app/i18n and organize it in a decentralized fashion:

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 would make for much nicer/cleaner/more organized code. If this is possible:

  • Do I just create folders/packages under grails-app/i18n, or is there a Grails CLI command I can use (e.g., grails create-i18n-bundle about)?
  • How do I then refer to my nested bundles from inside a GSP? For instance, in my about.gsp, would I just use: <g:message code="about/foo.bar" />?
like image 476
smeeb Avatar asked Nov 10 '22 14:11

smeeb


1 Answers

Grails takes all bundles that are under the grails-app/i18n folder. So you can create a folder for each of your groups.

To refer to them is just as simple as if it was in the messages.properties. I mean, if you have:

grails-app/i18n/messages.properties

foo.bar = foo bar

grails-app/i18n/about/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

like image 179
David Chavez Avatar answered Dec 08 '22 21:12

David Chavez