Module: Tr8nClientSdk::ActionControllerExtension::InstanceMethods
- Defined in:
- lib/tr8n_client_sdk/extensions/action_controller_extension.rb
Instance Method Summary collapse
- #tr8n_browser_accepted_locales ⇒ Object
-
#tr8n_component ⇒ Object
Overwrite this method in a controller to assign a custom component for all views.
- #tr8n_cookie ⇒ Object
- #tr8n_cookie_name ⇒ Object
- #tr8n_cookie_params ⇒ Object
- #tr8n_init_client_sdk ⇒ Object
- #tr8n_init_current_locale ⇒ Object
- #tr8n_init_current_translator ⇒ Object
- #tr8n_init_current_user ⇒ Object
- #tr8n_reset_client_sdk ⇒ Object
-
#tr8n_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views.
- #tr8n_translator_locale ⇒ Object
- #tr8n_user_preferred_locale ⇒ Object
Instance Method Details
#tr8n_browser_accepted_locales ⇒ Object
51 52 53 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 51 def tr8n_browser_accepted_locales @tr8n_browser_accepted_locales ||= Tr8n::Utils.browser_accepted_locales(request) end |
#tr8n_component ⇒ Object
Overwrite this method in a controller to assign a custom component for all views
71 72 73 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 71 def tr8n_component nil end |
#tr8n_cookie ⇒ Object
79 80 81 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 79 def request.[] end |
#tr8n_cookie_name ⇒ Object
75 76 77 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 75 def "tr8n_#{tr8n_application.key}" end |
#tr8n_cookie_params ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 83 def @tr8n_cookie_params ||= begin if = Tr8n::Utils.decode_and_verify_params(, tr8n_application.secret) Tr8n.logger.info(.inspect) else {} end end end |
#tr8n_init_client_sdk ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 126 def tr8n_init_client_sdk return if Tr8n.config.disabled? @tr8n_started_at = Time.now Tr8n.session.init Tr8n.session.current_user = tr8n_init_current_user Tr8n.session.current_language = tr8n_application.language(tr8n_init_current_locale) Tr8n.session.current_translator = tr8n_init_current_translator Tr8n.session.current_source = tr8n_source Tr8n.session.current_component = tr8n_component end |
#tr8n_init_current_locale ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 99 def tr8n_init_current_locale self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method rescue # fallback onto the cookie params from the service return tr8n_translator_locale if tr8n_translator_locale # fallback to the default session based locale implementation # choose the first language from the accepted languages header session[:locale] = tr8n_user_preferred_locale unless session[:locale] session[:locale] = params[:locale] if params[:locale] session[:locale] || Tr8n.config.default_locale end |
#tr8n_init_current_translator ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 118 def tr8n_init_current_translator if ["translator"] Tr8n::Translator.new(["translator"].merge(:application => tr8n_application)) else nil end end |
#tr8n_init_current_user ⇒ Object
112 113 114 115 116 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 112 def tr8n_init_current_user self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method rescue nil end |
#tr8n_reset_client_sdk ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 141 def tr8n_reset_client_sdk return if Tr8n.config.disabled? @tr8n_finished_at = Time.now tr8n_application.submit_missing_keys Tr8n.session.reset Tr8n.logger.info("Request took #{@tr8n_finished_at - @tr8n_started_at} mls") if @tr8n_started_at end |
#tr8n_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views
64 65 66 67 68 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 64 def tr8n_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tr8n_translator_locale ⇒ Object
95 96 97 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 95 def tr8n_translator_locale ["locale"] end |
#tr8n_user_preferred_locale ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 55 def tr8n_user_preferred_locale tr8n_browser_accepted_locales.each do |locale| next unless Tr8n.session.application.locales.include?(locale) return locale end Tr8n.config.default_locale end |