Class: String

### Home Classes Methods

### In Files

- lib/fast_gettext/vendor/string.rb

### Parent

Object

### Methods

- #%
- #_fast_gettext_old_format_m

### Class/Module Index

Quicksearch

- FastGettext
- 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.

# String

either we are on vanilla 1.8(call with hash raises ArgumentError) or someone else already patched % but did it wrong

### Constants

PERCENT_MATCH_RE

### Public Instance Methods

%(hash) click to toggle source

    Default: "%s, %s" % ["Masao", "Mutoh"]
    Extended:
       "%{firstname}, %{lastname}" % {:firstname=>"Masao",:lastname=>"Mutoh"} == "Masao Mutoh"
       with field type such as d(decimal), f(float), ...
       "%<age>d, %<weight>.1f" % {:age => 10, :weight => 43.4} == "10 43.4"

This is the recommanded way for Ruby-GetText because the translators can understand the meanings of the keys easily.

    # File lib/fast_gettext/vendor/string.rb, line 36
    def %(args)
      if args.kind_of? Hash
        #stringify keys
        replace = {}
        args.each{|k,v|replace[k.to_s]=v}

        #replace occurances
        ret = dup
        ret.gsub!(PERCENT_MATCH_RE) do |match|
          if match == '%%'
            '%'
          elsif $1
            replace.has_key?($1) ? replace[$1] : match
          elsif $2
            replace.has_key?($2) ? sprintf("%#{$3}", replace[$2]) : match
          end
        end
        ret
      else
        ret = gsub(/%([{<])/, '%%\1')
        ret._fast_gettext_old_format_m(args)
      end
    end

Also aliased as: _fast_gettext_old_format_m, _fast_gettext_old_format_m
_fast_gettext_old_format_m(args) click to toggle source
Alias for: %

[Validate]

Generated with the Darkfish Rdoc Generator 2.