Sha256: 24cecb45fe05a1053b8c1a8e2e2037dc2c78546369e61be34aad08822779c14a

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module FastGettext
  # this module should be included
  # Responsibility:
  #  - direct translation queries to the current repository
  #  - handle untranslated values
  #  - understand / enforce namespaces
  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)
      found = FastGettext.current_cache[translate] and return found
      FastGettext.current_cache[translate] = FastGettext.current_repository[translate] || translate
    end

    #translate pluralized
    def n_(singular,plural,count)
      if translation = FastGettext.current_repository.plural(singular,plural,count)
        translation
      else
        #TODO remove this repeated logic, e.g. return :plural / :singular or raise an exception ?
        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_repository[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

1 entries across 1 versions & 1 rubygems

Version Path
grosser-fast_gettext-0.2.11 lib/fast_gettext/translation.rb