Skip to content

Commit

Permalink
Rails 6.0.0rc1 try023
Browse files Browse the repository at this point in the history
update I18n fallbacks configuration to be compatible with i18n 1.1.0
rails/rails#33574

Describe how to silence the deprecation warning about empty I18n
fallbacks
rails/rails#35052
  • Loading branch information
suketa committed May 23, 2019
1 parent c76a3a9 commit f57f99e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 32 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/i18n_fallbacks.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the i18n_fallbacks controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
4 changes: 4 additions & 0 deletions app/controllers/i18n_fallbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class I18nFallbacksController < ApplicationController
def index
end
end
2 changes: 2 additions & 0 deletions app/helpers/i18n_fallbacks_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module I18nFallbacksHelper
end
16 changes: 16 additions & 0 deletions app/views/i18n_fallbacks/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<% I18n.with_locale(:de) do %>
<h1>I18n Fallbacks Test</h1>
<h2>I18n settings</h2>
<ul>
<li>I18n.default_locale = <%= I18n.default_locale %></li>
<li>I18n.locale = <%= I18n.locale %></li>
<li>I18n.fallbacks = <%= I18n.fallbacks %></li>
</ul>

<h2>I18n translations</h2>
<ul>
<li>morning=<%= t(:morning) %></li>
<li>afternoon=<%= t(:afternoon) %></li>
<li>night=<%= t(:night) %></li>
</ul>
<% end %>
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

config.i18n.fallbacks = [{de: :ja}]
# config.i18n.fallbacks = [nil, {de: :ja}]
end
3 changes: 3 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
de:
night: Gute Nacht

33 changes: 1 addition & 32 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,2 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# 'true': 'foo'
#
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
morning: "Good Morning"
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ja:
afternoon: こんにちは
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Rails.application.routes.draw do
get 'i18n_fallbacks/index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
18 changes: 18 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 0) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

end
9 changes: 9 additions & 0 deletions test/controllers/i18n_fallbacks_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'test_helper'

class I18nFallbacksControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get i18n_fallbacks_index_url
assert_response :success
end

end

0 comments on commit f57f99e

Please sign in to comment.