Sha256: e2c0d17a4d87ccd1c401ef5a77040f3c25b75c9040c499ee76535896753621a4
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
class LocaleJs::LocaleController < ApplicationController # remember to add the locales route # map.connect '/locale/:action.:format', :controller => :locale # then add this to your layout <%= javascript_include_tag "/locale/#{I18n.locale}.js" %> # your locale will be available in a javascript global: I18n rescue_from AbstractController::ActionNotFound, :with => :action_mising # this method searches the locales dir and then defines methods on this class for each locale Dir.glob(File.join(Rails.root,'config/locales/*.yml')).map do |file| locale = File.basename(file).match(/(.+)\.yml/)[1] define_method(locale) do generate_locale(locale) end end private def generate_locale(locale) expires(30.days.from_now) I18n.locale = locale # initialize i18n I18n.translate :hello @locale = I18n.backend.send(:translations)[I18n.locale] render :template => 'locale/i18n' end def action_missing(action) logger.debug("No config/locales/#{action}.yml exists! Reverting to #{I18n.default_locale}") generate_locale(I18n.default_locale) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locale_js-0.2.0 | app/controllers/locale_js/locale_controller.rb |