lola 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,2 @@
1
+ ### 0.1
2
+ * Added English & Spanish language translations
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "bundler", "~> 1.0.0"
5
+ gem "jeweler", "~> 1.6.4"
6
+ gem "rails"
7
+ gem "rcov", ">= 0"
8
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Carlos Hernandez
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.
@@ -0,0 +1,87 @@
1
+ = Lola - A simple collection of languages names and abbreviations for Ruby
2
+
3
+ The idea is to provide a single library for all language naming concerns, and unify them under a consistent API.
4
+
5
+ == Installation
6
+
7
+ gem install lola
8
+
9
+ If you're in Rails 3, put this in your Gemfile:
10
+
11
+ gem 'lola'
12
+
13
+
14
+ == Get a list of all countries
15
+
16
+ Lola.languages => […, ['English', 'EN'], …, ['Spanish', 'ES'], …]
17
+ Lola.languages(:locale => 'es') => […, ['Inglés', 'EN'], …, ['Español', 'ES'], …]
18
+
19
+ == Abbreviation handling
20
+
21
+ Lola.language_name('EN') => 'English'
22
+ Lola.language_code('Spanish') => 'ES'
23
+
24
+ == Default Language
25
+
26
+ Methods that take a language code argument will use the default language if none is provided. The default default language is 'EN'. You can change it to any language code:
27
+
28
+ Lola.default_language = 'DE'
29
+
30
+ == Excluding Languages
31
+
32
+ Languages to exclude are specified as an array of language codes:
33
+
34
+ Lola.excluded_languages = [ 'MR', 'PS', 'TI', ... ]
35
+
36
+ = Adding Priority Languages
37
+
38
+ It can be useful to show a few languages first in the list, before any others. This can be done like so:
39
+
40
+ Lola.priority_languages = %w(EN ES DE FR)
41
+
42
+ = Localization
43
+
44
+ You can switch between different localizations of the languages list, by setting the locale value (default is :en):
45
+
46
+ Lola.default_locale = :es
47
+
48
+ Methods that return language names also take an optional options hash as the last argument, which can be use to override the default locale for a single call:
49
+
50
+ Lola.language_name('EN') => 'English'
51
+ Lola.language_name('EN', :locale => :es) => 'Inglés'
52
+
53
+ Currently included localizations are: English (:en), Spanish (:es)
54
+
55
+ = Rails view helpers
56
+
57
+ Lola ships with replacements for language_select. Usage is simple:
58
+
59
+ <%= form_for @address do |f| %>
60
+ <%= f.label :language, "Language" %>
61
+ <%= f.language_select(:language, "EN") %>
62
+ <%= submit_tag "Create" %>
63
+ <% end %>
64
+
65
+ == Changelog
66
+
67
+ See CHANGELOG.md
68
+
69
+ == Development notes
70
+
71
+ The plugin does not require rubygems anywhere in the test or libraries, so if you are having trouble with load errors running the tests, prepend your command with RUBYOPT=rubygems. {More info}[http://tomayko.com/writings/require-rubygems-antipattern].
72
+
73
+
74
+ == Contributing to Lola
75
+
76
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
77
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
78
+ * Fork the project
79
+ * Start a feature/bugfix branch
80
+ * Commit and push until you are happy with your contribution
81
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
82
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
83
+
84
+ == Credits
85
+
86
+ Thanks to Jim Benton and all the team behind {Carmen}[https://github.com/jim/carmen].
87
+
@@ -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 = "lola"
18
+ gem.homepage = "http://github.com/polimorfico/lola"
19
+ gem.license = "MIT"
20
+ gem.summary = "A simple collection of language names and abbreviations for Rails apps (includes replacements for language_select)"
21
+ gem.description = "A simple collection of language names and abbreviations for Rails apps (includes replacements for language_select)"
22
+ gem.email = "carlos@recrea.es"
23
+ gem.authors = ["Carlos Hernandez"]
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 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "lola #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,375 @@
1
+ ---
2
+ - - Afar
3
+ - AA
4
+ - - Abkhazian
5
+ - AB
6
+ - - Avestan
7
+ - AE
8
+ - - Afrikaans
9
+ - AF
10
+ - - Akan
11
+ - AK
12
+ - - Amharic
13
+ - AM
14
+ - - Aragonese
15
+ - AN
16
+ - - Arabic
17
+ - AR
18
+ - - Assamese
19
+ - AS
20
+ - - Avaric
21
+ - AV
22
+ - - Aymara
23
+ - AY
24
+ - - Azerbaijani
25
+ - AZ
26
+ - - Bashkir
27
+ - BA
28
+ - - Belarusian
29
+ - BE
30
+ - - Bulgarian
31
+ - BG
32
+ - - Bihari
33
+ - BH
34
+ - - Bislama
35
+ - BI
36
+ - - Bambara
37
+ - BM
38
+ - - Bengali
39
+ - BN
40
+ - - Tibetan
41
+ - BO
42
+ - - Breton
43
+ - BR
44
+ - - Bosnian
45
+ - BS
46
+ - - Catalan
47
+ - CA
48
+ - - Chechen
49
+ - CE
50
+ - - Chamorro
51
+ - CH
52
+ - - Corsican
53
+ - CO
54
+ - - Cree
55
+ - CR
56
+ - - Czech
57
+ - CS
58
+ - - Church Slavic
59
+ - CU
60
+ - - Chuvash
61
+ - CV
62
+ - - Welsh
63
+ - CY
64
+ - - Danish
65
+ - DA
66
+ - - German
67
+ - DE
68
+ - - Divehi
69
+ - DV
70
+ - - Dzongkha
71
+ - DZ
72
+ - - Ewe
73
+ - EE
74
+ - - Greek
75
+ - EL
76
+ - - English
77
+ - EN
78
+ - - Esperanto
79
+ - EO
80
+ - - Spanish
81
+ - ES
82
+ - - Estonian
83
+ - ET
84
+ - - Basque
85
+ - EU
86
+ - - Persian
87
+ - FA
88
+ - - Fulah
89
+ - FF
90
+ - - Finnish
91
+ - FI
92
+ - - Fijian
93
+ - FJ
94
+ - - Faroese
95
+ - FO
96
+ - - French
97
+ - FR
98
+ - - Western Frisian
99
+ - FY
100
+ - - Irish
101
+ - GA
102
+ - - Scottish Gaelic
103
+ - GD
104
+ - - Galician
105
+ - GL
106
+ - - Guaraní
107
+ - GN
108
+ - - Gujarati
109
+ - GU
110
+ - - Manx
111
+ - GV
112
+ - - Hausa
113
+ - HA
114
+ - - Hebrew
115
+ - HE
116
+ - - Hindi
117
+ - HI
118
+ - - Hiri Motu
119
+ - HO
120
+ - - Croatian
121
+ - HR
122
+ - - Haitian
123
+ - HT
124
+ - - Hungarian
125
+ - HU
126
+ - - Armenian
127
+ - HY
128
+ - - Herero
129
+ - HZ
130
+ - - Interlingua
131
+ - IA
132
+ - - Indonesian
133
+ - ID
134
+ - - Interlingue
135
+ - IE
136
+ - - Igbo
137
+ - IG
138
+ - - Sichuan Yi
139
+ - II
140
+ - - Inupiaq
141
+ - IK
142
+ - - Ido
143
+ - IO
144
+ - - Icelandic
145
+ - IS
146
+ - - Italian
147
+ - IT
148
+ - - Inuktitut
149
+ - IU
150
+ - - Japanese
151
+ - JA
152
+ - - Javanese
153
+ - JV
154
+ - - Georgian
155
+ - KA
156
+ - - Kongo
157
+ - KG
158
+ - - Gikuyu
159
+ - KI
160
+ - - Kwanyama
161
+ - KJ
162
+ - - Kazakh
163
+ - KK
164
+ - - Kalaallisut
165
+ - KL
166
+ - - Khmer
167
+ - KM
168
+ - - Kannada
169
+ - KN
170
+ - - Korean
171
+ - KO
172
+ - - Kanuri
173
+ - KR
174
+ - - Kashmiri
175
+ - KS
176
+ - - Kurdish
177
+ - KU
178
+ - - Komi
179
+ - KV
180
+ - - Cornish
181
+ - KW
182
+ - - Kyrgyz
183
+ - KY
184
+ - - Latin
185
+ - LA
186
+ - - Luxembourgish
187
+ - LB
188
+ - - Ganda
189
+ - LG
190
+ - - Limburgish
191
+ - LI
192
+ - - Lingala
193
+ - LN
194
+ - - Lao
195
+ - LO
196
+ - - Lithuanian
197
+ - LT
198
+ - - Luba-Katanga
199
+ - LU
200
+ - - Latvian
201
+ - LV
202
+ - - Malagasy
203
+ - MG
204
+ - - Marshallese
205
+ - MH
206
+ - - Maori
207
+ - MI
208
+ - - Macedonian
209
+ - MK
210
+ - - Malayalam
211
+ - ML
212
+ - - Mongolian
213
+ - MN
214
+ - - Moldavian
215
+ - MO
216
+ - - Marathi
217
+ - MR
218
+ - - Malay
219
+ - MS
220
+ - - Maltese
221
+ - MT
222
+ - - Burmese
223
+ - MY
224
+ - - Nauru
225
+ - NA
226
+ - - Norwegian Bokmål
227
+ - NB
228
+ - - North Ndebele
229
+ - ND
230
+ - - Nepali
231
+ - NE
232
+ - - Ndonga
233
+ - NG
234
+ - - Dutch
235
+ - NL
236
+ - - Norwegian Nynorsk
237
+ - NN
238
+ - - Norwegian
239
+ - NO
240
+ - - Southern Ndebele
241
+ - NR
242
+ - - Navajo
243
+ - NV
244
+ - - Chichewa
245
+ - NY
246
+ - - Occitan
247
+ - OC
248
+ - - Ojibwa
249
+ - OJ
250
+ - - Oromo
251
+ - OM
252
+ - - Oriya
253
+ - OR
254
+ - - Ossetian
255
+ - OS
256
+ - - Panjabi
257
+ - PA
258
+ - - Pāli
259
+ - PI
260
+ - - Polish
261
+ - PL
262
+ - - Pashto
263
+ - PS
264
+ - - Portuguese
265
+ - PT
266
+ - - Quechua
267
+ - QU
268
+ - - Raeto-Romance
269
+ - RM
270
+ - - Kirundi
271
+ - RN
272
+ - - Romanian
273
+ - RO
274
+ - - Russian
275
+ - RU
276
+ - - Kinyarwanda
277
+ - RW
278
+ - - Rusyn
279
+ - RY
280
+ - - Sanskrit
281
+ - SA
282
+ - - Sardinian
283
+ - SC
284
+ - - Sindhi
285
+ - SD
286
+ - - Northern Sami
287
+ - SE
288
+ - - Sango
289
+ - SG
290
+ - - Serbo-Croatian
291
+ - SH
292
+ - - Sinhalese
293
+ - SI
294
+ - - Slovak
295
+ - SK
296
+ - - Slovenian
297
+ - SL
298
+ - - Samoan
299
+ - SM
300
+ - - Shona
301
+ - SN
302
+ - - Somali
303
+ - SO
304
+ - - Albanian
305
+ - SQ
306
+ - - Serbian
307
+ - SR
308
+ - - Swati
309
+ - SS
310
+ - - Sotho
311
+ - ST
312
+ - - Sundanese
313
+ - SU
314
+ - - Swedish
315
+ - SV
316
+ - - Swahili
317
+ - SW
318
+ - - Tamil
319
+ - TA
320
+ - - Telugu
321
+ - TE
322
+ - - Tajik
323
+ - TG
324
+ - - Thai
325
+ - TH
326
+ - - Tigrinya
327
+ - TI
328
+ - - Turkmen
329
+ - TK
330
+ - - Tagalog
331
+ - TL
332
+ - - Tswana
333
+ - TN
334
+ - - Tonga
335
+ - TO
336
+ - - Turkish
337
+ - TR
338
+ - - Tsonga
339
+ - TS
340
+ - - Tatar
341
+ - TT
342
+ - - Twi
343
+ - TW
344
+ - - Tahitian
345
+ - TY
346
+ - - Uighur
347
+ - UG
348
+ - - Ukrainian
349
+ - UK
350
+ - - Urdu
351
+ - UR
352
+ - - Uzbek
353
+ - UZ
354
+ - - Venda
355
+ - VE
356
+ - - Vietnamese
357
+ - VI
358
+ - - Volapük
359
+ - VO
360
+ - - Walloon
361
+ - WA
362
+ - - Wolof
363
+ - WO
364
+ - - Xhosa
365
+ - XH
366
+ - - Yiddish
367
+ - YI
368
+ - - Yoruba
369
+ - YO
370
+ - - Zhuang
371
+ - ZA
372
+ - - Chinese
373
+ - ZH
374
+ - - Zulu
375
+ - ZU
@@ -0,0 +1,375 @@
1
+ ---
2
+ - - Afar
3
+ - AA
4
+ - - Abjasio
5
+ - AB
6
+ - - Avéstico
7
+ - AE
8
+ - - Afrikaans
9
+ - AF
10
+ - - Akano
11
+ - AK
12
+ - - Amárico
13
+ - AM
14
+ - - Aragonés
15
+ - AN
16
+ - - Árabe
17
+ - AR
18
+ - - Asamés
19
+ - AS
20
+ - - Avar
21
+ - AV
22
+ - - Aimara
23
+ - AY
24
+ - - Azerí
25
+ - AZ
26
+ - - Baskir
27
+ - BA
28
+ - - Bielorruso
29
+ - BE
30
+ - - Búlgaro
31
+ - BG
32
+ - - Bhojpurí
33
+ - BH
34
+ - - Bislama
35
+ - BI
36
+ - - Bambara
37
+ - BM
38
+ - - Bengalí
39
+ - BN
40
+ - - Tibetano
41
+ - BO
42
+ - - Bretón
43
+ - BR
44
+ - - Bosnio
45
+ - BS
46
+ - - Catalán
47
+ - CA
48
+ - - Checheno
49
+ - CE
50
+ - - Chamorro
51
+ - CH
52
+ - - Corso
53
+ - CO
54
+ - - Cree
55
+ - CR
56
+ - - Checo
57
+ - CS
58
+ - - Eslavo eclesiástico antiguo
59
+ - CU
60
+ - - Chuvasio
61
+ - CV
62
+ - - Galés
63
+ - CY
64
+ - - Danés
65
+ - DA
66
+ - - Alemán
67
+ - DE
68
+ - - Maldivo
69
+ - DV
70
+ - - Dzongkha
71
+ - DZ
72
+ - - Ewe
73
+ - EE
74
+ - - Griego
75
+ - EL
76
+ - - Inglés
77
+ - EN
78
+ - - Esperanto
79
+ - EO
80
+ - - Español
81
+ - ES
82
+ - - Estonio
83
+ - ET
84
+ - - Euskera
85
+ - EU
86
+ - - Persa
87
+ - FA
88
+ - - Fula
89
+ - FF
90
+ - - Finés
91
+ - FI
92
+ - - Fiyiano
93
+ - FJ
94
+ - - Feroés
95
+ - FO
96
+ - - Francés
97
+ - FR
98
+ - - Frisón
99
+ - FY
100
+ - - Irlandés
101
+ - GA
102
+ - - Gaélico escocés
103
+ - GD
104
+ - - Gallego
105
+ - GL
106
+ - - Guaraní
107
+ - GN
108
+ - - Guyaratí
109
+ - GU
110
+ - - Manés
111
+ - GV
112
+ - - Hausa
113
+ - HA
114
+ - - Hebreo
115
+ - HE
116
+ - - Hindi
117
+ - HI
118
+ - - Hiri Motu
119
+ - HO
120
+ - - Croata
121
+ - HR
122
+ - - Haitiano
123
+ - HT
124
+ - - Húngaro
125
+ - HU
126
+ - - Armenio
127
+ - HY
128
+ - - Herero
129
+ - HZ
130
+ - - Interlingua
131
+ - IA
132
+ - - Indonesio
133
+ - ID
134
+ - - Occidental
135
+ - IE
136
+ - - Igbo
137
+ - IG
138
+ - - Yi de Sichuán
139
+ - II
140
+ - - Inupiaq
141
+ - IK
142
+ - - Ido
143
+ - IO
144
+ - - Islandés
145
+ - IS
146
+ - - Italiano
147
+ - IT
148
+ - - Inuktitut
149
+ - IU
150
+ - - Japonés
151
+ - JA
152
+ - - Javanés
153
+ - JV
154
+ - - Georgiano
155
+ - KA
156
+ - - Kongo
157
+ - KG
158
+ - - Kikuyu
159
+ - KI
160
+ - - Kuanyama
161
+ - KJ
162
+ - - Kazajo
163
+ - KK
164
+ - - Groelandés
165
+ - KL
166
+ - - Camboyano
167
+ - KM
168
+ - - Canarés
169
+ - KN
170
+ - - Coreano
171
+ - KO
172
+ - - Kanuri
173
+ - KR
174
+ - - Cachemiro
175
+ - KS
176
+ - - Kurdo
177
+ - KU
178
+ - - Komi
179
+ - KV
180
+ - - Córnico
181
+ - KW
182
+ - - Kirguís
183
+ - KY
184
+ - - Latín
185
+ - LA
186
+ - - Luxemburgués
187
+ - LB
188
+ - - Luganda
189
+ - LG
190
+ - - Limburgués
191
+ - LI
192
+ - - Lingala
193
+ - LN
194
+ - - Lao
195
+ - LO
196
+ - - Lituano
197
+ - LT
198
+ - - Luba-Katanga
199
+ - LU
200
+ - - Letón
201
+ - LV
202
+ - - Malgache
203
+ - MG
204
+ - - Marshalés
205
+ - MH
206
+ - - Maorí
207
+ - MI
208
+ - - Macedonio
209
+ - MK
210
+ - - Malayalam
211
+ - ML
212
+ - - Mongol
213
+ - MN
214
+ - - Moldavo
215
+ - MO
216
+ - - Maratí
217
+ - MR
218
+ - - Malayo
219
+ - MS
220
+ - - Maltés
221
+ - MT
222
+ - - Birmano
223
+ - MY
224
+ - - Nauruano
225
+ - NA
226
+ - - Noruego Bokmål
227
+ - NB
228
+ - - Ndebele del Norte
229
+ - ND
230
+ - - Nepalí
231
+ - NE
232
+ - - Ndonga
233
+ - NG
234
+ - - Neerlandés
235
+ - NL
236
+ - - Nynorsk
237
+ - NN
238
+ - - Noruego
239
+ - NO
240
+ - - Ndebele del Sur
241
+ - NR
242
+ - - Navajo
243
+ - NV
244
+ - - Chichewa
245
+ - NY
246
+ - - Occitano
247
+ - OC
248
+ - - Ojibwa
249
+ - OJ
250
+ - - Oromo
251
+ - OM
252
+ - - Oriya
253
+ - OR
254
+ - - Osético
255
+ - OS
256
+ - - Panyabí
257
+ - PA
258
+ - - Pāli
259
+ - PI
260
+ - - Polaco
261
+ - PL
262
+ - - Pastú
263
+ - PS
264
+ - - Portugués
265
+ - PT
266
+ - - Quechua
267
+ - QU
268
+ - - Retorrománico
269
+ - RM
270
+ - - Kirundi
271
+ - RN
272
+ - - Rumano
273
+ - RO
274
+ - - Ruso
275
+ - RU
276
+ - - Ruandés
277
+ - RW
278
+ - - Rusyn
279
+ - RY
280
+ - - Sánscrito
281
+ - SA
282
+ - - Sardo
283
+ - SC
284
+ - - Sindhi
285
+ - SD
286
+ - - Sami Septentrional
287
+ - SE
288
+ - - Sango
289
+ - SG
290
+ - - Serbocroata
291
+ - SH
292
+ - - Cingalés
293
+ - SI
294
+ - - Eslovaco
295
+ - SK
296
+ - - Esloveno
297
+ - SL
298
+ - - Samoano
299
+ - SM
300
+ - - Shona
301
+ - SN
302
+ - - Somalí
303
+ - SO
304
+ - - Albanés
305
+ - SQ
306
+ - - Serbio
307
+ - SR
308
+ - - Suazi
309
+ - SS
310
+ - - Sesotho
311
+ - ST
312
+ - - Sundanés
313
+ - SU
314
+ - - Sueco
315
+ - SV
316
+ - - Suajili
317
+ - SW
318
+ - - Tamil
319
+ - TA
320
+ - - Telugú
321
+ - TE
322
+ - - Tayiko
323
+ - TG
324
+ - - Tailandés
325
+ - TH
326
+ - - Tigriña
327
+ - TI
328
+ - - Turcomano
329
+ - TK
330
+ - - Tagalo
331
+ - TL
332
+ - - Setsuana
333
+ - TN
334
+ - - Tongano
335
+ - TO
336
+ - - Turco
337
+ - TR
338
+ - - Tsonga
339
+ - TS
340
+ - - Tártaro
341
+ - TT
342
+ - - Twi
343
+ - TW
344
+ - - Tahitiano
345
+ - TY
346
+ - - Uigur
347
+ - UG
348
+ - - Ucraniano
349
+ - UK
350
+ - - Urdu
351
+ - UR
352
+ - - Uzbeko
353
+ - UZ
354
+ - - Venda
355
+ - VE
356
+ - - Vietnamita
357
+ - VI
358
+ - - Volapük
359
+ - VO
360
+ - - Valón
361
+ - WA
362
+ - - Wolof
363
+ - WO
364
+ - - Xhosa
365
+ - XH
366
+ - - Yiddish
367
+ - YI
368
+ - - Yoruba
369
+ - YO
370
+ - - Zhuang
371
+ - ZA
372
+ - - Chino
373
+ - ZH
374
+ - - Zulú
375
+ - ZU
@@ -0,0 +1,83 @@
1
+ require 'yaml'
2
+
3
+ module Lola
4
+ class << self
5
+ attr_accessor :default_locale, :default_language, :excluded_languages, :priority_languages
6
+ end
7
+
8
+ self.default_locale = :en
9
+ self.default_language = 'EN'
10
+ self.excluded_languages = []
11
+ self.priority_languages = []
12
+
13
+ @data_path = File.join(File.dirname(__FILE__), '..', 'data')
14
+
15
+ # Raised when attemting to switch to a locale which does not exist
16
+ class UnavailableLocale < RuntimeError; end
17
+
18
+ # Returns a list of all languages
19
+ def self.languages(options={})
20
+ # Use specified locale or fall back to default locale
21
+ locale = (options.delete(:locale) || @default_locale).to_s
22
+
23
+ # Load the country list for the specified locale
24
+ @languages ||= {}
25
+ unless @languages[locale]
26
+ # Check if data in the specified locale is available
27
+ localized_data = File.join(@data_path, "#{locale}.yml")
28
+ unless File.exists?(localized_data)
29
+ raise(UnavailableLocale, "Could not load languages for '#{locale}' locale")
30
+ end
31
+
32
+ # As the data exists, load it
33
+ @languages[locale] = YAML.load_file(localized_data)
34
+ end
35
+
36
+ # Return data after filtering excluded languages and prepending prepended languages
37
+ result = @languages[locale].reject { |c| excluded_languages.include?( c[1] ) }
38
+ priority_languages.map { |code| [ search_collection(result, code, 1, 0), code ] } + result
39
+ end
40
+
41
+ # Returns the language name corresponding to the supplied language code, optionally using the specified locale.
42
+ # Carmen::language_name('EN') => 'English'
43
+ # Carmen::language_name('ES', :locale => :es) => 'Español'
44
+ def self.language_name(language_code, options={})
45
+ search_collection(languages(options), language_code, 1, 0)
46
+ end
47
+
48
+ # Returns the language code corresponding to the supplied language name
49
+ # Carmen::language_code('English') => 'EN'
50
+ def self.language_code(language_name, options={})
51
+ search_collection(languages(options), language_name, 0, 1)
52
+ end
53
+
54
+ # Returns an array of all language codes
55
+ # Carmen::language_codes => ['AA', 'AB', 'AE', ... ]
56
+ def self.language_codes
57
+ languages.map {|c| c[1] }
58
+ end
59
+
60
+ # Returns an array of all language names, optionally using the specified locale.
61
+ # Carmen::language_names => ['Afar', 'Abkhazian', Avestan', ... ]
62
+ # Carmen::language_names(:locale => :es) => ['Afrikaans', 'Árabe', 'Bengalí', ... ]
63
+ def self.language_names(options={})
64
+ languages(options).map {|c| c[0] }
65
+ end
66
+
67
+ protected
68
+ def self.search_collection(collection, value, index_to_match, index_to_retrieve)
69
+ return nil if collection.nil? || value.nil? || value.empty?
70
+ collection.each do |m|
71
+ return m[index_to_retrieve] if m[index_to_match].downcase == value.downcase
72
+ end
73
+ # In case we didn't get any results we'll try a broader search (via Regexp)
74
+ collection.each do |m|
75
+ return m[index_to_retrieve] if m[index_to_match].downcase.match(Regexp.escape(value.downcase))
76
+ end
77
+ nil
78
+ end
79
+ end
80
+
81
+ if defined?(Rails)
82
+ require 'lola/railtie'
83
+ end
@@ -0,0 +1,45 @@
1
+ module ActionView
2
+ module Helpers
3
+ module FormOptionsHelper
4
+ # Return select and option tags for the given object and method, using language_options_for_select to generate the list of option tags.
5
+ def language_select(object, method, priority_languages = nil, options = {}, html_options = {})
6
+ InstanceTag.new(object, method, self, options.delete(:object)).to_language_select_tag(priority_languages, options, html_options)
7
+ end
8
+
9
+ # Returns a string of option tags for pretty much any language in the world. Supply a language name as +selected+ to
10
+ # have it marked as the selected option tag. You can also supply a list of language codes as additional parameters, so
11
+ # that they will be listed above the rest of the (long) list.
12
+ def language_options_for_select(selected = nil, *priority_language_codes)
13
+ language_options = ""
14
+
15
+ unless priority_language_codes.empty?
16
+ priority_languages = Lola::languages.select do |pair| name, code = pair
17
+ priority_language_codes.include?(code)
18
+ end
19
+ unless priority_languages.empty?
20
+ language_options += options_for_select(priority_languages, selected)
21
+ language_options += "\n<option value=\"\" disabled=\"disabled\">-------------</option>\n"
22
+ end
23
+ end
24
+
25
+ return language_options + options_for_select(Lola.languages, priority_language_codes.include?(selected) ? nil : selected)
26
+ end
27
+ end
28
+
29
+ class InstanceTag
30
+ def to_language_select_tag(priority_languages, options, html_options)
31
+ html_options = html_options.stringify_keys
32
+ add_default_name_and_id(html_options)
33
+ value = value(object)
34
+ opts = add_options(language_options_for_select(value, *priority_languages), options, value)
35
+ content_tag("select", opts, html_options)
36
+ end
37
+ end
38
+
39
+ class FormBuilder
40
+ def language_select(method, priority_languages = nil, options = {}, html_options = {})
41
+ @template.language_select(@object_name, method, priority_languages, options.merge(:object => @object), html_options)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ require 'lola'
2
+ require 'rails'
3
+
4
+ module Lola
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ config.after_initialize do
8
+ require 'lola/helpers'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
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
+
12
+ require File.expand_path('../lib/lola', File.dirname(__FILE__))
13
+
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ class TestLola < Test::Unit::TestCase
4
+ def teardown
5
+ Lola.default_locale = :en # restore default
6
+ end
7
+
8
+ def test_default_languages
9
+ assert_equal ['Avestan', 'AE'], Lola.languages[2]
10
+ end
11
+
12
+ def test_localized_languages
13
+ Lola.default_locale = :es
14
+ assert_equal ["Afar", 'AA'], Lola.languages[0]
15
+ end
16
+
17
+ def test_single_localized_languages_call
18
+ # Check that we are working with the default
19
+ assert_equal ['Afar', 'AA'], Lola.languages[0]
20
+
21
+ # Switch to a different locale for one call
22
+ assert_equal ["Afar", 'AA'], Lola.languages(:locale => 'es')[0]
23
+
24
+ # Make sure that we are back in the default locale
25
+ assert_equal ['Afar', 'AA'], Lola.languages[0]
26
+ end
27
+
28
+ def test_language_name
29
+ assert_equal 'English', Lola.language_name('EN')
30
+ assert_equal 'English', Lola.language_name('en')
31
+ assert_nil Lola.language_name('')
32
+ assert_nil Lola.language_name(nil)
33
+ end
34
+
35
+ def test_localized_language_name
36
+ assert_equal 'English', Lola.language_name('EN')
37
+ assert_equal 'Griego', Lola.language_name('EL', :locale => :es)
38
+ Lola.default_locale = :es
39
+ assert_equal 'Griego', Lola.language_name('EL')
40
+ end
41
+
42
+ def test_language_code
43
+ assert_equal 'ES', Lola.language_code('Spanish')
44
+ assert_equal 'ES', Lola.language_code('spanish')
45
+ assert_equal 'DE', Lola.language_code('German')
46
+ end
47
+
48
+ def test_localized_language_code
49
+ assert_equal 'EL', Lola.language_code('Griego', :locale => :es)
50
+ Lola.default_locale = :es
51
+ assert_equal 'EL', Lola.language_code('Griego')
52
+ end
53
+
54
+ def test_language_codes
55
+ assert_equal 'AA', Lola.language_codes.first
56
+ assert_equal 187, Lola.language_codes.length
57
+ end
58
+
59
+ def test_language_names
60
+ assert_equal 'Afar', Lola.language_names.first
61
+ assert_equal 187, Lola.language_names.length
62
+ end
63
+
64
+ def test_excluded_languages
65
+ Lola.excluded_languages = [ 'EN', 'ES' ]
66
+ languages = Lola.languages
67
+ assert !languages.include?( ["English", "EN"] )
68
+ assert !languages.include?( ["Spanish", "ES"] )
69
+ assert languages.include?( ["German", "DE"] )
70
+ Lola.excluded_languages = [ ]
71
+ end
72
+
73
+ def test_prepended_languages
74
+ en_original_index = Lola.languages.index(['English', 'EN'])
75
+ Lola.priority_languages = %w(EN ES DE)
76
+ languages = Lola.languages
77
+ assert_equal 0, languages.index(['English', 'EN'])
78
+ assert_equal 1, languages.index(['Spanish', 'ES'])
79
+ assert_equal 2, languages.index(['German', 'DE'])
80
+
81
+ assert_equal 3 + en_original_index, languages.rindex(['English', 'EN'])
82
+
83
+ Lola.priority_languages = []
84
+ end
85
+
86
+ def test_unsupported_locale
87
+ assert_raises Lola::UnavailableLocale do
88
+ Lola.languages(:locale => :latin)
89
+ end
90
+ end
91
+
92
+ def test_special_characters_dont_rails_an_exception
93
+ assert_nil(Lola.language_code('???'))
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lola
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Carlos Hernandez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70164691573040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70164691573040
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ requirement: &70164691572500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.4
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70164691572500
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ requirement: &70164691571980 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70164691571980
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &70164691571400 !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: *70164691571400
58
+ description: A simple collection of language names and abbreviations for Rails apps
59
+ (includes replacements for language_select)
60
+ email: carlos@recrea.es
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - CHANGELOG.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - VERSION
74
+ - data/en.yml
75
+ - data/es.yml
76
+ - lib/lola.rb
77
+ - lib/lola/helpers.rb
78
+ - lib/lola/railtie.rb
79
+ - test/helper.rb
80
+ - test/test_lola.rb
81
+ homepage: http://github.com/polimorfico/lola
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -1457035954911685501
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.10
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple collection of language names and abbreviations for Rails apps (includes
109
+ replacements for language_select)
110
+ test_files: []