i18n-bamboo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +10 -0
- data/i18n-bamboo.gemspec +43 -0
- data/lib/i18n/bamboo.rb +7 -0
- data/lib/i18n/bamboo/fertilizer.rb +47 -0
- data/lib/i18n/bamboo/railtie.rb +15 -0
- data/lib/i18n/bamboo/version.rb +5 -0
- data/spec/i18n/bamboo/fertilizer_spec.rb +84 -0
- data/spec/spec_helper.rb +5 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 718a1e74f23f15a2d61c93ec2d64e1498886e449
|
4
|
+
data.tar.gz: b0c9f59693db52570dee83cabe5177a606847043
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89dc2394aac2b9a67836426a39491f13823b551afd3e793211446f48e0dd9109b0fcc2e95e4b4fb2b57f374fb41b64361f892a86c165b9db49172d69a26f42db
|
7
|
+
data.tar.gz: f6a8e679dd15867f3abb84de49e2de8732c78f1b837744fd5878504f4cb688bfebe3f2be0cb146fd90cdc56d3a8d238fef5c8e8b9a309b429186498758218406
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tim Downey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# I18n::Bamboo
|
2
|
+
|
3
|
+
Consider the noble bamboo. This peculiar member of the Poaceae family has been known to grow to extraordinary lengths without yielding to (mostly) any obstacles.
|
4
|
+
|
5
|
+
Not unlike bamboo, the i18n translations of a Rails app will continue to grow. As a tenacious stalk of bamboo breaks through a slab of sidewalk, so too will long translations break a UI.
|
6
|
+
|
7
|
+
I18n:Bamboo monkey patches the Rails I18n module and will force all calls to I18n.translate (I18n.t) and I18n.localize (I18n.l) to return the longest translated or localized value from all available locales. For obvious reasons (monkey patching :cold_sweat:), this gem is intended to be used for development purposes only to aid in UI and internationalization/localization testing.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'i18n-bamboo'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install i18n-bamboo
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
### Automatic
|
25
|
+
Simply add the following line to your `config/environments/development.rb` file:
|
26
|
+
```ruby
|
27
|
+
# config/environments/development.rb
|
28
|
+
Rails.application.configure do
|
29
|
+
# ... previous config
|
30
|
+
config.i18n_bamboo.active = true
|
31
|
+
# further config ...
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Setting `config.i18n_bamboo.active` to `false` will disable the automatic initialization of the gem.
|
36
|
+
|
37
|
+
### Manual
|
38
|
+
If you want to use the gem temporarily in a pry session or something simply require the following:
|
39
|
+
```ruby
|
40
|
+
require 'i18n/bamboo/fertilizer'
|
41
|
+
```
|
42
|
+
**CAUTION:** Keep in mind that the fertilizer _does_ monkey patch the existing I18n module, so you will need to restart your console session/server to get the original I18n behavior back.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/tcdowney/i18n-bamboo/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
data/i18n-bamboo.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'i18n/bamboo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'i18n-bamboo'
|
8
|
+
spec.version = I18n::Bamboo::VERSION
|
9
|
+
spec.authors = ['Tim Downey']
|
10
|
+
spec.email = ['tim@downey.io']
|
11
|
+
spec.summary = %q{
|
12
|
+
Aids in development by monkey patching the Rails I18n module to always return the longest
|
13
|
+
translation or localized value across all available locales.
|
14
|
+
}
|
15
|
+
spec.description = %q{
|
16
|
+
Consider the noble bamboo. This peculiar member of the Poaceae family has been known to
|
17
|
+
grow to extraordinary lengths without yielding to (mostly) any obstacles.
|
18
|
+
|
19
|
+
Not unlike bamboo, the i18n translations of a Rails app will continue to grow. As a
|
20
|
+
tenacious stalk of bamboo breaks through a slab of sidewalk, so too will long translations
|
21
|
+
break a UI.
|
22
|
+
|
23
|
+
I18n:Bamboo monkey patches the Rails I18n module and will force all calls to I18n.translate
|
24
|
+
(I18n.t) and I18n.localize (I18n.l) to return the longest translated or localized value from
|
25
|
+
all available_locales. For obvious reasons, this gem is intended to be used for development
|
26
|
+
purposes only to aid in UI and internationalization/localization testing.
|
27
|
+
}
|
28
|
+
spec.homepage = 'https://github.com/tcdowney/i18n-bamboo'
|
29
|
+
spec.license = 'MIT'
|
30
|
+
|
31
|
+
spec.files = `git ls-files -z`.split("\x0")
|
32
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
33
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
34
|
+
spec.require_paths = ['lib']
|
35
|
+
|
36
|
+
spec.add_dependency 'i18n'
|
37
|
+
|
38
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
39
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
40
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 0.27.1'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
43
|
+
end
|
data/lib/i18n/bamboo.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module Bamboo
|
5
|
+
module Fertilizer
|
6
|
+
module ::I18n
|
7
|
+
class << self
|
8
|
+
alias_method :original_translate, :translate
|
9
|
+
alias_method :original_localize, :localize
|
10
|
+
|
11
|
+
def translate(*args)
|
12
|
+
translations = []
|
13
|
+
|
14
|
+
available_locales.each do |locale|
|
15
|
+
args_copy = args.dup
|
16
|
+
|
17
|
+
if args_copy.last.is_a? Hash
|
18
|
+
args_copy.last.merge!(locale: locale)
|
19
|
+
else
|
20
|
+
args_copy << {locale: locale}
|
21
|
+
end
|
22
|
+
|
23
|
+
translations << original_translate(*args_copy)
|
24
|
+
end
|
25
|
+
|
26
|
+
translations.max
|
27
|
+
end
|
28
|
+
|
29
|
+
def localize(object, options = {})
|
30
|
+
localized_values = []
|
31
|
+
|
32
|
+
available_locales.each do |locale|
|
33
|
+
options_copy = options.merge(locale: locale)
|
34
|
+
|
35
|
+
localized_values << original_localize(object, options_copy)
|
36
|
+
end
|
37
|
+
|
38
|
+
localized_values.max
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method :t, :translate
|
42
|
+
alias_method :l, :localize
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module Bamboo
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
|
7
|
+
config.i18n_bamboo = ActiveSupport::OrderedOptions.new
|
8
|
+
|
9
|
+
config.after_initialize do
|
10
|
+
require 'i18n/bamboo/fertilizer' if config.i18n_bamboo.active
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'i18n/bamboo/fertilizer'
|
3
|
+
|
4
|
+
RSpec.describe 'I18n monkey patching' do
|
5
|
+
let(:available_locales) { [:en, :zh] }
|
6
|
+
|
7
|
+
let(:time) { Time.new(2014) }
|
8
|
+
let(:long_time) { '2014-01-01' }
|
9
|
+
let(:short_time) { '2014' }
|
10
|
+
|
11
|
+
let(:key) { 'key' }
|
12
|
+
let(:long_translation) { 'Something very long!' }
|
13
|
+
let(:short_translation) { 'Not as long.' }
|
14
|
+
|
15
|
+
before do
|
16
|
+
I18n.enforce_available_locales = false
|
17
|
+
I18n.default_locale = :en # English will always have the shortest translations for the sake of these tests
|
18
|
+
allow(I18n).to receive(:available_locales).and_return(available_locales)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#translate' do
|
22
|
+
before do
|
23
|
+
expect(I18n).to receive(:original_translate)
|
24
|
+
.with(key, {locale: :en})
|
25
|
+
.and_return(short_translation)
|
26
|
+
|
27
|
+
expect(I18n).to receive(:original_translate)
|
28
|
+
.with(key, {locale: :zh})
|
29
|
+
.and_return(long_translation)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the longest translation' do
|
33
|
+
expect(I18n.translate(key)).to eq(long_translation)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#t' do
|
38
|
+
before do
|
39
|
+
expect(I18n).to receive(:original_translate)
|
40
|
+
.with(key, {locale: :en})
|
41
|
+
.and_return(short_translation)
|
42
|
+
|
43
|
+
expect(I18n).to receive(:original_translate)
|
44
|
+
.with(key, {locale: :zh})
|
45
|
+
.and_return(long_translation)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns the longest translation' do
|
49
|
+
expect(I18n.t(key)).to eq(long_translation)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#localize' do
|
54
|
+
before do
|
55
|
+
expect(I18n).to receive(:original_localize)
|
56
|
+
.with(time, {locale: :en})
|
57
|
+
.and_return(short_time)
|
58
|
+
|
59
|
+
expect(I18n).to receive(:original_localize)
|
60
|
+
.with(time, {locale: :zh})
|
61
|
+
.and_return(long_time)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns the longest translation' do
|
65
|
+
expect(I18n.localize(time)).to eq(long_time)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#l' do
|
70
|
+
before do
|
71
|
+
expect(I18n).to receive(:original_localize)
|
72
|
+
.with(time, {locale: :en})
|
73
|
+
.and_return(short_time)
|
74
|
+
|
75
|
+
expect(I18n).to receive(:original_localize)
|
76
|
+
.with(time, {locale: :zh})
|
77
|
+
.and_return(long_time)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns the longest translation' do
|
81
|
+
expect(I18n.l(time)).to eq(long_time)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-bamboo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Downey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.27.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.27.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.1.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.1.0
|
97
|
+
description: "\n Consider the noble bamboo. This peculiar
|
98
|
+
member of the Poaceae family has been known to \n grow
|
99
|
+
to extraordinary lengths without yielding to (mostly) any obstacles.\n\n Not
|
100
|
+
unlike bamboo, the i18n translations of a Rails app will continue to grow. As a
|
101
|
+
\n tenacious stalk of bamboo breaks through a slab of sidewalk,
|
102
|
+
so too will long translations \n break a UI.\n\n I18n:Bamboo
|
103
|
+
monkey patches the Rails I18n module and will force all calls to I18n.translate
|
104
|
+
\n (I18n.t) and I18n.localize (I18n.l) to return the longest
|
105
|
+
translated or localized value from \n all available_locales.
|
106
|
+
\ For obvious reasons, this gem is intended to be used for development \n purposes
|
107
|
+
only to aid in UI and internationalization/localization testing.\n "
|
108
|
+
email:
|
109
|
+
- tim@downey.io
|
110
|
+
executables: []
|
111
|
+
extensions: []
|
112
|
+
extra_rdoc_files: []
|
113
|
+
files:
|
114
|
+
- ".gitignore"
|
115
|
+
- Gemfile
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- i18n-bamboo.gemspec
|
120
|
+
- lib/i18n/bamboo.rb
|
121
|
+
- lib/i18n/bamboo/fertilizer.rb
|
122
|
+
- lib/i18n/bamboo/railtie.rb
|
123
|
+
- lib/i18n/bamboo/version.rb
|
124
|
+
- spec/i18n/bamboo/fertilizer_spec.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
homepage: https://github.com/tcdowney/i18n-bamboo
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.2.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Aids in development by monkey patching the Rails I18n module to always return
|
150
|
+
the longest translation or localized value across all available locales.
|
151
|
+
test_files:
|
152
|
+
- spec/i18n/bamboo/fertilizer_spec.rb
|
153
|
+
- spec/spec_helper.rb
|