Sha256: b7f5f94dc173a1bfa02327b4edf090728754ed520c0b144162a588fe4811d8e4
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
Extended Globalize2 which is acting like gettext translations. == Installation sudo gem install kriss-gettext_like_i18n --source=http://gems.github.com/ == Usage in controllers... class FooController < ApplicationController def bar render :text => _('Wonderfull i18n notice!') end end in models... class Bar < ActiveRecord::Base def foo(condition) if condition return "Some translated string".t else return :"some.key.for.translation".t end end end in views... <div id="foo"> <%=_ 'Translated message' %> or <%= 'Other translated message'.t %><br /> <%=_ 'Great translated string with {{parameter}}, :parameter => 'gettext like i18n' %><br /> <%= link_to _('Get it now!'), 'http://github.com/kriss/gettext_like_i18n/' %> </div> == Translations Each string will be displayed as default if is not translated in locale files. Eg. locale file locales/pl.yml can look like this: pl: "Translated message": "Tlumaczona wiadomosc" "Some translated string": "Jakis tlumaczony tekst" key_to_translate: "Translated!" nested: key: "Hello!" == Rails i18n & Globalize2 compatibility gettext_like_i18n is full compatible with Ruby on Rails i18n and Globalize2 plugin. Only you should remember that to load translation by key using gettext method you have to specify key as symbol, eg: <%=_ "nested.key" %> is not the same as: <%=_ :"nested.key" %> First will produce "nested key" string, and second translation for specified key. For key based translation it's better to use #t or #translate method. == Extending your classes and modules You can also extend your own classes and modules in easy way. Only thing you have to do is include I18n::Gettext or I18n::Gettext::Singleton with your library, eg. class Foo include I18n::Gettext include I18n::Gettext::Singleton end module Foo extend I18n::Gettext end Enjoy!
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kriss-gettext_i18n-0.2.0 | README.rdoc |