Giter VIP home page Giter VIP logo

griffon-i18n-gettext's Introduction

Enables localization of messages using GNU Gettext. This plugin is a port of the grails i18n-gettext plugin Installation

To install just issue the following command

griffon install-plugin i18n-gettext

Usage

This plugin adds some methods to view instances:

tr(Map params, String text, Object... objects)
trc(String comment, String text)
trn(String singularText, String pluralText, Number n, Object... objects)
trnc(String comment, String singularText, String pluralText, Number n, Object... objects)

You just wrap your texts in one of the tr-methods. They work only with double quotes, not with single quotes, and the named parameters must be the last parameters.

tr("Content goes here")
tr("Hello {0}", name) // uses MessageFormat
tr("Hello \$name", name: 'Paul') // uses SimpleTemplateEngine -- make sure to escape $
tr("Hello \${name}", name: 'Paul') // uses SimpleTemplateEngine -- make sure to escape $
trc("Short for Order", "O", rb: 'MyResourceBundle', locale: Locale.German) // rb and locale might be given, but must be the last parameters

// but
tr(name: 'Paul', "Hello \$name") // will not work, because the named parameters must be the last parameters
tr('Hello') // will not work, because you must use "
tr("Hello $name", name: 'Paul') // will not work, because GStrings don't work
tr("Hello \${name} {0}", 'Maier', name: 'Paul') // will not work, because you are not allowed to mix named and indexed parameters (MessageFormat will complain because of ${name})

Then execute

griffon i18n-gettext

to generate the keys.pot and merge into existing po files, followed by

griffon i18n-gettext init de

to create a German language file. Edit the griffon-app/i18n/de.po file. Then execute

griffon i18n-gettext makemo

to generate a i18ngettext.jar in your lib folder.

When you added new texts to your source files or have changed something, just call griffon i18n-gettext again to regenerate the keys.pot file and merge into your existing po files. After translation, execute grifofn i18n-gettext makemo again.

Configuration

Dynamic method injection

The tr-methods are available on all view scripts by default. You can enable them on other mvc members by adding for example

root.'I18nGettextGriffonAddon'.controller='*:methods'

to your Builder.groovy

Other configuration

You can configure the behaviour of the plugin by defining some attributes in your BuildConfig.groovy

The default charset is assumed to be UTF-8. You can configure the charset of your source files by setting

i18n.inputFileCharset = 'UTF-8'

By default all java and groovy files are parsed by the plugin. If you specify a list of directory names

i18n.excludedDirs =['dir_to_exclude']

By default the bundle name is 'Messages'. This can be changed with

i18n.bundleName = 'Foo'

The default xgettext params are --add-comments and can be altered by

i18n.xgettextParams = '--add-comments'

Parameters for msginit can be set with

i18n.msginitParams = ''

Patameters for msgmerge can be set with

i18n.msgmergeParams = ''

griffon-i18n-gettext's People

Contributors

tschulte avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.