Module: Knj::Locales
- Defined in:
- lib/knj/locales.rb
Class Method Summary collapse
- .lang ⇒ Object
- .locale ⇒ Object
- .localeconv ⇒ Object
- .number_in(num_str) ⇒ Object
- .number_out(num_str, dec = 2) ⇒ Object
Class Method Details
.lang ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'lib/knj/locales.rb', line 2 def self.lang match = self.locale.to_s.match(/^([a-z]{2})_([A-Z]{2})/) raise "Could not understand language: #{self.locale}." if !match return { "first" => match[1], "second" => match[2], "full" => match[1] + "_" + match[2] } end |
.locale ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/knj/locales.rb', line 49 def self.locale begin return _session[:locale] rescue NameError if Thread.current[:locale] return Thread.current[:locale] elsif $locale return $locale elsif ENV["LANGUAGE"] return ENV["LANGUAGE"] end end raise "Could not figure out locale." end |
.localeconv ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/knj/locales.rb', line 13 def self.localeconv f = Knj::Locales.lang["first"] dec = "." thousand = "," csv_delimiter = "," case f when "da", "es", "de", "sv" dec = "," thousand = "." csv_delimiter = ";" when "en" #do nothing. else raise "Cant figure out numbers for language: #{f}." end return { "decimal_point" => dec, "thousands_sep" => thousand, "csv_delimiter" => csv_delimiter } end |
.number_in(num_str) ⇒ Object
38 39 40 41 42 |
# File 'lib/knj/locales.rb', line 38 def self.number_in(num_str) lc = Knj::Locales.localeconv num_str = num_str.to_s.gsub(lc["thousands_sep"], "").gsub(lc["decimal_point"], ".").to_f return num_str end |
.number_out(num_str, dec = 2) ⇒ Object
44 45 46 47 |
# File 'lib/knj/locales.rb', line 44 def self.number_out(num_str, dec = 2) lc = Knj::Locales.localeconv return Knj::Php.number_format(num_str, dec, lc["decimal_point"], lc["thousands_sep"]) end |