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_init_client_sdk ⇒ Object
- #tr8n_init_current_locale ⇒ 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_user_preferred_locale ⇒ Object
Instance Method Details
#tr8n_browser_accepted_locales ⇒ Object
44 45 46 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 44 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
64 65 66 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 64 def tr8n_component nil end |
#tr8n_init_client_sdk ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 84 def tr8n_init_client_sdk return if Tr8n.config.disabled? @tr8n_started_at = Time.now Tr8n.session.init translator = nil = "tr8n_#{tr8n_application.key}" if request.[] = Tr8n::Utils.decode_and_verify_params(request.[], tr8n_application.secret) Tr8n.logger.info(.inspect) locale = ["locale"] translator = Tr8n::Translator.new(["translator"].merge(:application => tr8n_application)) unless ["translator"].nil? end locale ||= tr8n_init_current_locale || Tr8n.config.default_locale Tr8n.session.current_user = tr8n_init_current_user Tr8n.session.current_translator = translator Tr8n.session.current_language = tr8n_application.language(locale || tr8n_init_current_locale || Tr8n.config.default_locale) Tr8n.session.current_source = tr8n_source Tr8n.session.current_component = tr8n_component end |
#tr8n_init_current_locale ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 68 def tr8n_init_current_locale self.send(Tr8n.config.current_locale_method) if Tr8n.config.current_locale_method rescue # 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] end |
#tr8n_init_current_user ⇒ Object
78 79 80 81 82 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 78 def tr8n_init_current_user self.send(Tr8n.config.current_user_method) if Tr8n.config.current_user_method rescue Tr8n.config.default_locale end |
#tr8n_reset_client_sdk ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 110 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
57 58 59 60 61 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 57 def tr8n_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tr8n_user_preferred_locale ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/tr8n_client_sdk/extensions/action_controller_extension.rb', line 48 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 |