i18n_scope 0.1.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.
- data/Rakefile +101 -0
- data/lib/i18n/scope.rb +46 -0
- data/lib/i18n_scope.rb +1 -0
- metadata +69 -0
data/Rakefile
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test i18n scope.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for i18n scope.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'Currency'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
require "rubygems"
|
26
|
+
require "rake/gempackagetask"
|
27
|
+
require "rake/rdoctask"
|
28
|
+
|
29
|
+
require "rake/testtask"
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << "test"
|
32
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
33
|
+
t.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task :default => ["test"]
|
38
|
+
|
39
|
+
# This builds the actual gem. For details of what all these options
|
40
|
+
# mean, and other ones you can add, check the documentation here:
|
41
|
+
#
|
42
|
+
# http://rubygems.org/read/chapter/20
|
43
|
+
#
|
44
|
+
spec = Gem::Specification.new do |s|
|
45
|
+
|
46
|
+
# Change these as appropriate
|
47
|
+
s.name = "i18n_scope"
|
48
|
+
s.version = "0.1.0"
|
49
|
+
s.summary = "Magic scoping for I18n"
|
50
|
+
s.author = "Matthew Rudy Jacobs"
|
51
|
+
s.email = "MatthewRudyJacobs@gmail.com"
|
52
|
+
s.homepage = "http://github.com/matthewrudy/i18n_scope"
|
53
|
+
|
54
|
+
s.has_rdoc = true
|
55
|
+
# You should probably have a README of some kind. Change the filename
|
56
|
+
# as appropriate
|
57
|
+
# s.extra_rdoc_files = %w(README)
|
58
|
+
# s.rdoc_options = %w(--main README)
|
59
|
+
|
60
|
+
# Add any extra files to include in the gem (like your README)
|
61
|
+
s.files = %w(Rakefile) + Dir.glob("{test,lib/**/*}")
|
62
|
+
s.require_paths = ["lib"]
|
63
|
+
|
64
|
+
# If you want to depend on other gems, add them here, along with any
|
65
|
+
# relevant versions
|
66
|
+
# s.add_dependency("some_other_gem", "~> 0.1.0")
|
67
|
+
|
68
|
+
# If your tests use any gems, include them here
|
69
|
+
# s.add_development_dependency("mocha") # for example
|
70
|
+
end
|
71
|
+
|
72
|
+
# This task actually builds the gem. We also regenerate a static
|
73
|
+
# .gemspec file, which is useful if something (i.e. GitHub) will
|
74
|
+
# be automatically building a gem for this project. If you're not
|
75
|
+
# using GitHub, edit as appropriate.
|
76
|
+
#
|
77
|
+
# To publish your gem online, install the 'gemcutter' gem; Read more
|
78
|
+
# about that here: http://gemcutter.org/pages/gem_docs
|
79
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
80
|
+
pkg.gem_spec = spec
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "Build the gemspec file #{spec.name}.gemspec"
|
84
|
+
task :gemspec do
|
85
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
86
|
+
File.open(file, "w") {|f| f << spec.to_ruby }
|
87
|
+
end
|
88
|
+
|
89
|
+
task :package => :gemspec
|
90
|
+
|
91
|
+
# Generate documentation
|
92
|
+
Rake::RDocTask.new do |rd|
|
93
|
+
|
94
|
+
rd.rdoc_files.include("lib/**/*.rb")
|
95
|
+
rd.rdoc_dir = "rdoc"
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'Clear out RDoc and generated packages'
|
99
|
+
task :clean => [:clobber_rdoc, :clobber_package] do
|
100
|
+
rm "#{spec.name}.gemspec"
|
101
|
+
end
|
data/lib/i18n/scope.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
|
5
|
+
def self.scoped(scope=nil)
|
6
|
+
I18n::Scope.new(scope)
|
7
|
+
end
|
8
|
+
|
9
|
+
class Scope
|
10
|
+
|
11
|
+
def initialize(scope=[])
|
12
|
+
@scope = Array(scope)
|
13
|
+
end
|
14
|
+
attr_reader :scope
|
15
|
+
|
16
|
+
def method_missing(method_name, *args, &block)
|
17
|
+
# we only match something that looks like a key
|
18
|
+
if method_name.to_s =~ /^[A-Za-z0-9_]+$/
|
19
|
+
self.scoped(method_name)
|
20
|
+
else
|
21
|
+
super(method_name, *args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def t(value)
|
26
|
+
I18n.t(value, :scope => self.scope)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
I18n.t(translation_key)
|
31
|
+
end
|
32
|
+
|
33
|
+
def scoped(key)
|
34
|
+
next_scope = self.scope.dup
|
35
|
+
next_scope << key
|
36
|
+
I18n::Scope.new(next_scope)
|
37
|
+
end
|
38
|
+
|
39
|
+
def translation_key
|
40
|
+
self.scope.map{|s| s.to_s }.join(".")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
data/lib/i18n_scope.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'i18n/scope'
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_scope
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matthew Rudy Jacobs
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-27 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: MatthewRudyJacobs@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- lib/i18n/scope.rb
|
33
|
+
- lib/i18n_scope.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/matthewrudy/i18n_scope
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.7
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Magic scoping for I18n
|
68
|
+
test_files: []
|
69
|
+
|