Files
nairobi/app/helpers/globalize_helper.rb
iagirre 8b9d1ebd33 Make portuguese locale work
There was a problem with the portuguese locale.
The locale was pt-BR, but `globalize_accessors` gem
doesn't allow the creation of methods using locales
with that format.

To avoid transforming pt-BR to pt and lose the distinction
of the different variations of the language, a function has
been added to transform pt-BR into pt_br (without changing
the locale itself). That way, when globalize uses the locales,
all of them will have a valid format (downcased and underscored)
AND they will be always the same (comparing pt-BR with pt_br
doesn't work).
2018-05-09 16:07:21 +02:00

46 lines
1.0 KiB
Ruby

module GlobalizeHelper
def globalize_locale
params[:globalize_locale] || I18n.locale
end
def options_for_locale_select
options_for_select(locale_options, nil)
end
def locale_options
I18n.available_locales.map do |locale|
[name_for_locale(locale), neutral_locale(locale)]
end
end
def display_translation?(locale)
neutral_locale(I18n.locale) == neutral_locale(locale) ? "" : "display: none"
end
def css_to_display_translation?(resource, locale)
resource.translated_locales.include?(neutral_locale(locale)) || locale == I18n.locale ? "" : "display: none"
end
def disable_translation?(locale)
locale == "en" ? "" : "disabled"
end
def css_for_globalize_locale(locale)
globalize_locale == locale ? "highlight" : ""
end
def highlight_current?(locale)
I18n.locale == locale ? 'highlight' : ''
end
def show_delete?(locale)
I18n.locale == locale ? '' : 'display: none'
end
def neutral_locale(locale)
locale.to_s.downcase.underscore.to_sym
end
end