r18n-rails 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ca55b10d4e9b95b8cc878e16b49d7237f45d983
4
- data.tar.gz: 95a12dbd7bfdb5780319fad76664f154c1b0c55b
2
+ SHA256:
3
+ metadata.gz: 3f89d4df26a1849c69bff90ed718823bf56c79bc0312544950bf3cee3a2d2bc3
4
+ data.tar.gz: 245b26a363d89724b14586b375a252e3ac0fb7da2a01b93b142ef19b2d3f8658
5
5
  SHA512:
6
- metadata.gz: f32c329a5bc650017cb52e51cf57097ee8ac761cc158299af4743f602e7d2c3187cdf87e0c11a40c38f069b1c0dcf9a6c517b8d672252819e6891ac099211d2c
7
- data.tar.gz: c713106962acd4da89f67dd3970af8af014642da4adace1de7eb00f0e4794d331d417031c7316fbec0698bb75abe5f4c05bef768285cfae4582cfab92055b462
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 :default => :spec
10
+ task default: :spec
9
11
 
10
12
  task :clobber_package do
11
- rm_r 'pkg' rescue nil
13
+ rm_rf 'pkg'
12
14
  end
13
- task :clobber => [:clobber_package]
15
+ task clobber: [:clobber_package]
@@ -1,31 +1,29 @@
1
- =begin
2
- R18n support for Rails.
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
- dir = Pathname(__FILE__).dirname.expand_path + 'r18n-rails'
25
- require dir + 'helpers'
26
- require dir + 'controller'
27
- require dir + 'translated'
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? Rails::Console and not defined? Wirble
54
- i18n = R18n::I18n.new(locale, R18n.default_places,
55
- off_filters: :untranslated,
56
- on_filters: :untranslated_bash)
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
- =begin
2
- Methods and filters to controllers.
3
-
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
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(locales, R18n.default_places,
42
- off_filters: :untranslated, on_filters: :untranslated_html)
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
@@ -1,21 +1,21 @@
1
- =begin
2
- Load R18n filters from Rails app directory.
3
-
4
- Copyright (C) 2012 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
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 || ::Rails.root.join('app/i18n')
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
- }.map { |i| i.name }
39
+ end.map(&:name)
39
40
  end
40
41
 
41
42
  # Shortcut to call `remove!` and `load!`.
@@ -1,21 +1,21 @@
1
- =begin
2
- R18n helpers for Rails.
1
+ # frozen_string_literal: true
3
2
 
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
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 :translate :t
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? or params.first.is_a? Hash
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 :localize :l
59
+ alias localize l
60
60
  end
61
61
  end
62
62
  end
@@ -1,27 +1,27 @@
1
- =begin
2
- ActiveRecord fix mixin to R18n::Translated.
1
+ # frozen_string_literal: true
3
2
 
4
- Copyright (C) 2011 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
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? ActiveRecord and ancestors.include? ActiveRecord::Base
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
@@ -1,4 +1,6 @@
1
- require File.expand_path('../../r18n-core/lib/r18n-core/version', __FILE__)
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 = <<-EOF
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
- EOF
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  protect_from_forgery
3
5
  end
@@ -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 { |i| i.code }.join(', ')
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 { |i| i.code }.sort.join(' ')
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: "#{R18n.get.user.not.exists}"
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
- l(Time.at(0).utc, format: :short)
36
+ l(Time.at(0).utc, format: :short)
35
37
  end
36
38
 
37
39
  def human_time
@@ -1,3 +1,5 @@
1
- R18n::Filters.add('rails', :rails_custom_filter) do |content, config, *params|
1
+ # frozen_string_literal: true
2
+
3
+ R18n::Filters.add('rails', :rails_custom_filter) do |content, _config, *_params|
2
4
  content.gsub('Ruby', 'Rails')
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class TestMailer < ActionMailer::Base
2
4
  default from: 'from@example.com'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Post < ActiveRecord::Base
2
4
  include R18n::Translated
3
5
  translations :title
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
- require ::File.expand_path('../config/environment', __FILE__)
5
+ require_relative 'config/environment'
4
6
  run App::Application
@@ -1,19 +1,21 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
- require "active_record/railtie"
4
- require "action_controller/railtie"
5
- require "action_mailer/railtie"
6
- require "rails/test_unit/railtie"
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(development test)))
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 = "utf-8"
18
+ config.encoding = 'utf-8'
17
19
 
18
20
  def config.database_configuration
19
21
  sqlite = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
+ ENV['BUNDLE_GEMFILE'] ||= File.join(__dir__, '..', 'Gemfile')
3
5
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
6
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
4
+ require_relative 'application'
3
5
 
4
6
  # Initialize the rails application
5
7
  App::Application.initialize!
@@ -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 = "public, max-age=3600"
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
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Fix R18n Rails require, because it doesn’t require in global Gemfile.
2
4
  require 'r18n-rails'
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  App::Application.config.secret_key_base = 'test'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  App::Application.routes.draw do
2
4
  get '/locales', to: 'test#locales'
3
5
  get '/translations', to: 'test#translations'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePosts < ActiveRecord::Migration
2
4
  def self.up
3
5
  create_table :posts do |t|
@@ -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 this schema definition.
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 (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
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
- create_table "posts", force: true do |t|
16
- t.string "title_en"
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
@@ -1,93 +1,94 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe TestController, type: :controller do
4
4
  render_views
5
5
 
6
- it "uses default locale" do
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 "gets locale from param" do
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 "gets locale from session" do
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 "gets locales from http" do
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 "loads translations" do
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 "returns available translations" do
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 "adds helpers" do
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 "formats untranslated" do
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 "adds methods to controller" do
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 "Name Name Name"
60
+ expect(response.body).to eq 'Name Name Name'
60
61
  end
61
62
 
62
- it "localizes time by Rails I18n" do
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 "localizes time by R18n" do
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 "translates models" do
75
+ it 'translates models' do
75
76
  ActiveRecord::Schema.verbose = false
76
- ActiveRecord::Schema.define(version: 20091218130034) do
77
- create_table "posts", force: true do |t|
78
- t.string "title_en"
79
- t.string "title_ru"
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 "sets default places" do
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 "translates mails" do
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 "reloads filters from app directory" do
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 "escapes html inside R18n" do
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 "works with Rails build-in herlpers" do
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 "caches I18n object" do
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 "parameterizes strigns" do
164
+ it 'parameterizes strigns' do
162
165
  expect('One two три'.parameterize).to eq 'one-two'
163
166
  end
164
167
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pp'
2
4
 
3
5
  ENV['RAILS_ENV'] ||= 'test'
4
- dir = File.dirname(__FILE__)
5
- require File.expand_path(File.join(dir, 'app/config/environment'))
6
- require File.expand_path(File.join(dir, '../lib/r18n-rails'))
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: 2.2.0
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: 2017-12-22 00:00:00.000000000 Z
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: 2.2.0
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: 2.2.0
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.5.2.2
96
+ rubygems_version: 2.7.6
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: R18n for Rails