module Tr8nClientSdk::ActionCommonMethods

Public Instance Methods

tr(label, description = '', tokens = {}, options = {}) click to toggle source

There are three ways to call the tr method

tr(label, desc = '', tokens = {}, options = {}) or tr(label, tokens = {}, options = {}) or tr(:label => label, :description => '', :tokens => {}, :options => {})

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 43
def tr(label, description = '', tokens = {}, options = {})
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
  return params[:label].html_safe if params[:label].tr8n_translated?

  params[:options][:caller] = caller

  if request
    params[:options][:url]  = request.url
    params[:options][:host] = request.env['HTTP_HOST']
  end

  if Tr8n.config.disabled?
    return Tr8n.config.default_language.translate(params[:label], params[:tokens], params[:options]).tr8n_translated.html_safe
  end

  # Translate individual sentences
  if params[:options][:split]
    text = params[:label]
    sentences = Tr8n::Utils.split_by_sentence(text)
    sentences.each do |sentence|
      text = text.gsub(sentence, tr8n_current_language.translate(sentence, params[:description], params[:tokens], params[:options]))
    end
    return text.tr8n_translated.html_safe
  end

  Tr8n.session.target_language.translate(params).tr8n_translated.html_safe
rescue Tr8n::Exception => ex
  #pp ex, ex.backtrace
  Tr8n.logger.error(ex.message)
  #Tr8n.logger.error(ex.message + "\n=> " + ex.backtrace.join("\n=> "))
  label
end
tr8n_application() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 106
def tr8n_application
  tr8n_session.application
end
tr8n_current_language() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 122
def tr8n_current_language
  tr8n_session.current_language
end
tr8n_current_locale() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 118
def tr8n_current_locale
  tr8n_session.current_language.locale
end
tr8n_current_translator() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 114
def tr8n_current_translator
  tr8n_session.current_translator
end
tr8n_current_user() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 110
def tr8n_current_user
  tr8n_session.current_user
end
tr8n_language_dir() click to toggle source
# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 126
def tr8n_language_dir
  tr8n_current_language.dir
end
tr8n_session() click to toggle source

Common methods - wrappers

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 102
def tr8n_session
  Tr8n.session
end
trfe(label, desc = '', tokens = {}, options = {}) click to toggle source

flash error

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 89
def trfe(label, desc = '', tokens = {}, options = {})
  flash[:trfe] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
end
trfn(label, desc = '', tokens = {}, options = {}) click to toggle source

flash notice

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 84
def trfn(label, desc = '', tokens = {}, options = {})
  flash[:trfn] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
end
trfw(label, desc = '', tokens = {}, options = {}) click to toggle source

flash warning

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 94
def trfw(label, desc = '', tokens = {}, options = {})
  flash[:trfw] = tr(Tr8n::Utils.normalize_tr_params(label, desc, tokens, options))
end
trl(label, description = '', tokens = {}, options = {}) click to toggle source

for translating labels

# File lib/tr8n_client_sdk/extensions/action_common_methods.rb, line 77
def trl(label, description = '', tokens = {}, options = {})
  params = Tr8n::Utils.normalize_tr_params(label, description, tokens, options)
  params[:options][:skip_decorations] = true
  tr(params)
end