Even if only the English version changed, every file would require modification,
as the strings are keyed on the exact source text.
Gibberish,* by Chris Wanstrath, is a very lightweight Rails localization plugin. Like
gettext, it is based on replacing individual strings from a language-dependent
resource file. However, it is much simpler (and, correspondingly, somewhat less flexible)
than gettext. It is also tailored toward Ruby??™s style and Rails??™ needs.
First, install the Rails plugin from Subversion. Its init.rb file will load Gibberish and
any translation files under the lang directory:
$ script/plugin install svn://errtheblog.com/svn/plugins/gibberish
Unlike gettext, which scans your source files to generate translation files, Gibberish
requires you to create translation files yourself. However, they are very easy to create.
A sample Gibberish language file looks like this:
lang/es.yml
welcome: ??Hola, mundo!
The source syntax is very much like gettext, but with the addition of a symbol tag,
used as a key in place of the string itself. Gibberish overrides the String#[] method
to provide nice syntax for this:
puts "Hello, world!"[:welcome]
# >> Hello, world!
The default language is English, so if no language is selected, that statement will output
???Hello, world!???. We can change the default language:
Gibberish.use_language :es
puts "Hello, world!"[:welcome]
# >> ??Hola, mundo!
Interpolation variables are available, and values for them can be passed as positional
or keyword arguments.
Pages:
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396