module ApplicationHelper @@keyQueue = nil @@translationsOnThisPage = nil @@lastTranslation = nil @@allTranslations = nil @@no_banner = true def ThereAreTranslationsOnThisPage? @@translationsOnThisPage end def get_all_translations @@allTranslations end def title(page_title) content_for(:title) { page_title.to_s } end def banner_image(banner_image) @@no_banner = false content_for(:banner_image) { banner_image.to_s } end def banner_attrs(banner_image) if banner_image.length > 0 return {style: 'background-image: url(' + banner_image + ');', class: 'has-image' } end {class: 'no-image'} end def has_banner? !@@no_banner end def banner_title(banner_title) @@no_banner = false content_for(:banner) { ('

' + banner_title.to_s + '

').html_safe } end def page_style(style) classes = ['page-style-' + style.to_s] if @@no_banner classes << 'no-banner' end if ThereAreTranslationsOnThisPage? classes << 'has-translations' end if params[:controller] classes << params[:controller] if params[:action] classes << params[:controller] + '-' + params[:action] end end content_for(:page_style) { classes.join(' ') } end def yield_or_default(section, default = '') content_for?(section) ? content_for(section) : default end def _(key, behavior = nil, behavior_size = nil, locale: nil, vars: {}, html: nil, blockData: {}, &block) options = vars options[:fallback] = true if behavior options[:behavior] = behavior options[:behavior_size] = behavior_size end if locale options[:locale] = locale.to_sym end #if vars # puts "\nVARS:\t#{vars}\n" #end I18n.translate(key, options) #queued_keys = nil # #result = nil # # #if key.kind_of?(Hash) # # blockData.merge!(key) # # key = key.keys # #end # # #if block_given? # # @@keyQueue ||= Array.new # # # if key.kind_of?(Array) # # @@keyQueue += key # # else # # @@keyQueue << key # # end # #end # # #if key.kind_of?(Array) # # new_key = key.shift # # if key.count > 0 # # queued_keys = key.dup # # end # # key = new_key # #end # # #if blockData[key] # # behavior = blockData[key][:behavior] || nil # # behavior_size = blockData[key][:behavior_size] || nil # # vars = blockData[key][:vars] || {} # #end # # #@@lastTranslation = nil # #generate_control = _can_translate? # # #puts "\nLLOOCCAALLEE:\t#{locale.to_s}" # #translation = _do_translate(key, vars, behavior, behavior_size, locale) # # #if block_given? # # html = capture(&block) # #end # # #if html # # translation['html'] = html.gsub('%' + key + '%', translation['untranslated']) # #end # # #if generate_control # # @@lastTranslation = translation # # @@allTranslations ||= Hash.new # # @@allTranslations[key] = key # # # result = _translate_me(translation) # #end # # #result ||= translation['html'] || (behavior.to_s == 'strict' ? nil : translation['untranslated']) # # #if queued_keys # # return _ queued_keys, behavior, behavior_size, vars: vars, html: result, blockData: blockData # #end # #return result end def _translate_me(translation) @@translationsOnThisPage = true datakeys = '' translation['vars'].each { |key, value| datakeys += ' data-var-' + key.to_s + '="' + value.to_s.gsub('"', '"') + '"' } ('' + (translation['html'] || translation['untranslated']) + '').to_s.html_safe end def _do_translate(key, vars, behavior, behavior_size, locale) translation = {'key' => key, 'lang' => '0', 'vars' => vars} v = vars.dup #locale ||= I18n.locale begin v[:raise] = true #v[:locale] = locale.to_sym #v[:fallback] = false #puts "\nSTART\n" options = {:raise => true} if locale options[:locale] = locale.to_sym end #puts "\n#{options.to_json.to_s}\n" translation['untranslated'] = I18n.translate(key, v, options) #puts "\nEND\n" translation['lang'] = locale.to_s translation['is_translated'] = true hash = Hash.new translations = Translation.where(["locale = ? AND key LIKE ?", locale.to_s, key + '%']).take(6).each { |o| hash[o.key] = o.value } translation['translated'] = hash.to_json.gsub('"', '"') rescue I18n::MissingTranslationData #begin #translation['untranslated'] = I18n.translate!(config.i18n.default_locale, key, vars) #translation['lang'] = config.i18n.default_locale.to_s #rescue #puts "BEHAVIOR:\t#{behavior.to_s}" default_translation = I18n::MissingTranslationExceptionHandler.note(key, behavior, behavior_size) translation['untranslated'] = default_translation #end end puts "TRANSLATION:\t#{translation.to_json.to_s}" return translation end def _can_translate?() false end def _!() if @@keyQueue return '%' + @@keyQueue.shift + '%' end end def _?() if @@keyQueue return '%' + @@keyQueue[0] + '%' end end def sortable(objects, id = 'id', url: nil, &block) result = '