Sha256: 7f7368d271c132894b88539dc913d6d6af7d2d0e366172b8a578c1ce032715c8

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module FastGettext
  module Translation
    extend self

    #make it usable in class definition, e.g.
    # class Y
    #   include FastGettext::Translation
    #   @@x = _('y')
    # end
    def self.included(klas)  #:nodoc:
      klas.extend self
    end

    def _(translate)
      FastGettext.current_translations[translate] || translate
    end

    #translate pluralized
    def n_(singular,plural,count)
      if translation = FastGettext.current_translations.plural(singular,plural,count)
        translation
      else
        count == 1 ? singular : plural
      end
    end

    #translate, but discard namespace if nothing was found
    # Car|Tire -> Tire if no translation could be found
    def s_(translate,seperator=nil)
      if translation = FastGettext.current_translations[translate]
        translation
      else
        translate.split(seperator||NAMESPACE_SEPERATOR).last
      end
    end

    #tell gettext: this string need translation (will be found during parsing)
    def N_(translate)
      translate
    end

    #tell gettext: this string need translation (will be found during parsing)
    def Nn_(singular,plural)
      [singular,plural]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grosser-fast_gettext-0.2.10 lib/fast_gettext/translation.rb
grosser-fast_gettext-0.2.8 lib/fast_gettext/translation.rb