RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
rails g controller translations index brew install redis
gem 'redis'
TRANSLATION_STORE = Redis.new I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(TRANSLATION_STORE), I18n.backend)
def index @translations = TRANSLATION_STORE end def create I18n.backend.store_translations(params[:locale], {params[:key] => params[:value]}, :escape => false) redirect_to translations_url, :notice => "Added translation" end
<h1><%= t "welcome" %></h1>
<h1>Translations</h1> <ul> <% @translations.keys.each do |key| %> <li><%= key %>: <%= @translations[key] %></li> <% end %> </ul> <h2>Add Translation</h2> <%= form_tag translations_path do %> <p> <%= label_tag :locale %><br /> <%= text_field_tag :locale %> </p> <p> <%= label_tag :key %><br /> <%= text_field_tag :key %> </p> <p> <%= label_tag :value %><br /> <%= text_field_tag :value %> </p> <p><%= submit_tag "Submit" %></p> <% end %>
en: welcome: "Welcome"