matta-globalite 0.5.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/README +199 -0
- data/lang/rails/de-DE.yml +357 -0
- data/lang/rails/en-UK.yml +357 -0
- data/lang/rails/en-US.yml +357 -0
- data/lang/rails/es-AR.yml +355 -0
- data/lang/rails/es-ES.yml +357 -0
- data/lang/rails/fi-FI.yml +357 -0
- data/lang/rails/fr-FR.yml +359 -0
- data/lang/rails/hu-HU.yml +357 -0
- data/lang/rails/it.yml +358 -0
- data/lang/rails/nl-NL.yml +347 -0
- data/lang/rails/pl-PL.yml +358 -0
- data/lang/rails/pt-BR.yml +324 -0
- data/lang/rails/pt-PT.yml +324 -0
- data/lang/rails/ru-RU.yml +357 -0
- data/lang/rails/sr-CP.yml +357 -0
- data/lang/rails/sr-SR.yml +357 -0
- data/lang/rails/tr.yml +186 -0
- data/lang/rails/zh-CN.yml +357 -0
- data/lang/rails/zh-HK.yml +357 -0
- data/lang/rails/zh-TW.yml +357 -0
- data/lib/globalite.rb +26 -0
- data/lib/globalite/l10n.rb +300 -0
- data/lib/globalite/locale.rb +56 -0
- data/lib/rails/core_ext.rb +19 -0
- data/lib/rails/localization.rb +58 -0
- data/lib/rails/localized_action_view.rb +211 -0
- data/lib/rails/localized_active_record.rb +80 -0
- data/spec/core_localization_spec.rb +116 -0
- data/spec/helpers/spec_helper.rb +16 -0
- data/spec/l10n_spec.rb +251 -0
- data/spec/lang/rails/zz.yml +13 -0
- data/spec/lang/ui/en-UK.yml +3 -0
- data/spec/lang/ui/en-US.yml +3 -0
- data/spec/lang/ui/es.yml +3 -0
- data/spec/lang/ui/fr-FR.yml +8 -0
- metadata +87 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
rescue LoadError
|
5
|
+
puts "==> The test/spec library (gem) is required to run the Globalite tests."
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
10
|
+
ENV["RAILS_ENV"] = "test"
|
11
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../../../../config/environment")
|
12
|
+
require 'globalite'
|
13
|
+
|
14
|
+
# add and Load the spec localization files
|
15
|
+
Globalite.add_localization_source(File.dirname(__FILE__) + '/../lang/ui')
|
16
|
+
Globalite.load_localization!
|
data/spec/l10n_spec.rb
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helpers/spec_helper'
|
2
|
+
|
3
|
+
describe "After loading languages, Globalite" do
|
4
|
+
before(:all) do
|
5
|
+
Globalite.add_localization_source(File.dirname(__FILE__) + '/../spec/lang/ui/')
|
6
|
+
Globalite.load_localization!
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have loaded en-US spec localization' do
|
10
|
+
Globalite.locales.should include(:"en-US")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have some default translations' do
|
14
|
+
:error_message_exclusion.l.should_not be(nil)
|
15
|
+
Globalite.localize(:welcome_friend).should_not be(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have loaded the Rails localizations' do
|
19
|
+
[:"es-*", :"fr-FR", :"pt-PT", :"en-US", :"it-*", :"es-ES", :"pt-BR", :"en-UK"].each { |locale| Globalite.locales.should include(locale) }
|
20
|
+
[:UK, :US, :ES, :FR, :BR, :PT].each { |country| Globalite.countries.should include(country) }
|
21
|
+
[:en, :es, :fr, :it, :pt].each { |language| Globalite.languages.should include(language) }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have both the UI and the RAILS translations even if a country isn t selected' do
|
25
|
+
Globalite.language = :fr
|
26
|
+
:welcome_friend.l.should_not == "__localization_missing__"
|
27
|
+
:date_helper_one_month.l.should_not == "__localization_missing__"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should have a list of unique languages' do
|
31
|
+
Globalite.languages.should be_an_instance_of(Array)
|
32
|
+
Globalite.languages.should == Globalite.languages.uniq
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should have a list of unique countries' do
|
36
|
+
Globalite.countries.should be_an_instance_of(Array)
|
37
|
+
Globalite.countries.should == Globalite.countries.uniq
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have a list of unique locales' do
|
41
|
+
Globalite.locales.should be_an_instance_of(Array)
|
42
|
+
Globalite.locales.should == Globalite.locales.uniq
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have at least some English localization" do
|
46
|
+
Globalite.languages.should include(:en)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should work using the alias methods' do
|
50
|
+
Globalite.country = :UK
|
51
|
+
Globalite.country.should == (:UK)
|
52
|
+
Globalite.current_country = :FR
|
53
|
+
Globalite.current_country.should == (:FR)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be able to switch between existing languages" do
|
57
|
+
Globalite.language = :fr
|
58
|
+
Globalite.locale.should == (:'fr-FR')
|
59
|
+
string = "Welcome, dude!"
|
60
|
+
Globalite.localize(:welcome_friend).should_not == string
|
61
|
+
Globalite.localize(:welcome_friend).should == "Bienvenue l'ami!"
|
62
|
+
Globalite.localize(:welcome_friend).should_not == "__localization_missing__"
|
63
|
+
|
64
|
+
Globalite.language = :es
|
65
|
+
Globalite.localize(:welcome_friend).should_not == string
|
66
|
+
Globalite.localize(:welcome_friend).should_not == "__localization_missing__"
|
67
|
+
|
68
|
+
Globalite.current_language = nil
|
69
|
+
Globalite.localize(:welcome_friend).should_not == string
|
70
|
+
Globalite.localize(:welcome_friend).should_not == "__localization_missing__"
|
71
|
+
|
72
|
+
Globalite.current_language = :en
|
73
|
+
Globalite.current_country = :US
|
74
|
+
Globalite.locales.should include(:"en-US")
|
75
|
+
Locale.code.should == :"en-US"
|
76
|
+
Globalite.localize(:welcome_friend).should == string
|
77
|
+
Globalite.localize(:welcome_friend).should_not == "__localization_missing__"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be able to switch languages using strings" do
|
81
|
+
Globalite.current_language = 'es'
|
82
|
+
Globalite.current_language.should == :es
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be able to switch to the default language at any time" do
|
86
|
+
Globalite.current_language = :fr
|
87
|
+
Globalite.current_language.should_not ==(Globalite.default_language)
|
88
|
+
|
89
|
+
Globalite.current_language = :en
|
90
|
+
Globalite.current_language.should ==(Globalite.default_language)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should be able to set the current locale" do
|
94
|
+
Globalite.current_locale = 'en-US'
|
95
|
+
Globalite.locale.should == 'en-US'.to_sym
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should not be able to change the current country if there's no locale for it" do
|
99
|
+
Globalite.language = :fr
|
100
|
+
Globalite.locale.should == "fr-*".to_sym
|
101
|
+
Globalite.countries.include?(:XY).should be(false)
|
102
|
+
|
103
|
+
Globalite.country = :XY
|
104
|
+
Globalite.current_locale.should == "fr-*".to_sym
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should let you assign a valid locale" do
|
108
|
+
Globalite.current_locale = :"fr-*"
|
109
|
+
Globalite.current_locale.should == :"fr-*"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should auto assign a language if you try to set a country defined in an available locale" do
|
113
|
+
Globalite.current_locale = :"fr-*"
|
114
|
+
Globalite.current_country = :US
|
115
|
+
Globalite.current_locale.should == "en-US".to_sym
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should auto assign a wild card if a country isn't assigned" do
|
119
|
+
Globalite.current_language = :fr
|
120
|
+
Globalite.current_locale.should == "fr-*".to_sym
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should find translations for a locale without country even though there's no generic translation for the language" do
|
124
|
+
Globalite.current_locale = :"fr-*"
|
125
|
+
Globalite.current_language = :en
|
126
|
+
Globalite.current_language.should == :en
|
127
|
+
Globalite.localizations.should_not be_empty
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should return an array of the languages it loaded" do
|
131
|
+
Globalite.load_localization!
|
132
|
+
languages = Globalite.languages
|
133
|
+
languages.should be_an_instance_of(Array)
|
134
|
+
languages.should include(:en)
|
135
|
+
languages.should include(:fr)
|
136
|
+
Globalite.locales.should include(:"en-US")
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should return an array of locales it loaded" do
|
140
|
+
locales = Globalite.locales
|
141
|
+
locales.should be_an_instance_of(Array)
|
142
|
+
locales.should include(:"en-US")
|
143
|
+
locales.should include(:"fr-FR")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should be able to accept new, unique reserved keys" do
|
147
|
+
key = :something_evil
|
148
|
+
Globalite.add_reserved_key key
|
149
|
+
Globalite.reserved_keys.should include(key)
|
150
|
+
Globalite.reserved_keys.size.should == 2
|
151
|
+
Globalite.add_reserved_key key
|
152
|
+
Globalite.add_reserved_key key
|
153
|
+
Globalite.reserved_keys.size.should == 2
|
154
|
+
end
|
155
|
+
|
156
|
+
it "shouldn't be able to set a unsupported locale" do
|
157
|
+
Locale.set_code :"te-st"
|
158
|
+
Locale.code.should == :"en-*"
|
159
|
+
Locale.set_code 'test'
|
160
|
+
Locale.code.should == :"en-*"
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "When a non-existent language is set" do
|
166
|
+
before(:each) do
|
167
|
+
Globalite.current_language = :klingon
|
168
|
+
end
|
169
|
+
|
170
|
+
it "the previous language should be used" do
|
171
|
+
Globalite.current_language.should == Globalite.default_language
|
172
|
+
Globalite.current_language = :fr
|
173
|
+
# testing alias
|
174
|
+
Globalite.language.should == :fr
|
175
|
+
Globalite.current_language = :klingon
|
176
|
+
Globalite.current_language.should == :fr
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "a localization key (in general)" do
|
182
|
+
|
183
|
+
before(:each) do
|
184
|
+
Globalite.current_locale = "en-US".to_sym
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return the proper localization it the key is localized" do
|
188
|
+
:welcome_friend.localize.should == "Welcome, dude!"
|
189
|
+
:welcome_friend.l.should == "Welcome, dude!"
|
190
|
+
Globalite.current_language = :fr
|
191
|
+
:welcome_friend.l.should == "Bienvenue l'ami!"
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should return the available localization for the language" do
|
195
|
+
Globalite.language = :fr
|
196
|
+
Globalite.language = :en
|
197
|
+
Globalite.locale.should == :'en-*'
|
198
|
+
|
199
|
+
:welcome_friend.localize.should == "Welcome mate!"
|
200
|
+
:error_message_exclusion.l.should == "is reserved"
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should return an optional string if the localization is missing" do
|
204
|
+
:unknown_key.l("this is my replacement string").should == "this is my replacement string"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return an error missing if the localization is missing and no option string was given" do
|
208
|
+
:unknown_key.l.should == "__localization_missing__"
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should return nil if a reserved key is used" do
|
212
|
+
:limit.l.should be(nil)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should be able to localized a key with one or many passed arguments" do
|
216
|
+
Globalite.current_language = :fr
|
217
|
+
:welcome_user.l_with_args({:user => :user.l}).should == "Cher utilisateur, Bienvenue!"
|
218
|
+
:many_args_test.l_with_args({:name => 'Matt', :what => 'déchire', :other => 'Serieusement'}).should == 'Serieusement, Matt vraiment déchire comme une bete ;)'
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should handle localizated pluralization properly" do
|
222
|
+
Globalite.current_language = :fr
|
223
|
+
:simple_pluralization.l.should == "2 erreurs"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should handle custom pluralization properly" do
|
227
|
+
Globalite.current_language = :fr
|
228
|
+
:pluralization_test.l.should == "Heidi a vu trois 3 chevaux dans le parc"
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should handle pluralization with passed arguments" do
|
232
|
+
Globalite.current_language = :fr
|
233
|
+
:pluralization_with_passed_args.l_with_args({:count => 2}).should == "Heidi a vu trois 2 chevaux dans le parc"
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "an alternative location with localization files" do
|
239
|
+
before(:all) do
|
240
|
+
Globalite.add_localization_source(File.dirname(__FILE__) + '/lang/rails')
|
241
|
+
end
|
242
|
+
|
243
|
+
it "could be added to the localization source path" do
|
244
|
+
Globalite.load_localization!.should include("/spec/lang/rails/zz.yml")
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should have been loaded properly" do
|
248
|
+
Globalite.languages.should include(:zz)
|
249
|
+
Globalite.locales.should include(:"zz-*")
|
250
|
+
end
|
251
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# ActiveRecord::Errors.default_error_messages
|
2
|
+
error_message_inclusion: is not included in the list
|
3
|
+
error_message_exclusion: is reserved
|
4
|
+
error_message_invalid: is invalid
|
5
|
+
error_message_confirmation: doesn't match confirmation
|
6
|
+
error_message_accepted: must be accepted
|
7
|
+
error_message_empty: can't be empty
|
8
|
+
error_message_blank: can't be blank
|
9
|
+
error_message_too_long: is too long (maximum is %d characters)
|
10
|
+
error_message_too_short: is too short (minimum is %d characters)
|
11
|
+
error_message_wrong_length: is the wrong length (should be %d characters)
|
12
|
+
error_message_taken: has already been taken
|
13
|
+
error_message_not_a_number: is not a number
|
data/spec/lang/ui/es.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
welcome_friend: Bienvenue l'ami!
|
2
|
+
welcome_user: Cher {user}, Bienvenue!
|
3
|
+
love_rails: J'aime Rails.
|
4
|
+
user: utilisateur
|
5
|
+
many_args_test: "{other}, {name} vraiment {what} comme une bete ;)"
|
6
|
+
simple_pluralization: pluralize{2, erreur}
|
7
|
+
pluralization_test: Heidi a vu trois pluralize{3, cheval, chevaux} dans le parc
|
8
|
+
:pluralization_with_passed_args: Heidi a vu trois pluralize{{count}, cheval, chevaux} dans le parc
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matta-globalite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Aimonetti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Easy UI localization, Rails localization. (Localization of the core functions from rails), Simple yet powerful solution for user content availability in multiple languages.
|
17
|
+
email: mattaimonetti@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- lang/rails/de-DE.yml
|
26
|
+
- lang/rails/en-UK.yml
|
27
|
+
- lang/rails/en-US.yml
|
28
|
+
- lang/rails/es-AR.yml
|
29
|
+
- lang/rails/es-ES.yml
|
30
|
+
- lang/rails/fi-FI.yml
|
31
|
+
- lang/rails/fr-FR.yml
|
32
|
+
- lang/rails/hu-HU.yml
|
33
|
+
- lang/rails/it.yml
|
34
|
+
- lang/rails/nl-NL.yml
|
35
|
+
- lang/rails/pl-PL.yml
|
36
|
+
- lang/rails/pt-BR.yml
|
37
|
+
- lang/rails/pt-PT.yml
|
38
|
+
- lang/rails/ru-RU.yml
|
39
|
+
- lang/rails/zh-CN.yml
|
40
|
+
- lang/rails/sr-CP.yml
|
41
|
+
- lang/rails/sr-SR.yml
|
42
|
+
- lang/rails/tr.yml
|
43
|
+
- lang/rails/zh-HK.yml
|
44
|
+
- lang/rails/zh-TW.yml
|
45
|
+
- lib/globalite/l10n.rb
|
46
|
+
- lib/globalite/locale.rb
|
47
|
+
- lib/rails/core_ext.rb
|
48
|
+
- lib/rails/localization.rb
|
49
|
+
- lib/rails/localized_action_view.rb
|
50
|
+
- lib/rails/localized_active_record.rb
|
51
|
+
- lib/globalite.rb
|
52
|
+
- README
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/mojombo/grit
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.0.1
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: Globalite is meant to be a breed of the best internationalization/localization plugins available for Rails.
|
79
|
+
test_files:
|
80
|
+
- spec/helpers/spec_helper.rb
|
81
|
+
- spec/lang/rails/zz.yml
|
82
|
+
- spec/lang/ui/es.yml
|
83
|
+
- spec/lang/ui/en-UK.yml
|
84
|
+
- spec/lang/ui/en-US.yml
|
85
|
+
- spec/lang/ui/fr-FR.yml
|
86
|
+
- spec/core_localization_spec.rb
|
87
|
+
- spec/l10n_spec.rb
|