Grails:组织 i18n 包

Grails: Organizing i18n bundles

我看到 grails-app/i18n 下有很多 messages*.properties 包。我想国际化我的应用程序,但每页有 1 "bundle set"。 bundle set 我的意思是,一组 bundles/properties 包含相同文本但用于不同语言的文件。例如,如果我希望我的站点支持英语、法语和西班牙语,那么我的 "About" 页面可能有一组 3 个捆绑包:

如果我的应用程序包含 100 个页面,并且每页有 3 个属性文件,那么我最终将在 grails-app/i18n 下拥有 300 个属性文件!那是一个蠕虫罐头!

我想知道我是否可以在 grails-app/i18n 下添加子文件夹并以分散的方式组织它:

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.

这会产生很多 nicer/cleaner/more 有组织的代码。如果可能的话:

Grails 获取 grails-app/i18n 文件夹下的所有包。因此,您可以为每个组创建一个文件夹。

引用它们就像在 messages.properties 中一样简单。 我的意思是,如果你有:

grails-app/i18n/messages.properties

foo.bar = foo bar

grails-app/i18n/about/about.properties

bar.foo = bar foo

你可以在 gsp 中做:

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

这里有一个简短的文档:https://grails.org/wiki/Internationalization