i18n_namespace 0.0.1
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.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/i18n_namespace.gemspec +77 -0
- data/lib/i18n_namespace/config.rb +48 -0
- data/lib/i18n_namespace/fallbacks.rb +31 -0
- data/lib/i18n_namespace/helper.rb +11 -0
- data/lib/i18n_namespace/key_value.rb +18 -0
- data/lib/i18n_namespace/storing.rb +16 -0
- data/lib/i18n_namespace.rb +11 -0
- data/spec/lib/i18n_namespace_spec.rb +188 -0
- data/test/helper.rb +18 -0
- data/test/test_i18n_namespace.rb +7 -0
- metadata +155 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
active_support (3.0.0)
|
5
|
+
activesupport (= 3.0.0)
|
6
|
+
activesupport (3.0.0)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
git (1.2.5)
|
9
|
+
i18n (0.6.0)
|
10
|
+
jeweler (1.6.4)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
rake (0.9.2.2)
|
15
|
+
rcov (0.9.11)
|
16
|
+
rspec (2.6.0)
|
17
|
+
rspec-core (~> 2.6.0)
|
18
|
+
rspec-expectations (~> 2.6.0)
|
19
|
+
rspec-mocks (~> 2.6.0)
|
20
|
+
rspec-core (2.6.4)
|
21
|
+
rspec-expectations (2.6.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.6.0)
|
24
|
+
shoulda (2.11.3)
|
25
|
+
yajl-ruby (1.1.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
active_support
|
32
|
+
bundler (~> 1.0.0)
|
33
|
+
i18n
|
34
|
+
jeweler (~> 1.6.4)
|
35
|
+
rcov
|
36
|
+
rspec
|
37
|
+
shoulda
|
38
|
+
yajl-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Matthias Zirnstein
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= i18n_namespace
|
2
|
+
|
3
|
+
I18n.namespace = :administrator
|
4
|
+
|
5
|
+
# with a namespace set, these are the lookup keys
|
6
|
+
# administrator.home.index.content
|
7
|
+
# home.index.content
|
8
|
+
t('home.index.content')
|
9
|
+
|
10
|
+
# your namespace can an array too
|
11
|
+
I18n.namespace = [:administrator, :special_club]
|
12
|
+
|
13
|
+
# administrator.special_club.home.index.content
|
14
|
+
# administrator.home.index.content
|
15
|
+
# home.index.content
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "i18n_namespace"
|
18
|
+
gem.homepage = "http://github.com/avarteqgmbh/i18n_namespace"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{I18n key injection}
|
21
|
+
gem.description = %Q{I18n key injection with fallback functionality}
|
22
|
+
gem.email = "matthias.zirnstein@googlemail.com"
|
23
|
+
gem.authors = ["Matthias Zirnstein"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "i18n_namespace #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "i18n_namespace"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthias Zirnstein"]
|
12
|
+
s.date = "2012-01-11"
|
13
|
+
s.description = "I18n key injection with fallback functionality"
|
14
|
+
s.email = "matthias.zirnstein@googlemail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"i18n_namespace.gemspec",
|
28
|
+
"lib/i18n_namespace.rb",
|
29
|
+
"lib/i18n_namespace/config.rb",
|
30
|
+
"lib/i18n_namespace/fallbacks.rb",
|
31
|
+
"lib/i18n_namespace/helper.rb",
|
32
|
+
"lib/i18n_namespace/key_value.rb",
|
33
|
+
"lib/i18n_namespace/storing.rb",
|
34
|
+
"spec/lib/i18n_namespace_spec.rb",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_i18n_namespace.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/avarteqgmbh/i18n_namespace"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.10"
|
42
|
+
s.summary = "I18n key injection"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<active_support>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
54
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
58
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
59
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
68
|
+
s.add_dependency(%q<yajl-ruby>, [">= 0"])
|
69
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
70
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
73
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module I18nNamespace
|
2
|
+
module I18n
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
# TODO: fix this, its absolute
|
10
|
+
::I18n::RESERVED_KEYS << :namespaced
|
11
|
+
|
12
|
+
def namespace
|
13
|
+
config.namespace
|
14
|
+
end
|
15
|
+
|
16
|
+
def namespace=(ns)
|
17
|
+
raise "Namespace contains unsupported objects. Allowed are: String, Symbol, Array[Symbol, String] or NilClass. Inspection: #{ns.inspect}" unless valid_namespace?(ns)
|
18
|
+
config.namespace = ns
|
19
|
+
end
|
20
|
+
|
21
|
+
def store_resolved_translation(locale, key, value, options = {})
|
22
|
+
raise "Key has to be a String" unless key.is_a? String
|
23
|
+
raise "Value has to be a String or NilClass" if !value.is_a?(String) && !value.is_a?(NilClass)
|
24
|
+
|
25
|
+
resolved = key.split('.').reverse.inject(value) {|a, n| {n => a}}
|
26
|
+
|
27
|
+
backend.store_translations locale, resolved, options
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
# TODO: fix this complicated logic :)
|
32
|
+
def valid_namespace?(ns)
|
33
|
+
return true if [String, Symbol, NilClass].include?(ns.class)
|
34
|
+
return false unless ns.is_a?(Array)
|
35
|
+
|
36
|
+
# check array for invalid objects
|
37
|
+
return false if ns.select(&:blank?).present?
|
38
|
+
return false if ns.select{|o| ![String, Symbol].include?(o.class)}.present?
|
39
|
+
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Config
|
46
|
+
attr_accessor :namespace
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module I18nNamespace
|
2
|
+
|
3
|
+
module Fallbacks
|
4
|
+
include I18nNamespace::Helper
|
5
|
+
|
6
|
+
def translate(locale, key, options = {})
|
7
|
+
namespaced = options.fetch(:namespaced, false)
|
8
|
+
|
9
|
+
return super if !namespaced || ::I18n.namespace.blank?
|
10
|
+
# TODO: accept default, look for i18n/backend/fallback for a solution
|
11
|
+
# default = extract_string_or_lambda_default!(options) if options[:default]
|
12
|
+
|
13
|
+
scope = to_a(options.delete(:scope))
|
14
|
+
namespace = to_a(::I18n.namespace)
|
15
|
+
|
16
|
+
(namespace.size + 1).times do |part|
|
17
|
+
catch(:exception) do
|
18
|
+
options[:scope] = (namespace | scope).reject(&:nil?)
|
19
|
+
|
20
|
+
result = super(locale, key, options)
|
21
|
+
return result unless result.nil?
|
22
|
+
end
|
23
|
+
namespace.pop
|
24
|
+
end
|
25
|
+
|
26
|
+
# return super(locale, nil, options.merge(:default => default)) if default
|
27
|
+
throw(:exception, ::I18n::MissingTranslation.new(locale, key, options))
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module I18nNamespace
|
2
|
+
class KeyValue
|
3
|
+
def self.include(base)
|
4
|
+
raise "You can't include I18n::Backends::Fallbacks in this class." if base == ::I18n::Backend::Fallbacks
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.extend(base)
|
9
|
+
raise "You can't extend this class with I18n::Backends::Fallbacks." if base == ::I18n::Backend::Fallbacks
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
include ::I18n::Backend::KeyValue::Implementation
|
14
|
+
include Fallbacks
|
15
|
+
include Storing
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module I18nNamespace
|
2
|
+
module Storing
|
3
|
+
include I18nNamespace::Helper
|
4
|
+
|
5
|
+
def store_translations(locale, data, options = {})
|
6
|
+
# TODO: use delete instead of fetch
|
7
|
+
namespaced = options.fetch(:namespaced, false)
|
8
|
+
|
9
|
+
if namespaced && ::I18n.namespace.present?
|
10
|
+
data = to_a(::I18n.namespace).reverse.inject(data) {|a, n| {n => a}}
|
11
|
+
end
|
12
|
+
|
13
|
+
super locale, data, options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require 'i18n_namespace/config'
|
3
|
+
require 'i18n_namespace/helper'
|
4
|
+
require 'i18n_namespace/storing'
|
5
|
+
require 'i18n_namespace/fallbacks'
|
6
|
+
require 'i18n_namespace/key_value'
|
7
|
+
|
8
|
+
I18n.send :include, I18nNamespace::I18n
|
9
|
+
I18n::Config.send :include, I18nNamespace::Config
|
10
|
+
|
11
|
+
raise "Please require 'yajl/json_gem' for proper use. Without causing Json decoding errors when accessing the backend." unless defined?(Yajl) && defined?(JSON)
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'yajl/json_gem'
|
2
|
+
require 'rspec'
|
3
|
+
require 'i18n'
|
4
|
+
require 'i18n_namespace'
|
5
|
+
require 'active_support/core_ext/hash'
|
6
|
+
|
7
|
+
describe 'I18n' do
|
8
|
+
before(:all) do
|
9
|
+
@i18n_backend_saved = I18n.backend
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
I18n.backend = @i18n_backend_saved
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_new_backend
|
17
|
+
I18n.backend = I18nNamespace::KeyValue.new({})
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'with backend chain' do
|
21
|
+
before(:each) do
|
22
|
+
I18n.backend = I18n::Backend::Simple.new
|
23
|
+
I18n.backend.store_translations I18n.locale, {:foo => {:bar => {:title => 'foo bar'}}}, :escape => false
|
24
|
+
|
25
|
+
I18n.backend = I18n::Backend::Chain.new(I18nNamespace::KeyValue.new({}), I18n.backend)
|
26
|
+
I18n.backend.store_translations I18n.locale, {:title => 'Willkommen'}, :escape => false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should fallback with the backend chain' do
|
30
|
+
I18n.t('foo.bar.title').should == 'foo bar'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'storing' do
|
35
|
+
before(:each) do
|
36
|
+
set_new_backend
|
37
|
+
end
|
38
|
+
|
39
|
+
def t(key, options = {})
|
40
|
+
options.reverse_merge!(:namespaced => false)
|
41
|
+
I18n.t key, options
|
42
|
+
end
|
43
|
+
|
44
|
+
def s(data, options = {})
|
45
|
+
options.reverse_merge!(:namespaced => true, :escape => false)
|
46
|
+
|
47
|
+
I18n.backend.store_translations I18n.locale, data, options
|
48
|
+
end
|
49
|
+
|
50
|
+
def sr(key, value)
|
51
|
+
I18n.store_resolved_translation I18n.locale, key, value, :escape => false, :namespaced => true
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
it 'should resolve dot separated key to hash' do
|
56
|
+
sr('foo.bar.title', 'FooBar')
|
57
|
+
t('foo.bar.title').should == 'FooBar'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should save with namespace' do
|
61
|
+
I18n.namespace = :salesman
|
62
|
+
|
63
|
+
s('title' => 'Willkommen')
|
64
|
+
t('salesman.title').should == 'Willkommen'
|
65
|
+
|
66
|
+
I18n.namespace = [ :salesman, :club ]
|
67
|
+
|
68
|
+
s('title' => 'Willkommen')
|
69
|
+
t('salesman.club.title').should == 'Willkommen'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should not save with namespace' do
|
73
|
+
options = { :namespaced => false }
|
74
|
+
|
75
|
+
I18n.namespace = :salesman
|
76
|
+
|
77
|
+
s({'title' => 'Willkommen'}, options)
|
78
|
+
t('salesman.title').should include('translation missing')
|
79
|
+
|
80
|
+
I18n.namespace = [:salesman, :club]
|
81
|
+
|
82
|
+
s({'title' => 'Willkommen'}, options)
|
83
|
+
t('salesman.club.title').should include('translation missing')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'validation' do
|
88
|
+
it 'should raise if namespace array includes none supported objects' do
|
89
|
+
lambda { I18n.namespace = [ :salesman, nil ] }.should raise_error
|
90
|
+
lambda { I18n.namespace = [ :salesman, "" ] }.should raise_error
|
91
|
+
|
92
|
+
lambda { I18n.namespace = [ :salesman, Proc.new{} ] }.should raise_error
|
93
|
+
lambda { I18n.namespace = [ :salesman, Array.new ] }.should raise_error
|
94
|
+
lambda { I18n.namespace = [ :salesman, Hash.new ] }.should raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should only accept String, Symbol, Array or NilClass' do
|
98
|
+
I18n.namespace = :symbol
|
99
|
+
I18n.namespace.should == :symbol
|
100
|
+
|
101
|
+
I18n.namespace = "string"
|
102
|
+
I18n.namespace.should == "string"
|
103
|
+
|
104
|
+
I18n.namespace = nil
|
105
|
+
I18n.namespace.should == nil
|
106
|
+
|
107
|
+
I18n.namespace = []
|
108
|
+
I18n.namespace.should == []
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'namespace fallbacks' do
|
113
|
+
before(:each) do
|
114
|
+
set_new_backend
|
115
|
+
|
116
|
+
@salesman_title = 'Willkommen Salesman'
|
117
|
+
@club_title = 'Willkommen im Club'
|
118
|
+
@title = 'Willkommen'
|
119
|
+
|
120
|
+
store_translations(
|
121
|
+
{ :title => @title,
|
122
|
+
:salesman => { :title => @salesman_title,
|
123
|
+
:club => { :title => @club_title }
|
124
|
+
}
|
125
|
+
})
|
126
|
+
end
|
127
|
+
|
128
|
+
def store_translations(*args)
|
129
|
+
case args.count
|
130
|
+
when 1
|
131
|
+
raise "Your argument isn't a Hash" unless args.first.is_a? Hash
|
132
|
+
data = args.shift
|
133
|
+
when 2
|
134
|
+
data = { args.shift => args.shift }
|
135
|
+
end
|
136
|
+
|
137
|
+
I18n.backend.store_translations I18n.locale, data
|
138
|
+
end
|
139
|
+
|
140
|
+
def t(key, options = {})
|
141
|
+
options.reverse_merge!(:namespaced => true)
|
142
|
+
|
143
|
+
I18n.t key, options
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'with no namespace' do
|
147
|
+
before(:each) do
|
148
|
+
I18n.namespace = nil
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should return title' do
|
152
|
+
t('title').should == @title
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should show translation missing' do
|
156
|
+
t('foobar').should include('translation missing:')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'with namespace' do
|
161
|
+
before(:each) do
|
162
|
+
I18n.namespace = :salesman
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should not fallback' do
|
166
|
+
I18n.namespace = :salesman
|
167
|
+
t('title').should == @salesman_title
|
168
|
+
|
169
|
+
I18n.namespace = [:salesman, :club]
|
170
|
+
t('title').should == @club_title
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'should fallback' do
|
174
|
+
I18n.namespace = [:salesman, :user]
|
175
|
+
t('title').should == @salesman_title
|
176
|
+
|
177
|
+
I18n.namespace = [:community, :user, '23051949']
|
178
|
+
t('title').should == @title
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should show translation missing' do
|
182
|
+
t('foobar').should include('translation missing')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'i18n_namespace'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_namespace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthias Zirnstein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: &70287162048300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70287162048300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yajl-ruby
|
27
|
+
requirement: &70287162046920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70287162046920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: active_support
|
38
|
+
requirement: &70287162046200 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70287162046200
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: shoulda
|
49
|
+
requirement: &70287162039100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70287162039100
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &70287162036740 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70287162036740
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: &70287162033180 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.6.4
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70287162033180
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rcov
|
82
|
+
requirement: &70287162024740 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70287162024740
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rspec
|
93
|
+
requirement: &70287162023100 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70287162023100
|
102
|
+
description: I18n key injection with fallback functionality
|
103
|
+
email: matthias.zirnstein@googlemail.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.rdoc
|
109
|
+
files:
|
110
|
+
- .document
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.rdoc
|
115
|
+
- Rakefile
|
116
|
+
- VERSION
|
117
|
+
- i18n_namespace.gemspec
|
118
|
+
- lib/i18n_namespace.rb
|
119
|
+
- lib/i18n_namespace/config.rb
|
120
|
+
- lib/i18n_namespace/fallbacks.rb
|
121
|
+
- lib/i18n_namespace/helper.rb
|
122
|
+
- lib/i18n_namespace/key_value.rb
|
123
|
+
- lib/i18n_namespace/storing.rb
|
124
|
+
- spec/lib/i18n_namespace_spec.rb
|
125
|
+
- test/helper.rb
|
126
|
+
- test/test_i18n_namespace.rb
|
127
|
+
homepage: http://github.com/avarteqgmbh/i18n_namespace
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ! '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
hash: 2288591149329551058
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.8.10
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: I18n key injection
|
155
|
+
test_files: []
|