找到你要的答案

Q:Grails: Organizing i18n bundles

Q:目的:组织国际化的束

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" />?

我看到grails-app/i18n下有一吨的邮件*。属性包。我想国际化我的应用程序,但有1个“捆绑”的每一页。我的意思是,一组集合/属性文件包含相同的文本,但不同的语言。例如,如果我希望我的网站支持英语,法语和西班牙语,那么我的“左右”页面可能有一套3束:

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

如果我的应用程序有100页,我有3个属性文件页面的300个属性文件我最终会有grails-app/i18n下!那是一只虫子!

我不知道我是否可以加入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.

这将使更好的/更清洁的/更有组织的代码。如果这是可能的:

  • 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" />?
answer1: 回答1:

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

Grails将所有束,grails-app/i18n文件夹下。因此,您可以为每个组创建文件夹。

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.properties

bar.foo = bar foo

你可以在你的画板:

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

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

grails  internationalization