r18n-core 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/ChangeLog +11 -0
  2. data/README.rdoc +225 -53
  3. data/lib/r18n-core/filters.rb +34 -34
  4. data/lib/r18n-core/i18n.rb +110 -46
  5. data/lib/r18n-core/locale.rb +109 -103
  6. data/lib/r18n-core/translated.rb +9 -4
  7. data/lib/r18n-core/translated_string.rb +10 -0
  8. data/lib/r18n-core/translation.rb +55 -99
  9. data/lib/r18n-core/unsupported_locale.rb +1 -13
  10. data/lib/r18n-core/untranslated.rb +18 -16
  11. data/lib/r18n-core/utils.rb +0 -12
  12. data/lib/r18n-core/version.rb +1 -1
  13. data/lib/r18n-core/yaml_loader.rb +67 -0
  14. data/lib/r18n-core.rb +25 -3
  15. data/locales/cs.rb +30 -16
  16. data/locales/de.rb +21 -0
  17. data/locales/en-us.rb +9 -4
  18. data/locales/en.rb +35 -20
  19. data/locales/eo.rb +20 -0
  20. data/locales/es.rb +20 -0
  21. data/locales/fr.rb +24 -9
  22. data/locales/it.rb +21 -9
  23. data/locales/kk.rb +26 -0
  24. data/locales/pl.rb +30 -18
  25. data/locales/pt-br.rb +24 -0
  26. data/locales/ru.rb +30 -12
  27. data/locales/zh.rb +19 -0
  28. data/spec/filters_spec.rb +24 -7
  29. data/spec/i18n_spec.rb +137 -50
  30. data/spec/locale_spec.rb +91 -53
  31. data/spec/locales/cs_spec.rb +9 -7
  32. data/spec/locales/pl_spec.rb +8 -9
  33. data/spec/locales/ru_spec.rb +9 -9
  34. data/spec/r18n_spec.rb +32 -13
  35. data/spec/spec_helper.rb +28 -4
  36. data/spec/translated_spec.rb +1 -1
  37. data/spec/translation_spec.rb +33 -67
  38. data/spec/translations/two/en.yml +0 -1
  39. data/spec/yaml_loader_spec.rb +33 -0
  40. metadata +11 -16
  41. data/locales/cs.yml +0 -26
  42. data/locales/de.yml +0 -26
  43. data/locales/en-us.yml +0 -10
  44. data/locales/en.yml +0 -26
  45. data/locales/eo.yml +0 -26
  46. data/locales/es.yml +0 -26
  47. data/locales/fr.yml +0 -26
  48. data/locales/it.yml +0 -26
  49. data/locales/kk.yml +0 -26
  50. data/locales/pl.yml +0 -26
  51. data/locales/pt-br.yml +0 -26
  52. data/locales/ru.yml +0 -26
  53. data/locales/zh.yml +0 -26
@@ -19,23 +19,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  =end
20
20
 
21
21
  require 'pathname'
22
- require 'yaml'
23
22
 
24
23
  module R18n
25
- # Translation for interface to i18n support. You can load several locales and
26
- # if translation willn’t be found in first, r18n will be search it in next.
27
- # Use R18n::I18n.new to load translations.
28
- #
29
- # Translation files use YAML format and has name like en.yml (English) or
30
- # en-US.yml (USA English dialect) with language/country code (RFC 3066). In
31
- # translation file you can use strings, numbers, floats (any YAML types)
32
- # and pluralizable values (<tt>!!pl</tt>). You can use params in string
33
- # values, which you can replace in program. Just write <tt>%1</tt>,
34
- # <tt>%2</tt>, etc and set it values as method arguments, when you will be get
35
- # value.
24
+ # Struct to containt translation with some type for filter.
25
+ Typed = Struct.new(:type, :value, :locale, :path)
26
+
27
+ # Translation is container of translated messages.
36
28
  #
37
- # You can use filters for some YAML type or for all strings. See R18n::Filters
38
- # for details.
29
+ # You can load several locales and if translation willn’t be found in first,
30
+ # r18n will be search it in next. Use R18n::I18n.new to load translations.
39
31
  #
40
32
  # To get translation value use method with same name. If translation name
41
33
  # is equal with Object methods (+new+, +to_s+, +methods+) use
@@ -45,9 +37,6 @@ module R18n
45
37
  # Translated strings will have +locale+ methods, which return Locale or
46
38
  # UnsupportedLocale, if locale file isn’t exists.
47
39
  #
48
- # R18n contain translations for common words (such as “OK”, “Cancel”, etc)
49
- # for most supported locales. See <tt>base/</tt> dir.
50
- #
51
40
  # == Examples
52
41
  # translations/ru.yml
53
42
  #
@@ -69,8 +58,6 @@ module R18n
69
58
  #
70
59
  # example.rb
71
60
  #
72
- # locales = [R18n::Locale.load('ru'), R18n::Locale.load('en')]
73
- # i18n = R18n::Translation.load(locales, 'translations/')
74
61
  # i18n.one #=> "Один"
75
62
  # i18n.two #=> "Two"
76
63
  #
@@ -82,73 +69,50 @@ module R18n
82
69
  #
83
70
  # i18n.comments(0) #=> "no comments"
84
71
  # i18n.comments(10) #=> "10 comments"
85
- #
86
- # i18n.yes #=> "Yes"
87
- # i18n.ok #=> "OK"
88
- # i18n.cancel #=> "Cancel"
89
- #
90
- # == Extension translations
91
- # For r18n plugin you can add dir with translations, which will be used with
92
- # application translations. For example, DB plugin may place translations for
93
- # error messages in extension dir. R18n contain translations for base words as
94
- # extension dir too.
95
72
  class Translation
96
- @@extension_translations = [
97
- Pathname(__FILE__).dirname.expand_path + '../../base']
98
-
99
- # Get dirs with extension translations. If application translations with
100
- # same locale isn’t exists, extension file willn’t be used.
101
- def self.extension_translations
102
- @@extension_translations
73
+ # Create translation hash for +path+ with messages in +data+ for +locale+.
74
+ #
75
+ # This is internal a constructor. To load translation use
76
+ # <tt>R18n::Translation.load(locales, translations_dir)</tt>.
77
+ def initialize(main_locale, path = '', locale = nil, data = {})
78
+ @path = path
79
+ @data = {}
80
+ @locale = main_locale
81
+ merge! data, locale unless data.empty?
103
82
  end
104
83
 
105
- # Return available translations in +dirs+
106
- def self.available(dirs)
107
- if dirs.is_a? Array
108
- return dirs.inject([]) do |available, i|
109
- available |= self.available(i)
110
- end
111
- end
112
-
113
- Dir.glob(File.join(dirs, '*.yml')).map do |i|
114
- File.basename(i, '.yml')
115
- end
116
- end
117
-
118
- # Load all available translations for +locales+. +Locales+ must be Locale or
119
- # UnsupportedLocale instance or an array them. +Dirs+ may be an array or a
120
- # string with path to dir with translations.
121
- #
122
- # To load translations use R18n::I18n.new method, which is more usable.
123
- def self.load(locales, dirs)
124
- dirs = @@extension_translations + Array(dirs)
125
-
126
- available = self.available(dirs)
127
- translations = []
128
- locales.each do |locale|
129
- next unless available.include? locale.code.downcase
130
- translation = {}
131
- dirs.each do |dir|
132
- file = File.join(dir, "#{locale.code.downcase}.yml")
133
- if File.exists? file
134
- Utils.deep_merge! translation, YAML::load_file(file)
84
+ # Add another hash with +translations+ for some +locale+. Current data is
85
+ # more priority, that new one in +translations+.
86
+ def merge!(translations, locale)
87
+ translations.each_pair do |name, value|
88
+ if not @data.has_key? name
89
+ path = @path.empty? ? name : "#{@path}.#{name}"
90
+ case value
91
+ when Hash
92
+ value = Translation.new(@locale, path, locale, value)
93
+ when String
94
+ value = TranslatedString.new(value, locale, path)
95
+ when YAML::PrivateType
96
+ value = Typed.new(value.type_id, value.value, locale, path)
97
+ when Typed
98
+ value.locale = locale
99
+ value.path = path
135
100
  end
101
+ @data[name] = value
102
+ elsif @data[name].is_a? Translation
103
+ @data[name].merge! value, locale
136
104
  end
137
- translations << translation
138
105
  end
139
-
140
- self.new(locales, translations)
141
106
  end
142
107
 
143
- # Create translation hash for +path+ with messages in +translations+ for
144
- # +locales+.
145
- #
146
- # This is internal a constructor. To load translation use
147
- # <tt>R18n::Translation.load(locales, translations_dir)</tt>.
148
- def initialize(locales, translations, path = '')
149
- @locales = locales
150
- @translations = translations
151
- @path = path
108
+ # Use untranslated filter to print path.
109
+ def to_s
110
+ Filters.process(Untranslated, @path, @locale, @path, [@path, '', @path])
111
+ end
112
+
113
+ # Return +default+.
114
+ def |(default)
115
+ default
152
116
  end
153
117
 
154
118
  # Short and pretty way to get translation by method name. If translation
@@ -158,7 +122,7 @@ module R18n
158
122
  # Translation can contain variable part. Just set is as <tt>%1</tt>,
159
123
  # <tt>%2</tt>, etc in translations file and set values as methods params.
160
124
  def method_missing(name, *params)
161
- self[name.to_s, *params]
125
+ self[name, *params]
162
126
  end
163
127
 
164
128
  # Return translation with special +name+.
@@ -166,27 +130,19 @@ module R18n
166
130
  # Translation can contain variable part. Just set is as <tt>%1</tt>,
167
131
  # <tt>%2</tt>, etc in translations file and set values in next +params+.
168
132
  def [](name, *params)
169
- path = @path.empty? ? name : "#{@path}.#{name}"
170
-
171
- @translations.each_with_index do |translation, i|
172
- result = translation[name]
173
- next unless result
174
-
175
- if result.is_a? Hash
176
- return self.class.new(@locales, @translations.map { |i|
177
- i[name] or {}
178
- }, path)
179
- elsif result.is_a? YAML::PrivateType
180
- type = result.type_id
181
- result = result.value
182
- else
183
- type = nil
184
- end
185
-
186
- return Filters.process(result, @locales[i], path, type, params)
133
+ value = @data[name.to_s]
134
+ case value
135
+ when TranslatedString
136
+ Filters.process_string(value, @path, params)
137
+ when Typed
138
+ Filters.process(value.type, value.value, value.locale, value.path,
139
+ params)
140
+ when nil
141
+ translated = @path.empty? ? '' : "#{@path}."
142
+ Untranslated.new(translated, name.to_s, @locale)
143
+ else
144
+ value
187
145
  end
188
-
189
- Untranslated.new(path, name, @locales)
190
146
  end
191
147
  end
192
148
  end
@@ -41,18 +41,6 @@ module R18n
41
41
  def inspect
42
42
  "Unsupported locale #{@code}"
43
43
  end
44
-
45
- # Get information about locale.
46
- def [](name)
47
- case name
48
- when 'code'
49
- @code
50
- when 'title'
51
- @code
52
- else
53
- @base[name]
54
- end
55
- end
56
44
 
57
45
  # Locale RFC 3066 code.
58
46
  def code
@@ -64,7 +52,7 @@ module R18n
64
52
  @code
65
53
  end
66
54
 
67
- # Is another locale has same code
55
+ # Is another locale has same code.
68
56
  def ==(locale)
69
57
  @code.downcase == locale.code.downcase
70
58
  end
@@ -40,24 +40,25 @@ module R18n
40
40
  #
41
41
  # R18n::Filters.add(R18n::Untranslated, :hide_untranslated) { '' }
42
42
  class Untranslated
43
- # Path to translation.
44
- attr_reader :path
45
-
46
43
  # Path, that isn’t in translation.
47
44
  attr_reader :untranslated_path
48
45
 
49
46
  # Path, that exists in translation.
50
47
  attr_reader :translated_path
51
48
 
52
- def initialize(path, untranslated_path, locales)
53
- @path = path
54
- @locales = locales
49
+ def initialize(translated_path, untranslated_path, locale)
50
+ @translated_path = translated_path
55
51
  @untranslated_path = untranslated_path
56
- @translated_path = path[0...(-untranslated_path.length)]
52
+ @locale = locale
57
53
  end
58
54
 
59
- def nil?
60
- true
55
+ # Path to translation.
56
+ def path
57
+ "#{@translated_path}#{@untranslated_path}"
58
+ end
59
+
60
+ def translated?
61
+ false
61
62
  end
62
63
 
63
64
  def method_missing(*params)
@@ -65,16 +66,17 @@ module R18n
65
66
  end
66
67
 
67
68
  def [](*params)
68
- Untranslated.new("#{@path}.#{params.first}",
69
- "#{@untranslated_path}.#{params.first}", @locales)
69
+ Untranslated.new(translated_path, "#{@untranslated_path}.#{params.first}",
70
+ @locale)
71
+ end
72
+
73
+ def |(default)
74
+ default
70
75
  end
71
76
 
72
77
  def to_s
73
- config = OpenStruct.new(:locale => @locales.first, :path => @path,
74
- :locales => @locales)
75
- Filters.enabled[Untranslated].inject(@path) do |string, filter|
76
- filter.call(string, config, @translated_path, @untranslated_path, @path)
77
- end
78
+ Filters.process(Untranslated, path, @locale, path,
79
+ [@translated_path, @untranslated_path, path])
78
80
  end
79
81
  end
80
82
  end
@@ -21,18 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21
21
  # Common methods for another R18n code.
22
22
  module R18n
23
23
  module Utils
24
- # Recursively hash merge.
25
- def self.deep_merge!(a, b)
26
- b.each_pair do |name, value|
27
- if a[name].is_a? Hash
28
- self.deep_merge!(a[name], value)
29
- else
30
- a[name] = value
31
- end
32
- end
33
- a
34
- end
35
-
36
24
  # Convert Time to Date. Backport from Ruby 1.9.
37
25
  def self.to_date(time)
38
26
  jd = Date.send(:civil_to_jd, time.year, time.mon, time.mday, Date::ITALY)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module R18n
3
- VERSION = '0.3.2' unless defined? R18n::VERSION
3
+ VERSION = '0.4' unless defined? R18n::VERSION
4
4
  end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Loader for YAML translations.
4
+
5
+ Copyright (C) 2009 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Lesser General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General Public License
18
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ require 'yaml'
22
+
23
+ module R18n
24
+ module Loader
25
+ # Loader for translations in YAML format. Them should have name like
26
+ # +en.yml+ (English) or en-US.yml (USA English dialect) with
27
+ # language/country code (RFC 3066).
28
+ #
29
+ # R18n::I18n.new('en', R18n::Loader::YAML.new('dir/with/translations'))
30
+ #
31
+ # YAML loader is default loader, so you can just set constructor parameter
32
+ # to <tt>R18n::I18n.new</tt>:
33
+ #
34
+ # R18n::I18n.new('en', 'dir/with/translations')
35
+ class YAML
36
+ # Dir with translations.
37
+ attr_reader :dir
38
+
39
+ # Create new loader for +dir+ with YAML translations.
40
+ def initialize(dir)
41
+ @dir = File.expand_path(dir)
42
+ end
43
+
44
+ # Array of locales, which has translations in +dir+.
45
+ def available
46
+ Dir.glob(File.join(@dir, '*.yml')).map do |i|
47
+ R18n::Locale.load(File.basename(i, '.yml'))
48
+ end
49
+ end
50
+
51
+ # Return Hash with translations for +locale+.
52
+ def load(locale)
53
+ ::YAML::load(IO.read(File.join(@dir, "#{locale.code.downcase}.yml")))
54
+ end
55
+
56
+ # YAML loader with same +dir+ will be have same +hash+.
57
+ def hash
58
+ self.class.hash + @dir.hash
59
+ end
60
+
61
+ # Is another +loader+ load YAML translations from same +dir+.
62
+ def ==(loader)
63
+ self.class == loader.class and self.dir == loader.dir
64
+ end
65
+ end
66
+ end
67
+ end
data/lib/r18n-core.rb CHANGED
@@ -31,18 +31,40 @@ require dir + 'translated_string'
31
31
  require dir + 'untranslated'
32
32
  require dir + 'filters'
33
33
  require dir + 'translation'
34
+ require dir + 'yaml_loader'
34
35
  require dir + 'i18n'
35
36
 
36
37
  module R18n
37
38
  class << self
38
39
  # Set I18n object to current thread.
39
- def set(i18n)
40
- Thread.current['i18n'] = i18n
40
+ def set(i18n = nil, &block)
41
+ if block_given?
42
+ @setter = block
43
+ @i18n = nil
44
+ else
45
+ @i18n = i18n
46
+ end
41
47
  end
42
48
 
43
49
  # Get I18n object for current thread.
44
50
  def get
45
- Thread.current['i18n']
51
+ @i18n ||= (@setter.call if @setter)
46
52
  end
53
+
54
+ # Default loader class, which will be used if you didn’t send loader to
55
+ # +I18n.new+ (object with +available+ and +load+ methods).
56
+ attr_accessor :default_loader
57
+
58
+ # Loaders with extension translations. If application translations with
59
+ # same locale isn’t exists, extension file willn’t be used.
60
+ attr_accessor :extension_places
61
+
62
+ # Hash of hash-like (see Moneta) object to store loaded translations.
63
+ attr_accessor :cache
47
64
  end
65
+
66
+ self.default_loader = R18n::Loader::YAML
67
+ self.extension_places = [
68
+ Loader::YAML.new(Pathname(__FILE__).dirname.expand_path + '../base')]
69
+ self.cache = {}
48
70
  end
data/locales/cs.rb CHANGED
@@ -1,21 +1,35 @@
1
+ # encoding: utf-8
1
2
  module R18n
2
- module Locales
3
- class Cs < R18n::Locale
4
- def pluralize(n)
5
- return 0 if n == 0
6
- # 0 - 0
7
- # 1 - 1
8
- # 2..4 - 2
9
- # n
3
+ class Locales::Cs < Locale
4
+ set :title => 'Český',
5
+ :sublocales => %w{cz sk en},
6
+
7
+ :wday_names => %w{Neděle Pondělí Úterý Středa Čtvrtek Pátek Sobota},
8
+ :wday_abbrs => %w{Ne Po Út St Čt Pá So},
9
+
10
+ :month_names => %w{Ledna Února Března Dubna Května Června Července Srpna
11
+ Září Října Listopadu Prosince},
12
+ :month_abbrs => %w{Led Úno Bře Dub Kvě Čer Čvc Srp Zář Říj Lis Pro},
13
+ :month_standalone => %w{Leden Únor Březen Duben Květen Červen Červenec
14
+ Srpen Září Říjen Listopad Prosinec},
15
+
16
+ :time_am => 'dop.',
17
+ :time_pm => 'odp.',
18
+ :date_format => '%d.%m.%Y',
19
+
20
+ :number_decimal => ",",
21
+ :number_group => " "
10
22
 
11
- case n
12
- when 1
13
- 1
14
- when 2..4
15
- 2
16
- else
17
- 'n'
18
- end
23
+ def pluralize(n)
24
+ case n
25
+ when 0
26
+ 0
27
+ when 1
28
+ 1
29
+ when 2..4
30
+ 2
31
+ else
32
+ 'n'
19
33
  end
20
34
  end
21
35
  end
data/locales/de.rb ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::De < Locale
4
+ set :title => 'Deutsch',
5
+
6
+ :wday_names => %w{Sonntag Montag Dienstag Mittwoch Donnerstag Freitag
7
+ Samstag},
8
+ :wday_abbrs => %w{So Mo Di Mi Do Fr Sa},
9
+
10
+ :month_names => %w{Januar Februar März April Mai Juni Juli August
11
+ September Oktober November Dezember},
12
+ :month_abbrs => %w{Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez},
13
+
14
+ :time_am => 'vormittags',
15
+ :time_pm => 'nachmittags',
16
+ :date_format => '%d.%m.%Y',
17
+
18
+ :number_decimal => ",",
19
+ :number_group => "."
20
+ end
21
+ end
data/locales/en-us.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  require File.join(File.dirname(__FILE__), 'en')
2
2
 
3
- module R18n
4
- module Locales
5
- class EnUs < En
6
- end
3
+ module R18n::Locales
4
+ class EnUs < En
5
+ set :title => 'English (US)',
6
+ :code => 'en-US',
7
+ :sublocales => %w{en},
8
+
9
+ :time_format => ' %I:%M %p',
10
+ :date_format => '%m/%d/%Y',
11
+ :full_format => '%B %e'
7
12
  end
8
13
  end
data/locales/en.rb CHANGED
@@ -1,26 +1,41 @@
1
1
  module R18n
2
- module Locales
3
- class En < R18n::Locale
4
- def ordinalize(n)
5
- if (11..13).include?(n % 100)
6
- "#{n}th"
7
- else
8
- case n % 10
9
- when 1; "#{n}st"
10
- when 2; "#{n}nd"
11
- when 3; "#{n}rd"
12
- else "#{n}th"
13
- end
2
+ class Locales::En < Locale
3
+ set :title => 'English',
4
+ :sublocales => [],
5
+
6
+ :week_start => :sunday,
7
+ :wday_names => %w{Sunday Monday Tuesday Wednesday Thursday Friday
8
+ Saturday},
9
+ :wday_abbrs => %w{Sun Mon Tue Wed Thu Fri Sat},
10
+
11
+ :month_names => %w{January February March April May June July August
12
+ September October November December},
13
+ :month_abbrs => %w{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec},
14
+
15
+ :date_format => '%d/%m/%Y',
16
+ :full_format => '%e of %B',
17
+ :year_format => '_, %Y',
18
+
19
+ :number_decimal => ".",
20
+ :number_group => ","
21
+
22
+ def ordinalize(n)
23
+ if (11..13).include?(n % 100)
24
+ "#{n}th"
25
+ else
26
+ case n % 10
27
+ when 1; "#{n}st"
28
+ when 2; "#{n}nd"
29
+ when 3; "#{n}rd"
30
+ else "#{n}th"
14
31
  end
15
32
  end
16
-
17
- def format_date_full(i18n, date, year = true)
18
- format = @data['time']['full']
19
- if year
20
- format = @data['time']['year'].sub('_', format)
21
- end
22
- strftime(date, format.sub('%e', ordinalize(date.mday)))
23
- end
33
+ end
34
+
35
+ def format_date_full(date, year = true, *params)
36
+ format = full_format
37
+ format = year_format.sub('_', format) if year
38
+ strftime(date, format.sub('%e', ordinalize(date.mday)))
24
39
  end
25
40
  end
26
41
  end
data/locales/eo.rb ADDED
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::Eo < Locale
4
+ set :title => 'Esperanto',
5
+
6
+ :wday_names => %w{dimanĉo lundo mardo merkredo ĵaŭdo vendredo sabato},
7
+ :wday_abbrs => %w{dim lun mar mer ĵaŭ ven seb},
8
+
9
+ :month_names => %w{januaro februaro marto aprilo majo junio julio
10
+ aŭgusto septembro oktobro novembro decembro},
11
+ :month_abbrs => %w{jan feb mar apr maj jun jul aŭg sep okt nov dec},
12
+
13
+ :date_format => '%Y-%m-%d',
14
+ :full_format => 'la %e-a de %B',
15
+ :year_format => '_ de %Y',
16
+
17
+ :number_decimal => ".",
18
+ :number_group => " "
19
+ end
20
+ end
data/locales/es.rb ADDED
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module R18n
3
+ class Locales::Es < Locale
4
+ set :title => 'Español',
5
+
6
+ :wday_names => %w{domingo lunes martes miércoles jueves viernes sábado},
7
+ :wday_abbrs => %w{dom lun mar mie jue mie sab},
8
+
9
+ :month_names => %w{Enero Febrero Marzo Abril Mayo Junio Julio Agosto
10
+ Septiembre Octubre Noviembre Diciembre},
11
+ :month_abbrs => %w{ene feb mar abr may jun jul ago sep oct nov dic},
12
+
13
+ :date_format => '%d/%m/%Y',
14
+ :full_format => '%d de %B',
15
+ :year_format => '_ de %Y',
16
+
17
+ :number_decimal => ",",
18
+ :number_group => "."
19
+ end
20
+ end
data/locales/fr.rb CHANGED
@@ -1,13 +1,28 @@
1
+ # encoding: utf-8
1
2
  module R18n
2
- module Locales
3
- class Fr < R18n::Locale
4
- def format_date_full(i18n, date, year = true)
5
- full = super(i18n, date, year)
6
- if ' 1' == full[0..1]
7
- '1er' + full[2..-1]
8
- else
9
- full
10
- end
3
+ class Locales::Fr < Locale
4
+ set :title => 'Français',
5
+
6
+ :wday_names => %w{dimanche lundi mardi mercredi jeudi vendredi samedi},
7
+ :wday_abbrs => %w{dim lun mar mer jeu ven sam},
8
+
9
+ :month_names => %w{janvier février mars avril mai juin juillet août
10
+ septembre octobre novembre décembre},
11
+ :month_abbrs => %w{jan fév mar avr mai jun jui aoû sep oct nov déc},
12
+ :month_standalone => %w{Janvier Février Mars Avril Mai Juin Juillet Août
13
+ Septembre Octobre Novembre Décembre},
14
+
15
+ :date_format => '%d/%m/%Y',
16
+
17
+ :number_decimal => ",",
18
+ :number_group => " "
19
+
20
+ def format_date_full(date, year = true, *params)
21
+ full = super(date, year)
22
+ if ' 1' == full[0..1]
23
+ '1er' + full[2..-1]
24
+ else
25
+ full
11
26
  end
12
27
  end
13
28
  end