sinatra-r18n 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 +5 -5
- data/.rspec +1 -1
- data/README.md +1 -1
- data/Rakefile +5 -3
- data/lib/sinatra/r18n.rb +25 -23
- data/sinatra-r18n.gemspec +6 -4
- data/spec/app/app.rb +4 -2
- data/spec/sinatra-r18n_spec.rb +22 -22
- data/spec/spec_helper.rb +7 -2
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d3c2992234343118814eef964dbc36ecc55acccc76505b2808abf4e31e3091c
|
4
|
+
data.tar.gz: 424ba607babdf58467c73bc70e8a077b050485635620e967be5d4c67c7319f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab53364047a6d1a10153256094eda43ecdbbf1d8680e7258d876bfd1e99c7346fbfb302834e76d6d3fa014dd400deb5d87390708255d3b3d0bc129d6dd1c3d6
|
7
|
+
data.tar.gz: 0fd56d9c6a3ec7f5f2757075e9e546ef2e4255d82521ac0ce1f5ede75f963bff4cbb5ae4cec5dde292a971d3f0ce7e0653ef2302c07feff6f8bc8d872253d64e
|
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--format documentation --colour
|
1
|
+
--format documentation --colour --warnings --require spec_helper
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
4
6
|
require 'rspec/core/rake_task'
|
5
7
|
RSpec::Core::RakeTask.new
|
6
|
-
task :
|
8
|
+
task default: :spec
|
7
9
|
|
8
10
|
task :clobber_package do
|
9
|
-
|
11
|
+
rm_rf 'pkg'
|
10
12
|
end
|
11
|
-
task :
|
13
|
+
task clobber: [:clobber_package]
|
data/lib/sinatra/r18n.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
|
+
# Sinatra extension to i18n support.
|
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 'sinatra/base'
|
21
21
|
require 'r18n-core'
|
@@ -24,10 +24,10 @@ module Sinatra
|
|
24
24
|
module R18n
|
25
25
|
def self.registered(app)
|
26
26
|
app.helpers ::R18n::Helpers
|
27
|
-
app.set :default_locale,
|
28
|
-
app.set :translations,
|
27
|
+
app.set :default_locale, (proc { ::R18n::I18n.default })
|
28
|
+
app.set :translations, (proc { ::R18n.default_places })
|
29
29
|
|
30
|
-
::R18n.default_places { File.join(app.root, 'i18n
|
30
|
+
::R18n.default_places { File.join(app.root, 'i18n') }
|
31
31
|
|
32
32
|
app.before do
|
33
33
|
::R18n.clear_cache! if self.class.development?
|
@@ -44,8 +44,10 @@ module Sinatra
|
|
44
44
|
locales.insert(0, session[:locale])
|
45
45
|
end
|
46
46
|
|
47
|
-
::R18n::I18n.new(
|
48
|
-
|
47
|
+
::R18n::I18n.new(
|
48
|
+
locales, ::R18n.default_places,
|
49
|
+
off_filters: :untranslated, on_filters: :untranslated_html
|
50
|
+
)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/sinatra-r18n.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 = 'A Sinatra extension that provides i18n support'
|
10
|
-
s.description = <<-
|
12
|
+
s.description = <<-DESC
|
11
13
|
A Sinatra extension that provides i18n support to translate your web
|
12
14
|
application. It is just a wrapper for R18n core library.
|
13
15
|
It 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")
|
@@ -26,6 +28,6 @@ Gem::Specification.new do |s|
|
|
26
28
|
s.homepage = 'https://github.com/ai/r18n/tree/master/sinatra-r18n'
|
27
29
|
s.license = 'LGPL-3'
|
28
30
|
|
29
|
-
s.add_dependency 'sinatra', ">= 1.3"
|
30
31
|
s.add_dependency 'r18n-core', "= #{R18n::VERSION}"
|
32
|
+
s.add_dependency 'sinatra', '>= 1.3'
|
31
33
|
end
|
data/spec/app/app.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../lib/sinatra/r18n'
|
2
4
|
require 'sinatra'
|
3
5
|
|
4
6
|
get '/:locale/posts/:name' do
|
@@ -31,5 +33,5 @@ get '/warning' do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
get '/untranslated' do
|
34
|
-
|
36
|
+
t.post.no.to_s
|
35
37
|
end
|
data/spec/sinatra-r18n_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe Sinatra::R18n do
|
4
4
|
before(:all) do
|
@@ -10,81 +10,81 @@ describe Sinatra::R18n do
|
|
10
10
|
app.set :environment, :test
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'translates messages' do
|
14
14
|
get '/en/posts/1'
|
15
15
|
expect(last_response).to be_ok
|
16
16
|
expect(last_response.body).to eq "<h1>Post 1</h1>\n"
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'uses translations from default locale' do
|
20
20
|
get '/ru/posts/1/comments'
|
21
21
|
expect(last_response).to be_ok
|
22
22
|
expect(last_response.body).to eq '3 comments'
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'uses default locale' do
|
26
26
|
app.set :default_locale, 'ru'
|
27
27
|
get '/locale'
|
28
28
|
expect(last_response).to be_ok
|
29
29
|
expect(last_response.body).to eq 'Русский'
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
get '/locale', {
|
32
|
+
it 'autodetects user locale' do
|
33
|
+
get '/locale', {}, 'HTTP_ACCEPT_LANGUAGE' => 'ru,en;q=0.9'
|
34
34
|
expect(last_response).to be_ok
|
35
35
|
expect(last_response.body).to eq 'Русский'
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
get '/locale',
|
38
|
+
it 'uses locale from param' do
|
39
|
+
get '/locale', locale: 'ru'
|
40
40
|
expect(last_response).to be_ok
|
41
41
|
expect(last_response.body).to eq 'Русский'
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
45
|
-
get '/locale',
|
44
|
+
it 'ignore empty param' do
|
45
|
+
get '/locale', locale: ''
|
46
46
|
expect(last_response).to be_ok
|
47
47
|
expect(last_response.body).to eq 'English'
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
get '/locale', {
|
50
|
+
it 'uses locale from session' do
|
51
|
+
get '/locale', {}, 'rack.session' => { locale: 'ru' }
|
52
52
|
expect(last_response).to be_ok
|
53
53
|
expect(last_response.body).to eq 'Русский'
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
57
|
-
get '/locale', {
|
56
|
+
it 'ignore empty session' do
|
57
|
+
get '/locale', {}, 'rack.session' => { locale: '' }
|
58
58
|
expect(last_response).to be_ok
|
59
59
|
expect(last_response.body).to eq 'English'
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
get '/locale', {
|
62
|
+
it 'ignores empty locale' do
|
63
|
+
get '/locale', {}
|
64
64
|
expect(last_response).to be_ok
|
65
65
|
expect(last_response.body).to eq 'English'
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'returns locales list' do
|
69
69
|
get '/locales'
|
70
70
|
expect(last_response).to be_ok
|
71
71
|
expect(last_response.body).to eq 'en: English; ru: Русский'
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it 'formats untranslated string' do
|
75
75
|
get '/untranslated'
|
76
76
|
expect(last_response).to be_ok
|
77
77
|
expect(last_response.body).to eq 'post.<span style="color: red">[no]</span>'
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
80
|
+
it 'localizes objects' do
|
81
81
|
get '/time'
|
82
82
|
expect(last_response).to be_ok
|
83
|
-
expect(last_response.body).to eq
|
83
|
+
expect(last_response.body).to eq '1970-01-01 00:00'
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
87
|
-
path =
|
86
|
+
it 'sets default places' do
|
87
|
+
path = File.join(__dir__, 'app', 'i18n')
|
88
88
|
expect(R18n.default_places).to eq path
|
89
89
|
R18n.set('en')
|
90
90
|
expect(R18n.get.post.title(1)).to eq 'Post 1'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pp'
|
2
4
|
|
3
5
|
ENV['RACK_ENV'] = 'test'
|
4
|
-
|
6
|
+
require_relative 'app/app'
|
5
7
|
|
6
8
|
require 'rack/test'
|
7
9
|
|
8
10
|
module RSpecMixinExample
|
9
11
|
include Rack::Test::Methods
|
10
|
-
|
12
|
+
|
13
|
+
def app
|
14
|
+
Sinatra::Application
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
RSpec.configure { |c| c.include RSpecMixinExample }
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-r18n
|
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
|
-
name:
|
14
|
+
name: r18n-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
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
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sinatra
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '1.3'
|
41
41
|
description: |2
|
42
42
|
A Sinatra extension that provides i18n support to translate your web
|
43
43
|
application. It is just a wrapper for R18n core library.
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.7.6
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
90
|
summary: A Sinatra extension that provides i18n support
|