Created
April 7, 2010 16:30
-
-
Save jamesbebbington/359096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class I18nController < ApplicationController | |
caches_page :show | |
# Renders HTTP cacheable JSON encoded dictionary of translation strings for requested locale and currently selected locale | |
def show | |
@locale = params[:locale].to_sym | |
raise ActiveRecord::RecordNotFound unless I18n.selectable_locales.include?(@locale) | |
respond_to do |format| | |
format.js do | |
@strings = I18n.t('javascript', :locale => @locale) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionController::Routing::Routes.draw do |map| | |
map.i18n '/javascripts/i18n/i18n.:locale.:format', :controller => "i18n", :action => "show" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quick and dirty I18n object that echos the basic functionality of the I18n gem. | |
// e.g. I18n.t('key.to.translate', {interpolation_key: interpolation_value}) | |
var I18n = { | |
locale: '<%= @locale %>', | |
strings: <%= raw(@strings.to_json) %>, | |
t: function(key, interpolations) { | |
string = eval("this.strings." + key); | |
for (key in interpolations) { | |
string = string.replace(new RegExp("\{\{" + key + "\}\}"), interpolations[key]) | |
} | |
return string; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment