· 1 min read
Screencast: Internationalisierung im Backend
Download:
Download(18 MB, 11:11) Alternativer Download für iPod & Apple TV(18.3 MB, 11:11)
Resourcen:
Quellcode:
[bash] rails g controller translations index brew install redis [/bash]
[ruby] # Gemfile gem ‘redis’
# config/initializers/i18n_backend.rb TRANSLATION_STORE = Redis.new I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(TRANSLATION_STORE), I18n.backend)
# translations_controller.rb 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 [/ruby]
[html]
<%= t “welcome” %>
Translations
- <% @translations.keys.each do |key| %>
- <%= key %>: <%= @translations\[key\] %> <% end %>
Add Translation
<%= form_tag translations_path do %>
<%= label_tag :locale %>
<%= text_field_tag :locale %>
<%= label_tag :key %>
<%= text_field_tag :key %>
<%= label_tag :value %>
<%= text_field_tag :value %>
<%= submit_tag “Submit” %>
<% end %> [/html][text] # config/locales/en.yml en: welcome: “Welcome” [/text]