Sha256: 9b756dc74223f0e164ed78d074fab995a4db15b8640b822788a0aedd0e78e6b6

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

Extended Globalize2 which is acting like gettext translations.

== Installation

  sudo gem install kriss-gettext_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

3 entries across 3 versions & 1 rubygems

Version Path
kriss-gettext_i18n-0.2.1 README.rdoc
kriss-gettext_i18n-0.2.2 README.rdoc
kriss-gettext_i18n-0.2.3 README.rdoc