Module: Tr8nClientSdk::ActionViewExtension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/tr8n_client_sdk/extensions/action_view_extension.rb
Instance Method Summary collapse
- #tr8n_dir_attribute_tag(lang = tr8n_current_language) ⇒ Object
- #tr8n_flashes_tag(opts = {}) ⇒ Object
- #tr8n_language_flag_tag(lang = tr8n_current_language, opts = {}) ⇒ Object
- #tr8n_language_name_tag(lang = tr8n_current_language, opts = {}) ⇒ Object
- #tr8n_language_selector_tag(opts = {}) ⇒ Object
- #tr8n_language_strip_tag(opts = {}) ⇒ Object
- #tr8n_options_for_select(options, selected = nil, description = nil, lang = Tr8n.session.current_language) ⇒ Object
- #tr8n_phrases_link_tag(search = "", phrase_type = :without, phrase_status = :any) ⇒ Object
- #tr8n_scripts_tag(opts = {}) ⇒ Object
- #tr8n_select_month(date, options = {}, html_options = {}) ⇒ Object
-
#tr8n_style_attribute_tag(attr_name = 'float', default = 'right', lang = tr8n_current_language) ⇒ Object
Language Direction Support.
- #tr8n_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tr8n_current_language) ⇒ Object
- #tr8n_when_string_tag(time, opts = {}) ⇒ Object
- #tr8n_with_options_tag(opts, &block) ⇒ Object
Instance Method Details
#tr8n_dir_attribute_tag(lang = tr8n_current_language) ⇒ Object
153 154 155 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 153 def tr8n_dir_attribute_tag(lang = tr8n_current_language) "dir='#{lang.dir}'".html_safe end |
#tr8n_flashes_tag(opts = {}) ⇒ Object
82 83 84 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 82 def tr8n_flashes_tag(opts = {}) render(:partial => '/tr8n_client_sdk/tags/flashes', :locals => {:opts => opts}) end |
#tr8n_language_flag_tag(lang = tr8n_current_language, opts = {}) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 41 def tr8n_language_flag_tag(lang = tr8n_current_language, opts = {}) return "" unless tr8n_application.feature_enabled?(:language_flags) html = image_tag(lang.flag_url, :style => "vertical-align:middle;", :title => lang.native_name) html << " ".html_safe html.html_safe end |
#tr8n_language_name_tag(lang = tr8n_current_language, opts = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 48 def tr8n_language_name_tag(lang = tr8n_current_language, opts = {}) show_flag = opts[:flag].nil? ? true : opts[:flag] name_type = opts[:name].nil? ? :full : opts[:name] # :full, :native, :english, :locale linked = opts[:linked].nil? ? true : opts[:linked] html = "<span style='white-space: nowrap'>" html << tr8n_language_flag_tag(lang, opts) if show_flag html << "<span dir='ltr'>" name = case name_type when :native then lang.native_name when :english then lang.english_name when :locale then lang.locale else lang.full_name end html << name html << "</span></span>" html.html_safe end |
#tr8n_language_selector_tag(opts = {}) ⇒ Object
69 70 71 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 69 def tr8n_language_selector_tag(opts = {}) render(:partial => '/tr8n_client_sdk/tags/language_selector', :locals => {:opts => opts}) end |
#tr8n_language_strip_tag(opts = {}) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 73 def tr8n_language_strip_tag(opts = {}) opts[:flag] = opts[:flag].nil? ? false : opts[:flag] opts[:name] = opts[:name].nil? ? :native : opts[:name] opts[:linked] = opts[:linked].nil? ? true : opts[:linked] opts[:javascript] = opts[:javascript].nil? ? false : opts[:javascript] render(:partial => '/tr8n_client_sdk/tags/language_strip', :locals => {:opts => opts}) end |
#tr8n_options_for_select(options, selected = nil, description = nil, lang = Tr8n.session.current_language) ⇒ Object
28 29 30 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 28 def (, selected = nil, description = nil, lang = Tr8n.session.current_language) (.tro(description), selected) end |
#tr8n_phrases_link_tag(search = "", phrase_type = :without, phrase_status = :any) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 32 def tr8n_phrases_link_tag(search = "", phrase_type = :without, phrase_status = :any) return unless Tr8n.config.enabled? return if tr8n_current_language.default? return unless tr8n_current_translator.inline? link_to(image_tag(tr8n_application.url_for("/assets/tr8n/translate_icn.gif"), :style => "vertical-align:middle; border: 0px;", :title => search), tr8n_application.url_for("/tr8n/app/phrases/index?search=#{search}")).html_safe end |
#tr8n_scripts_tag(opts = {}) ⇒ Object
86 87 88 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 86 def tr8n_scripts_tag(opts = {}) render(:partial => '/tr8n_client_sdk/tags/scripts', :locals => {:opts => opts}) end |
#tr8n_select_month(date, options = {}, html_options = {}) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 90 def tr8n_select_month(date, = {}, = {}) month_names = [:use_short_month] ? Tr8n.config.default_abbr_month_names : Tr8n.config.default_month_names select_month(date, .merge( :use_month_names => month_names.collect{|month_name| tr8n_current_language.translate(month_name, [:description] || "Month name")} ), ) end |
#tr8n_style_attribute_tag(attr_name = 'float', default = 'right', lang = tr8n_current_language) ⇒ Object
Language Direction Support
145 146 147 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 145 def tr8n_style_attribute_tag(attr_name = 'float', default = 'right', lang = tr8n_current_language) "#{attr_name}:#{lang.align(default)}".html_safe end |
#tr8n_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tr8n_current_language) ⇒ Object
149 150 151 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 149 def tr8n_style_directional_attribute_tag(attr_name = 'padding', default = 'right', value = '5px', lang = tr8n_current_language) "#{attr_name}-#{lang.align(default)}:#{value}".html_safe end |
#tr8n_when_string_tag(time, opts = {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 114 def tr8n_when_string_tag(time, opts = {}) elapsed_seconds = Time.now - time if elapsed_seconds < 0 tr('In the future, Marty!', 'Time reference') elsif elapsed_seconds < 2.minutes tr('a moment ago', 'Time reference') elsif elapsed_seconds < 55.minutes elapsed_minutes = (elapsed_seconds / 1.minute).to_i tr("{minutes||minute} ago", 'Time reference', :minutes => elapsed_minutes) elsif elapsed_seconds < 1.75.hours tr("about an hour ago", 'Time reference') elsif elapsed_seconds < 12.hours elapsed_hours = (elapsed_seconds / 1.hour).to_i tr("{hours||hour} ago", 'Time reference', :hours => elapsed_hours) elsif time.today_in_time_zone? display_time(time, :time_am_pm) elsif time.yesterday_in_time_zone? tr("Yesterday at {time}", 'Time reference', :time => time.tr(:time_am_pm).gsub('/ ', '/').sub(/^[0:]*/,"")) elsif elapsed_seconds < 5.days time.tr(:day_time).gsub('/ ', '/').sub(/^[0:]*/,"") elsif time.same_year_in_time_zone? time.tr(:monthname_abbr_time).gsub('/ ', '/').sub(/^[0:]*/,"") else time.tr(:monthname_abbr_year_time).gsub('/ ', '/').sub(/^[0:]*/,"") end end |
#tr8n_with_options_tag(opts, &block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tr8n_client_sdk/extensions/action_view_extension.rb', line 97 def (opts, &block) if Tr8n.config.disabled? return capture(&block) if block_given? return "" end Thread.current[:block_options] ||= [] Thread.current[:block_options].push(opts) if block_given? ret = capture(&block) end Thread.current[:block_options].pop ret end |