g11n 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -3
- data/features/domain_specific_language.feature +2 -0
- data/features/stepdefs/domain_specific_language/setup_the_translations_path_the_locale_and_get_a_translation.rb +1 -1
- data/features/stepdefs/get_a_translation/simple_example_and_simple_translation.rb +2 -2
- data/lib/g11n/configuration.rb +3 -2
- data/lib/g11n/translator.rb +5 -0
- data/lib/g11n/version.rb +1 -1
- data/spec/g11n/translator_spec.rb +6 -0
- metadata +4 -9
data/README.md
CHANGED
@@ -74,14 +74,35 @@ G11n.t.home.land # => "Российская Федер
|
|
74
74
|
|
75
75
|
Also, the `G11n::DSL` module can be included in any object of class you want to use the `#t` method more confortably.
|
76
76
|
|
77
|
-
|
77
|
+
## Use it in Sinatra
|
78
|
+
The G11n DSL (the `#t` and `#translate` methods) are available as a module unimaginatively called `G11n::DSL`. You can of course include it into your helpers as easy as:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# .app.rb
|
82
|
+
require 'sinatra'
|
83
|
+
require 'g11n'
|
84
|
+
|
85
|
+
helpers G11n::DSL
|
86
|
+
|
87
|
+
G11n.locale :es
|
88
|
+
|
89
|
+
get '/' do
|
90
|
+
t.welcome # => "¡Bienvenido, amigo!"
|
91
|
+
# as described in es.yaml
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
```yaml
|
96
|
+
# .translations/es.yaml
|
97
|
+
welcome: ¡Bienvenido, amigo!
|
98
|
+
```
|
99
|
+
|
100
|
+
It works in modular style too.
|
78
101
|
|
79
102
|
## Testing
|
80
103
|
|
81
104
|
Cucumber features and RSpec specs are provided to check functionality.
|
82
105
|
|
83
|
-
An exception is the G11n::Dictionary class, which is just a subclass of SymbolTable that recursively converts all hashes passed as argument to the initializer into Dictionaries. This is really handy.
|
84
|
-
|
85
106
|
## License
|
86
107
|
|
87
108
|
Copyright (C) 2012 Fetcher
|
@@ -24,7 +24,7 @@ end
|
|
24
24
|
And /^I run "(.*?)" on the :(\w+) method$/ do |argument, message|
|
25
25
|
o = Object.new
|
26
26
|
o.extend G11n::DSL
|
27
|
-
@
|
27
|
+
@result = eval "o.#{message}.#{argument}"
|
28
28
|
end
|
29
29
|
|
30
30
|
When /^I send :(\w+) to the configuration DSL$/ do |message|
|
@@ -16,9 +16,9 @@ When /^I have the locale setted as "(.*?)"$/ do |locale|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
And /^I write "(.*?)" in the translation engine$/ do |identifier|
|
19
|
-
@
|
19
|
+
@result = eval "G11n::Translator.instance.translate.#{identifier}"
|
20
20
|
end
|
21
21
|
|
22
22
|
Then /^I should see "(.*?)"$/ do |text|
|
23
|
-
@
|
23
|
+
@result.should == text
|
24
24
|
end
|
data/lib/g11n/configuration.rb
CHANGED
@@ -2,8 +2,9 @@ module G11n
|
|
2
2
|
# DSL for the configuration of G11n
|
3
3
|
module Configuration
|
4
4
|
# Sets the translations path
|
5
|
-
def path the_path
|
6
|
-
Translator.instance.translations_path = the_path + "/"
|
5
|
+
def path the_path = nil
|
6
|
+
Translator.instance.translations_path = the_path + "/" if the_path
|
7
|
+
Translator.instance.translations_path
|
7
8
|
end
|
8
9
|
|
9
10
|
# Sets or get the locale
|
data/lib/g11n/translator.rb
CHANGED
@@ -24,6 +24,11 @@ module G11n
|
|
24
24
|
def translations_path= the_path
|
25
25
|
@translations_path = the_path
|
26
26
|
end
|
27
|
+
|
28
|
+
# @return [String] the current path to translations
|
29
|
+
def translations_path
|
30
|
+
@translations_path
|
31
|
+
end
|
27
32
|
|
28
33
|
# Forwards the method call to the right "dictionary" (a SymbolTable object)
|
29
34
|
# http://mjijackson.com/2010/04/config-revisited
|
data/lib/g11n/version.rb
CHANGED
@@ -62,6 +62,12 @@ describe G11n::Translator do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "#translations_path" do
|
66
|
+
it "should return the translations path" do
|
67
|
+
G11n::Translator.instance.translations_path.should == "translations/"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
65
71
|
describe "#dictionary_for" do
|
66
72
|
context "there is in fact a dictionary for the locale" do
|
67
73
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: g11n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: symbolmatrix
|
@@ -130,21 +130,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- - ! '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: 686192047
|
136
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
134
|
none: false
|
138
135
|
requirements:
|
139
136
|
- - ! '>='
|
140
137
|
- !ruby/object:Gem::Version
|
141
138
|
version: '0'
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
hash: 686192047
|
145
139
|
requirements: []
|
146
140
|
rubyforge_project:
|
147
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.21
|
148
142
|
signing_key:
|
149
143
|
specification_version: 3
|
150
144
|
summary: Internationalization library focused in simplicity of implementation
|
@@ -156,3 +150,4 @@ test_files:
|
|
156
150
|
- features/support/env.rb
|
157
151
|
- features/support/hooks.rb
|
158
152
|
- spec/g11n/translator_spec.rb
|
153
|
+
has_rdoc:
|