Module: FastGettext::Translation

### Home Classes Methods

### In Files

- lib/fast_gettext/translation.rb

### Methods

- #N_
- #Nn_
- #_
- #n_
- #ns_
- #s_

### Class/Module Index

Quicksearch

- FastGettext
- FastGettext::Cache
- FastGettext::GetText
- FastGettext::GetText::MOFile
- FastGettext::GetText::MOFile::HeaderRev1
- FastGettext::GetText::MOFile::InvalidFormat
- FastGettext::GetText::PoParser
- FastGettext::MoFile
- FastGettext::PoFile
- FastGettext::Storage
- FastGettext::Storage::NoTextDomainConfigured
- FastGettext::Translation
- FastGettext::TranslationMultidomain
- FastGettext::TranslationRepository
- FastGettext::TranslationRepository::Base
- FastGettext::TranslationRepository::Chain
- FastGettext::TranslationRepository::Db
- FastGettext::TranslationRepository::Logger
- FastGettext::TranslationRepository::Mo
- FastGettext::TranslationRepository::Po
- FastGettext::TranslationRepository::Yaml
- String
- TranslationKey
- TranslationText

No matching classes.

# FastGettext::Translation

this module should be included Responsibility:

    - direct translation queries to the current repository
    - handle untranslated values
    - understand / enforce namespaces
    - decide which plural form is used

### Public Instance Methods

N_(translate) click to toggle source

tell gettext: this string need translation (will be found during parsing)

    # File lib/fast_gettext/translation.rb, line 53
    def N_(translate)
      translate
    end

Nn_(*keys) click to toggle source

tell gettext: this string need translation (will be found during parsing)

    # File lib/fast_gettext/translation.rb, line 58
    def Nn_(*keys)
      keys
    end

_(key, &block) click to toggle source

    # File lib/fast_gettext/translation.rb, line 20
    def _(key, &block)
      FastGettext.cached_find(key) or (block ? block.call : key)
    end

n_(*keys, &block) click to toggle source

translate pluralized

    some languages have up to 4 plural forms...
    n_(singular, plural, plural form 2, ..., count)
    n_('apple','apples',3)

    # File lib/fast_gettext/translation.rb, line 28
    def n_(*keys, &block)
      count = keys.pop
      translations = FastGettext.cached_plural_find(*keys)

      selected = FastGettext.pluralisation_rule.call(count)
      selected = (selected ? 1 : 0) unless selected.is_a? Numeric #convert booleans to numbers

      result = translations[selected]
      if result
        result
      elsif keys[selected]
        _(keys[selected])
      else
        block ? block.call : keys.last
      end
    end

ns_(*args, &block) click to toggle source

    # File lib/fast_gettext/translation.rb, line 62
    def ns_(*args, &block)
      translation = n_(*args, &block)
      # block is called once again to compare result
      block && translation == block.call ? translation : translation.split(NAMESPACE_SEPARATOR).last
    end

s_(key, separator=nil, &block) click to toggle source

translate, but discard namespace if nothing was found

    Car|Tire -> Tire if no translation could be found

    # File lib/fast_gettext/translation.rb, line 47
    def s_(key, separator=nil, &block)
      translation = FastGettext.cached_find(key) and return translation
      block ? block.call : key.split(separator||NAMESPACE_SEPARATOR).last
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.