Sha256: da348e4b3ee01898166e00988469a8e571aef9dc8dc8e6bbdbd0769e844321c3

Contents?: true

Size: 1.44 KB

Versions: 23

Compression:

Stored size: 1.44 KB

Contents

class Hayabusa
  #Translates a given key for a given object.
  #===Examples
  # print _hb.trans(obj, :title) #=> "Trala"
  def trans(obj, key, args = {})
    args[:locale] = self.trans_locale if !args[:locale]
    trans_val = self.translations.get(obj, key, args).to_s
    trans_val = @events.call(:trans_no_str, {:obj => obj, :key => key, :args => args}) if trans_val.length <= 0
    return trans_val
  end
  
  #Returns the locale for the current thread.
  def trans_locale(args = {})
    if args.is_a?(Hash) and args[:locale]
      return args[:locale]
    elsif _session and _session[:locale]
      return _session[:locale]
    elsif _httpsession and _httpsession.data[:locale]
      return _httpsession.data[:locale]
    elsif Thread.current[:locale]
      return Thread.current[:locale]
    elsif @config[:locale_default]
      return @config[:locale_default]
    end
    
    raise "Could not figure out locale."
  end
  
  #Sets new translations for the given object.
  #===Examples
  # _hb.trans_set(obj, {:title => "Trala"})
  def trans_set(obj, values, args = {})
    raise "Translations-object now spawned." if !self.translations
    args[:locale] = self.trans_locale if !args[:locale]
    self.translations.set(obj, values, args)
  end
  
  #Deletes all translations for the given object.
  #===Examples
  # _hb.trans_del(obj)
  def trans_del(obj)
    raise "Translations-object now spawned." if !self.translations
    self.translations.delete(obj)
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
hayabusa-0.0.30 lib/hayabusa_ext/translations.rb
hayabusa-0.0.29 lib/hayabusa_ext/translations.rb
hayabusa-0.0.28 lib/hayabusa_ext/translations.rb
hayabusa-0.0.25 lib/hayabusa_ext/translations.rb
hayabusa-0.0.24 lib/hayabusa_ext/translations.rb
hayabusa-0.0.23 lib/hayabusa_ext/translations.rb
hayabusa-0.0.22 lib/hayabusa_ext/translations.rb
hayabusa-0.0.20 lib/hayabusa_ext/translations.rb
hayabusa-0.0.19 lib/hayabusa_ext/translations.rb
hayabusa-0.0.18 lib/hayabusa_ext/translations.rb
hayabusa-0.0.17 lib/hayabusa_ext/translations.rb
hayabusa-0.0.16 lib/hayabusa_ext/translations.rb
hayabusa-0.0.15 lib/hayabusa_ext/translations.rb
hayabusa-0.0.14 lib/hayabusa_ext/translations.rb
hayabusa-0.0.13 lib/hayabusa_ext/translations.rb
hayabusa-0.0.12 lib/hayabusa_ext/translations.rb
hayabusa-0.0.11 lib/hayabusa_ext/translations.rb
hayabusa-0.0.10 lib/hayabusa_ext/translations.rb
hayabusa-0.0.9 lib/hayabusa_ext/translations.rb
hayabusa-0.0.8 lib/hayabusa_ext/translations.rb