Module: TmlRails::ActionCommonMethods
- Defined in:
- lib/tml_rails/extensions/action_common_methods.rb
Instance Method Summary collapse
- #tml_application ⇒ Object
- #tml_current_language ⇒ Object
- #tml_current_locale ⇒ Object
- #tml_current_source ⇒ Object
- #tml_current_translator ⇒ Object
- #tml_current_user ⇒ Object
- #tml_language_dir ⇒ Object
-
#tml_session ⇒ Object
Common methods - wrappers.
- #tml_subdomain_locale_url(locale = tml_current_locale) ⇒ Object
-
#tr(label, description = '', tokens = {}, options = {}) ⇒ Object
There are three ways to call the tr method.
-
#trfe(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash error.
-
#trfn(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash notice.
-
#trfw(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash warning.
-
#trl(label, description = '', tokens = {}, options = {}) ⇒ Object
for translating labels.
Instance Method Details
#tml_application ⇒ Object
106 107 108 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 106 def tml_application tml_session.application end |
#tml_current_language ⇒ Object
122 123 124 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 122 def tml_current_language tml_session.current_language end |
#tml_current_locale ⇒ Object
118 119 120 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 118 def tml_current_locale tml_session.current_language.locale end |
#tml_current_source ⇒ Object
126 127 128 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 126 def tml_current_source tml_session.current_source end |
#tml_current_translator ⇒ Object
114 115 116 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 114 def tml_current_translator tml_session.current_translator end |
#tml_current_user ⇒ Object
110 111 112 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 110 def tml_current_user tml_session.current_user end |
#tml_language_dir ⇒ Object
130 131 132 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 130 def tml_language_dir tml_current_language.dir end |
#tml_session ⇒ Object
Common methods - wrappers
102 103 104 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 102 def tml_session Tml.session end |
#tml_subdomain_locale_url(locale = tml_current_locale) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 134 def tml_subdomain_locale_url(locale = tml_current_locale) uri = URI::parse(request.url) host = uri.host.split('.') if host.count == 2 host.unshift(locale) else host[0] = locale end uri.host = host.join('.') uri.to_s end |
#tr(label, description = '', tokens = {}, options = {}) ⇒ Object
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 => {})
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 43 def tr(label, description = '', tokens = {}, = {}) params = Tml::Utils.normalize_tr_params(label, description, tokens, ) return params[:label].html_safe if params[:label].tml_translated? params[:options][:caller] = caller if request params[:options][:url] = request.url params[:options][:host] = request.env['HTTP_HOST'] end if Tml.config.disabled? return Tml.config.default_language.translate(params[:label], params[:tokens], params[:options]).tml_translated.html_safe end # Translate individual sentences if params[:options][:split] text = params[:label] sentences = Tml::Utils.split_by_sentence(text) sentences.each do |sentence| text = text.gsub(sentence, tml_current_language.translate(sentence, params[:description], params[:tokens], params[:options])) end return text.tml_translated.html_safe end Tml.session.target_language.translate(params).tml_translated.html_safe rescue Tml::Exception => ex #pp ex, ex.backtrace Tml.logger.error(ex.) #Tml.logger.error(ex.message + "\n=> " + ex.backtrace.join("\n=> ")) label end |
#trfe(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash error
89 90 91 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 89 def trfe(label, desc = '', tokens = {}, = {}) flash[:trfe] = tr(Tml::Utils.normalize_tr_params(label, desc, tokens, )) end |
#trfn(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash notice
84 85 86 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 84 def trfn(label, desc = '', tokens = {}, = {}) flash[:trfn] = tr(Tml::Utils.normalize_tr_params(label, desc, tokens, )) end |
#trfw(label, desc = '', tokens = {}, options = {}) ⇒ Object
flash warning
94 95 96 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 94 def trfw(label, desc = '', tokens = {}, = {}) flash[:trfw] = tr(Tml::Utils.normalize_tr_params(label, desc, tokens, )) end |
#trl(label, description = '', tokens = {}, options = {}) ⇒ Object
for translating labels
77 78 79 80 81 |
# File 'lib/tml_rails/extensions/action_common_methods.rb', line 77 def trl(label, description = '', tokens = {}, = {}) params = Tml::Utils.normalize_tr_params(label, description, tokens, ) params[:options][:skip_decorations] = true tr(params) end |