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_locale ⇒ 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 ⇒ Object
- #tr8n_user_preferred_locale ⇒ Object
Instance Method Details
#tr8n_browser_accepted_locales ⇒ Object
52 53 54 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 52 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
72 73 74 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 72 def tr8n_component nil end |
#tr8n_cookie ⇒ Object
80 81 82 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 80 def request.[] end |
#tr8n_cookie_name ⇒ Object
76 77 78 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 76 def "tr8n_#{tr8n_application.key}" end |
#tr8n_cookie_params ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 84 def ||= begin if = Tr8n::Utils.decode_and_verify_params(, tr8n_application.secret) Tr8n.logger.info(.inspect) else {} end end end |
#tr8n_init_client_sdk ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 120 def tr8n_init_client_sdk return if Tr8n.config.disabled? @tr8n_started_at = Time.now Tr8n.session.init( :cookies => request., :locale => tr8n_locale, :user => tr8n_user, :source => tr8n_source, :component => tr8n_component ) I18n.enforce_available_locales = false I18n.locale = Tr8n.session.current_language.locale end |
#tr8n_locale ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 101 def tr8n_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_reset_client_sdk ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 137 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
65 66 67 68 69 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 65 def tr8n_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tr8n_translator_locale ⇒ Object
96 97 98 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 96 def tr8n_translator_locale ["locale"] end |
#tr8n_user ⇒ Object
114 115 116 117 118 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 114 def tr8n_user self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method rescue nil end |
#tr8n_user_preferred_locale ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 56 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 |