r18n-rails 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +1 -1
- data/Rakefile +5 -3
- data/lib/r18n-rails.rb +28 -28
- data/lib/r18n-rails/controller.rb +22 -20
- data/lib/r18n-rails/filters.rb +22 -21
- data/lib/r18n-rails/helpers.rb +20 -20
- data/lib/r18n-rails/translated.rb +18 -18
- data/r18n-rails.gemspec +5 -4
- data/spec/app/app/controllers/application_controller.rb +2 -0
- data/spec/app/app/controllers/test_controller.rb +7 -5
- data/spec/app/app/i18n/filters.rb +3 -1
- data/spec/app/app/mailers/test_mailer.rb +2 -0
- data/spec/app/app/models/post.rb +2 -0
- data/spec/app/config.ru +3 -1
- data/spec/app/config/application.rb +9 -7
- data/spec/app/config/boot.rb +4 -2
- data/spec/app/config/environment.rb +3 -1
- data/spec/app/config/environments/test.rb +3 -1
- data/spec/app/config/initializers/r18n.rb +2 -0
- data/spec/app/config/initializers/secret_token.rb +2 -0
- data/spec/app/config/routes.rb +2 -0
- data/spec/app/db/migrate/20091218123631_create_posts.rb +2 -0
- data/spec/app/db/schema.rb +10 -8
- data/spec/rails_spec.rb +35 -32
- data/spec/spec_helper.rb +5 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f89d4df26a1849c69bff90ed718823bf56c79bc0312544950bf3cee3a2d2bc3
|
4
|
+
data.tar.gz: 245b26a363d89724b14586b375a252e3ac0fb7da2a01b93b142ef19b2d3f8658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6bc6137b61b9390d4ae754ffe413a415bc79799a1184f8bc2dc4288cada211d32e5a28881950919e4fb17ffc70f13d09cadb5f34b93c597eb14204d78bb20a7
|
7
|
+
data.tar.gz: 1a82c0ff9431801aadd5c373adba5edf88e888fd096afae43359c1b264ed606d787089d4a4aeb9e65fdf9bf180b0ded7b34ab0278d1d895825ae52ce47cabd93
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--format documentation --colour
|
1
|
+
--format documentation --colour --warnings --require spec_helper
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
|
3
5
|
require 'bundler/setup'
|
@@ -5,9 +7,9 @@ Bundler::GemHelper.install_tasks
|
|
5
7
|
|
6
8
|
require 'rspec/core/rake_task'
|
7
9
|
RSpec::Core::RakeTask.new
|
8
|
-
task :
|
10
|
+
task default: :spec
|
9
11
|
|
10
12
|
task :clobber_package do
|
11
|
-
|
13
|
+
rm_rf 'pkg'
|
12
14
|
end
|
13
|
-
task :
|
15
|
+
task clobber: [:clobber_package]
|
data/lib/r18n-rails.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# R18n support for Rails.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
3
19
|
|
4
|
-
Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
5
|
-
|
6
|
-
This program is free software: you can redistribute it and/or modify
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
9
|
-
(at your option) any later version.
|
10
|
-
|
11
|
-
This program is distributed in the hope that it will be useful,
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
GNU Lesser General Public License for more details.
|
15
|
-
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
17
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
=end
|
19
|
-
|
20
|
-
require 'pathname'
|
21
20
|
require 'r18n-core'
|
22
21
|
require 'r18n-rails-api'
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
require dir + 'filters'
|
23
|
+
require_relative 'r18n-rails/helpers'
|
24
|
+
require_relative 'r18n-rails/controller'
|
25
|
+
require_relative 'r18n-rails/translated'
|
26
|
+
require_relative 'r18n-rails/filters'
|
29
27
|
|
30
28
|
R18n.default_places { [Rails.root.join('app/i18n'), R18n::Loader::Rails.new] }
|
31
29
|
|
@@ -50,10 +48,12 @@ ActiveSupport.on_load(:after_initialize) do
|
|
50
48
|
env = ENV['LANG']
|
51
49
|
env = env.split('.').first if env
|
52
50
|
locale = env || I18n.default_locale.to_s
|
53
|
-
if defined?
|
54
|
-
i18n
|
55
|
-
|
56
|
-
|
51
|
+
if defined?(Rails::Console) && !defined?(Wirble)
|
52
|
+
i18n = R18n::I18n.new(
|
53
|
+
locale, R18n.default_places,
|
54
|
+
off_filters: :untranslated,
|
55
|
+
on_filters: :untranslated_bash
|
56
|
+
)
|
57
57
|
R18n.set(i18n)
|
58
58
|
else
|
59
59
|
R18n.set(locale)
|
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Methods and filters to controllers.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
require 'r18n-rails-api'
|
21
21
|
|
@@ -38,8 +38,10 @@ module R18n
|
|
38
38
|
locales.insert(0, session[:locale])
|
39
39
|
end
|
40
40
|
|
41
|
-
i18n = R18n::I18n.new(
|
42
|
-
|
41
|
+
i18n = R18n::I18n.new(
|
42
|
+
locales, R18n.default_places,
|
43
|
+
off_filters: :untranslated, on_filters: :untranslated_html
|
44
|
+
)
|
43
45
|
::I18n.locale = i18n.locale.code.to_sym
|
44
46
|
i18n
|
45
47
|
end
|
data/lib/r18n-rails/filters.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
the
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Load R18n filters from Rails app directory.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
21
|
module Rails
|
@@ -28,14 +28,15 @@ module R18n
|
|
28
28
|
# Path to filters. Should be set to `app/i18n`.
|
29
29
|
attr_writer :path
|
30
30
|
def path
|
31
|
-
@path
|
31
|
+
return @path if defined?(@path)
|
32
|
+
::Rails.root.join('app/i18n')
|
32
33
|
end
|
33
34
|
|
34
35
|
# Load all ruby files from `app/i18n` and remember loaded filters.
|
35
36
|
def load!
|
36
|
-
@loaded = R18n::Filters.listen
|
37
|
+
@loaded = R18n::Filters.listen do
|
37
38
|
Pathname.glob(path.join('**/*.rb').to_s) { |i| load i.to_s; }
|
38
|
-
|
39
|
+
end.map(&:name)
|
39
40
|
end
|
40
41
|
|
41
42
|
# Shortcut to call `remove!` and `load!`.
|
data/lib/r18n-rails/helpers.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
|
2
|
-
R18n helpers for Rails.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# R18n helpers for Rails.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
21
|
module Rails
|
@@ -42,7 +42,7 @@ module R18n
|
|
42
42
|
super(*params)
|
43
43
|
end
|
44
44
|
end
|
45
|
-
alias
|
45
|
+
alias translate t
|
46
46
|
|
47
47
|
# Extend +l+ helper to use also R18n syntax.
|
48
48
|
#
|
@@ -50,13 +50,13 @@ module R18n
|
|
50
50
|
# l Time.now, format: :short # Rails I18n style
|
51
51
|
# l Time.now, :human # R18n style
|
52
52
|
def l(obj, *params)
|
53
|
-
if params.empty?
|
53
|
+
if params.empty? || params.first.is_a?(Hash)
|
54
54
|
super(obj, *params)
|
55
55
|
else
|
56
56
|
r18n.l(obj, *params)
|
57
57
|
end
|
58
58
|
end
|
59
|
-
alias
|
59
|
+
alias localize l
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
|
2
|
-
ActiveRecord fix mixin to R18n::Translated.
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
# ActiveRecord fix mixin to R18n::Translated.
|
4
|
+
#
|
5
|
+
# Copyright (C) 2011 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
21
|
module Translated
|
22
22
|
module Base
|
23
23
|
def unlocalized_methods
|
24
|
-
if defined?
|
24
|
+
if defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
|
25
25
|
column_names + column_names.map { |i| i + '=' } + instance_methods
|
26
26
|
else
|
27
27
|
instance_methods
|
data/r18n-rails.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../r18n-core/lib/r18n-core/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.platform = Gem::Platform::RUBY
|
@@ -7,14 +9,14 @@ Gem::Specification.new do |s|
|
|
7
9
|
s.date = Time.now.strftime('%Y-%m-%d')
|
8
10
|
|
9
11
|
s.summary = 'R18n for Rails'
|
10
|
-
s.description = <<-
|
12
|
+
s.description = <<-DESC
|
11
13
|
Out-of-box R18n support for Ruby on Rails.
|
12
14
|
It is just a wrapper for R18n Rails API and R18n core libraries.
|
13
15
|
R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,
|
14
16
|
translation support for any classes, time and number localization, several
|
15
17
|
user language support, agnostic core package with out-of-box support for
|
16
18
|
Rails, Sinatra and desktop applications.
|
17
|
-
|
19
|
+
DESC
|
18
20
|
|
19
21
|
s.files = `git ls-files`.split("\n")
|
20
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -28,4 +30,3 @@ Gem::Specification.new do |s|
|
|
28
30
|
|
29
31
|
s.add_dependency 'r18n-rails-api', "= #{R18n::VERSION}"
|
30
32
|
end
|
31
|
-
|
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TestController < ApplicationController
|
2
4
|
layout false
|
3
5
|
|
4
6
|
before_action :reload_r18n, only: :filter
|
5
7
|
|
6
8
|
def locales
|
7
|
-
render plain: R18n.get.locales.map
|
9
|
+
render plain: R18n.get.locales.map(&:code).join(', ')
|
8
10
|
end
|
9
11
|
|
10
12
|
def translations
|
11
|
-
render plain: "R18n: #{R18n.get.r18n.translations}. "
|
13
|
+
render plain: "R18n: #{R18n.get.r18n.translations}. " \
|
12
14
|
"Rails I18n: #{R18n.get.i18n.translations}"
|
13
15
|
end
|
14
16
|
|
15
17
|
def available
|
16
|
-
render plain: R18n.get.available_locales.map
|
18
|
+
render plain: R18n.get.available_locales.map(&:code).sort.join(' ')
|
17
19
|
end
|
18
20
|
|
19
21
|
def helpers
|
@@ -22,7 +24,7 @@ class TestController < ApplicationController
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def untranslated
|
25
|
-
render plain:
|
27
|
+
render plain: R18n.get.user.not.exists.to_s
|
26
28
|
end
|
27
29
|
|
28
30
|
def controller
|
@@ -31,7 +33,7 @@ class TestController < ApplicationController
|
|
31
33
|
|
32
34
|
def time
|
33
35
|
render plain: l(Time.at(0).utc) + "\n" +
|
34
|
-
|
36
|
+
l(Time.at(0).utc, format: :short)
|
35
37
|
end
|
36
38
|
|
37
39
|
def human_time
|
data/spec/app/app/models/post.rb
CHANGED
data/spec/app/config.ru
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require_relative 'boot'
|
4
|
+
|
5
|
+
require 'active_record/railtie'
|
6
|
+
require 'action_controller/railtie'
|
7
|
+
require 'action_mailer/railtie'
|
8
|
+
require 'rails/test_unit/railtie'
|
7
9
|
|
8
10
|
if defined?(Bundler)
|
9
|
-
Bundler.require(*Rails.groups(assets: %w
|
11
|
+
Bundler.require(*Rails.groups(assets: %w[development test]))
|
10
12
|
end
|
11
13
|
|
12
14
|
module App
|
13
15
|
class Application < Rails::Application
|
14
16
|
config.time_zone = 'UTC'
|
15
17
|
config.i18n.default_locale = :ru
|
16
|
-
config.encoding =
|
18
|
+
config.encoding = 'utf-8'
|
17
19
|
|
18
20
|
def config.database_configuration
|
19
21
|
sqlite = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
|
data/spec/app/config/boot.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.join(__dir__, '..', 'Gemfile')
|
3
5
|
|
4
|
-
require 'bundler/setup' if File.
|
6
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
App::Application.configure do
|
2
4
|
config.cache_classes = true
|
3
5
|
config.serve_static_files = true
|
4
|
-
config.static_cache_control =
|
6
|
+
config.static_cache_control = 'public, max-age=3600'
|
5
7
|
config.eager_load = false
|
6
8
|
config.consider_all_requests_local = true
|
7
9
|
config.action_controller.perform_caching = false
|
data/spec/app/config/routes.rb
CHANGED
data/spec/app/db/schema.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is auto-generated from the current state of the database. Instead
|
2
4
|
# of editing this file, please use the migrations feature of Active Record to
|
3
|
-
# incrementally modify your database, and then regenerate
|
5
|
+
# incrementally modify your database, and then regenerate
|
6
|
+
# this schema definition.
|
4
7
|
#
|
5
8
|
# Note that this schema.rb definition is the authoritative source for your
|
6
9
|
# database schema. If you need to create the application database on another
|
7
10
|
# system, you should be using db:schema:load, not running all the migrations
|
8
|
-
# from scratch. The latter is a flawed and unsustainable approach
|
9
|
-
# you'll amass, the slower it'll run
|
11
|
+
# from scratch. The latter is a flawed and unsustainable approach
|
12
|
+
# (the more migrations you'll amass, the slower it'll run
|
13
|
+
# and the greater likelihood for issues).
|
10
14
|
#
|
11
15
|
# It's strongly recommended to check this file into your version control system.
|
12
16
|
|
13
17
|
ActiveRecord::Schema.define(version: 20091218123631) do
|
14
|
-
|
15
|
-
|
16
|
-
t.string
|
17
|
-
t.string "title_ru"
|
18
|
+
create_table 'posts', force: true do |t|
|
19
|
+
t.string 'title_en'
|
20
|
+
t.string 'title_ru'
|
18
21
|
end
|
19
|
-
|
20
22
|
end
|
data/spec/rails_spec.rb
CHANGED
@@ -1,93 +1,94 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe TestController, type: :controller do
|
4
4
|
render_views
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'uses default locale' do
|
7
7
|
get :locales
|
8
8
|
expect(response).to be_success
|
9
9
|
expect(response.body).to eq 'ru'
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'gets locale from param' do
|
13
13
|
get :locales, params: { locale: 'ru' }
|
14
14
|
expect(response).to be_success
|
15
15
|
expect(response.body).to eq 'ru, en'
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'gets locale from session' do
|
19
19
|
get :locales, session: { locale: 'ru' }
|
20
20
|
expect(response).to be_success
|
21
21
|
expect(response.body).to eq 'ru, en'
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'gets locales from http' do
|
25
25
|
request.env['HTTP_ACCEPT_LANGUAGE'] = 'ru,fr;q=0.9'
|
26
26
|
get :locales
|
27
27
|
expect(response).to be_success
|
28
28
|
expect(response.body).to eq 'ru, fr, en'
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'loads translations' do
|
32
32
|
get :translations, params: { locale: 'en' }
|
33
33
|
expect(response).to be_success
|
34
34
|
expect(response.body).to eq 'R18n: supported. Rails I18n: supported'
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'returns available translations' do
|
38
38
|
get :available
|
39
39
|
expect(response).to be_success
|
40
40
|
expect(response.body).to eq 'en ru'
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'adds helpers' do
|
44
44
|
get :helpers, params: { locale: 'en' }
|
45
45
|
expect(response).to be_success
|
46
46
|
expect(response.body).to eq "Name\nName\nName\nName\n"
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'formats untranslated' do
|
50
50
|
get :untranslated
|
51
51
|
expect(response).to be_success
|
52
52
|
expect(response.body).to eq(
|
53
|
-
'user.<span style="color: red">[not.exists]</span>'
|
53
|
+
'user.<span style="color: red">[not.exists]</span>'
|
54
|
+
)
|
54
55
|
end
|
55
56
|
|
56
|
-
it
|
57
|
+
it 'adds methods to controller' do
|
57
58
|
get :controller, params: { locale: 'en' }
|
58
59
|
expect(response).to be_success
|
59
|
-
expect(response.body).to eq
|
60
|
+
expect(response.body).to eq 'Name Name Name'
|
60
61
|
end
|
61
62
|
|
62
|
-
it
|
63
|
+
it 'localizes time by Rails I18n' do
|
63
64
|
get :time, params: { locale: 'en' }
|
64
65
|
expect(response).to be_success
|
65
66
|
expect(response.body).to eq "Thu, 01 Jan 1970 00:00:00 +0000\n01 Jan 00:00"
|
66
67
|
end
|
67
68
|
|
68
|
-
it
|
69
|
+
it 'localizes time by R18n' do
|
69
70
|
get :human_time, params: { locale: 'en' }
|
70
71
|
expect(response).to be_success
|
71
72
|
expect(response.body).to eq 'now'
|
72
73
|
end
|
73
74
|
|
74
|
-
it
|
75
|
+
it 'translates models' do
|
75
76
|
ActiveRecord::Schema.verbose = false
|
76
|
-
ActiveRecord::Schema.define(version:
|
77
|
-
create_table
|
78
|
-
t.string
|
79
|
-
t.string
|
77
|
+
ActiveRecord::Schema.define(version: 20_091_218_130_034) do
|
78
|
+
create_table 'posts', force: true do |t|
|
79
|
+
t.string 'title_en'
|
80
|
+
t.string 'title_ru'
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
|
-
expect(Post.unlocalized_getters(:title)).to eq(
|
84
|
+
expect(Post.unlocalized_getters(:title)).to eq(
|
84
85
|
'ru' => 'title_ru',
|
85
86
|
'en' => 'title_en'
|
86
|
-
|
87
|
-
expect(Post.unlocalized_setters(:title)).to eq(
|
87
|
+
)
|
88
|
+
expect(Post.unlocalized_setters(:title)).to eq(
|
88
89
|
'ru' => 'title_ru=',
|
89
90
|
'en' => 'title_en='
|
90
|
-
|
91
|
+
)
|
91
92
|
|
92
93
|
@post = Post.new
|
93
94
|
@post.title_en = 'Record'
|
@@ -101,21 +102,22 @@ describe TestController, type: :controller do
|
|
101
102
|
expect(@post.title).to eq 'Запись'
|
102
103
|
end
|
103
104
|
|
104
|
-
it
|
105
|
+
it 'sets default places' do
|
105
106
|
expect(R18n.default_places).to eq([
|
106
|
-
Rails.root.join('app/i18n'), R18n::Loader::Rails.new
|
107
|
+
Rails.root.join('app/i18n'), R18n::Loader::Rails.new
|
108
|
+
])
|
107
109
|
|
108
110
|
R18n.set('en')
|
109
111
|
expect(R18n.get.user.name).to eq 'Name'
|
110
112
|
end
|
111
113
|
|
112
|
-
it
|
114
|
+
it 'translates mails' do
|
113
115
|
R18n.set('en')
|
114
116
|
email = TestMailer.test.deliver_now
|
115
117
|
expect(email.body.to_s).to eq "Name\nName\nName\n"
|
116
118
|
end
|
117
119
|
|
118
|
-
it
|
120
|
+
it 'reloads filters from app directory' do
|
119
121
|
get :filter, params: { locale: 'en' }
|
120
122
|
expect(response).to be_success
|
121
123
|
expect(response.body).to eq 'Rails'
|
@@ -128,20 +130,21 @@ describe TestController, type: :controller do
|
|
128
130
|
expect(response.body).to eq 'Rails'
|
129
131
|
end
|
130
132
|
|
131
|
-
it
|
133
|
+
it 'escapes html inside R18n' do
|
132
134
|
get :safe, params: { locale: 'en' }
|
133
135
|
expect(response).to be_success
|
134
136
|
expect(response.body).to eq(
|
135
|
-
"<b> user.<span style=\"color: red\">[no_tr]</span>\n"
|
137
|
+
"<b> user.<span style=\"color: red\">[no_tr]</span>\n"
|
138
|
+
)
|
136
139
|
end
|
137
140
|
|
138
|
-
it
|
141
|
+
it 'works with Rails build-in herlpers' do
|
139
142
|
get :format
|
140
143
|
expect(response).to be_success
|
141
144
|
expect(response.body).to eq "1 000,1 руб.\n"
|
142
145
|
end
|
143
146
|
|
144
|
-
it
|
147
|
+
it 'caches I18n object' do
|
145
148
|
R18n.clear_cache!
|
146
149
|
|
147
150
|
get :translations
|
@@ -158,7 +161,7 @@ describe TestController, type: :controller do
|
|
158
161
|
expect(R18n.cache.keys.length).to eq 2
|
159
162
|
end
|
160
163
|
|
161
|
-
it
|
164
|
+
it 'parameterizes strigns' do
|
162
165
|
expect('One two три'.parameterize).to eq 'one-two'
|
163
166
|
end
|
164
167
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pp'
|
2
4
|
|
3
5
|
ENV['RAILS_ENV'] ||= 'test'
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
require_relative 'app/config/environment'
|
8
|
+
require_relative '../lib/r18n-rails'
|
7
9
|
|
8
10
|
require 'rspec/rails'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r18n-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Sitnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: r18n-rails-api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
description: |2
|
28
28
|
Out-of-box R18n support for Ruby on Rails.
|
29
29
|
It is just a wrapper for R18n Rails API and R18n core libraries.
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.7.6
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: R18n for Rails
|