Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kslazarev committed Jun 24, 2012
2 parents 507df3a + 6f18014 commit 79c6ece
Show file tree
Hide file tree
Showing 40 changed files with 556 additions and 100 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,14 @@
## 0.3.2 (June 03, 2012) ## 0.4.0 (June 24, 2012)

### Features
* Add Turkish language. \[[#26](https://github.com/kslazarev/numbers_and_words/issues/26)\] \([@Shk-Serji](https://github.com/Shk-Serji)\)
* Add Ukrainian language. \[[#25](https://github.com/kslazarev/numbers_and_words/issues/25)\] \([@Shk-Serji](https://github.com/Shk-Serji)\)

### Supports
* Combine all connections with i18n library in one sub-module. \[[#28](https://github.com/kslazarev/numbers_and_words/issues/28)\] \([@kslazarev](https://github.com/kslazarev)\)
* Add separate logics for pluralization in different languages. \[[#27](https://github.com/kslazarev/numbers_and_words/issues/27)\] \([@kslazarev](https://github.com/kslazarev)\)

## 0.3.2 (June 24, 2012)


### Bugs ### Bugs
* Ломает плюрализацию russian. \[[#22](https://github.com/kslazarev/numbers_and_words/issues/22)\] \([@kslazarev](https://github.com/kslazarev)\) * Ломает плюрализацию russian. \[[#22](https://github.com/kslazarev/numbers_and_words/issues/22)\] \([@kslazarev](https://github.com/kslazarev)\)
Expand Down
17 changes: 16 additions & 1 deletion README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Convert numbers to words using the I18n library.


* English * English
* Русский * Русский
* Українська
* Türkçe


== Examples / Примеры == Examples / Примеры


Expand All @@ -20,22 +22,32 @@ Convert numbers to words using the I18n library.
21.to_words 21.to_words
=> "twenty-one" => "twenty-one"
=> "двадцать один" => "двадцать один"
=> "двадцять один"
=> "yirmi bir"


231.to_words 231.to_words
=> "two hundred thirty-one" => "two hundred thirty-one"
=> "двести тридцать один" => "двести тридцать один"
=> "двiстi тридцять один"
=> "iki yüz otuz bir"


4030.to_words 4030.to_words
=> "four thousand thirty" => "four thousand thirty"
=> "четыре тысячи тридцать" => "четыре тысячи тридцать"
=> "чотири тисячi тридцять"
=> "dört bin otuz"


1000100.to_words 1000100.to_words
=> "one million one hundred" => "one million one hundred"
=> "один миллион сто" => "один миллион сто"
=> "один мiльйон сто"
=> "bir milyon bir yüz"


1000000000000000000000000000000000.to_words 1000000000000000000000000000000000.to_words
=> "one decillion" => "one decillion"
=> "один дециллион" => "один дециллион"
=> "один децильйон"
=> "bir desilyon"


[1, 2, 3].to_words [1, 2, 3].to_words
=> ["one", "two", "three"] => ["one", "two", "three"]
Expand All @@ -44,7 +56,9 @@ Convert numbers to words using the I18n library.
[11, 22, 133].to_words [11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"] => ["eleven", "twenty-two", "one hundred thirty-three"]
=> ["одиннадцать", "двадцать два", "сто тридцать три"] => ["одиннадцать", "двадцать два", "сто тридцать три"]

=> ["одинадцять", "двадцять два", "сто тридцять три"]
=> ["on bir", "yirmi iki", "bir yüz otuz üç"]

== Requirements / Требования == Requirements / Требования


* 1.8.7 <= Ruby (compatible with/совместимость с Ruby 1.9, JRuby and/и Rubinius); * 1.8.7 <= Ruby (compatible with/совместимость с Ruby 1.9, JRuby and/и Rubinius);
Expand All @@ -70,3 +84,4 @@ Send a pull request. Bonus points for topic branches.


* Kirill Lazarev (mailto:k.s.lazarev@gmail.com) * Kirill Lazarev (mailto:k.s.lazarev@gmail.com)
* Daniel Doubrovkine (link:http://github.com/dblock) * Daniel Doubrovkine (link:http://github.com/dblock)
* Sergey Shkirando (mailto:shkirando.s@yandex.ru)
2 changes: 0 additions & 2 deletions lib/initializers/i18n.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/locales/plurals.rb

This file was deleted.

26 changes: 5 additions & 21 deletions lib/numbers_and_words.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,30 +1,14 @@
require 'rubygems' require 'rubygems'
require 'i18n' require 'i18n'
require 'initializers/i18n' require 'i18n/backend/pluralization'
require 'active_support/inflector' require 'active_support/inflector'


require 'numbers_and_words/version'

require 'numbers_and_words/translations_helpers' require 'numbers_and_words/translations_helpers'
require 'numbers_and_words/strategies' require 'numbers_and_words/strategies'
require 'numbers_and_words/array_additions' require 'numbers_and_words/array_additions'
require 'numbers_and_words/figures_array' require 'numbers_and_words/figures_array'
require 'numbers_and_words/core_ext'
require 'numbers_and_words/i18n'
require 'numbers_and_words/version'


require 'numbers_and_words/core_ext/integer' NumbersAndWords::I18n::Initialization.init
require 'numbers_and_words/core_ext/array'

module NumbersAndWords
module I18nInitialization
extend self

def init
locale_files.each { |locale_file| I18n.load_path << locale_file }
end

def locale_files
Dir[File.join(File.dirname(__FILE__), 'locales', '**/*')]
end
end
end

NumbersAndWords::I18nInitialization.init
2 changes: 2 additions & 0 deletions lib/numbers_and_words/core_ext.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'numbers_and_words/core_ext/integer'
require 'numbers_and_words/core_ext/array'
12 changes: 12 additions & 0 deletions lib/numbers_and_words/i18n.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'numbers_and_words/i18n/pluralization'
require 'numbers_and_words/i18n/initialization'

module NumbersAndWords
module I18n
extend self

def files directory, ext
Dir[File.join File.dirname(__FILE__), "i18n/#{directory}", "**/#{ext}"]
end
end
end
22 changes: 22 additions & 0 deletions lib/numbers_and_words/i18n/initialization.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,22 @@
module NumbersAndWords
module I18n
module Initialization
extend self

def init
locale_files.each { |locale_file| ::I18n.load_path << locale_file}
NumbersAndWords::I18n::Pluralization.init
end

private

def locale_files
I18n.files 'locales', '*.*'
end

def languages
locale_files.map{|path| path.split /[\/.]/}[-2]
end
end
end
end
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.tr.yml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
tr:
numbers:
ones: [sıfır, bir, iki, üç, dört, beş, altı, yedi, sekiz, dokuz]
teens: ['on', on bir, on iki, on üç, on dört, on beş, on altı, on yedi, on sekiz, on dokuz]
tens: [sıfır, 'on', yirmi, otuz, kırk, elli, altmış, yetmiş, seksen, doksan]
hundreds: yüz
mega: [bir, bin, milyon, milyar, trilyon, katrilyon, kentilyon, seksilyon, septilyon, oktilyon, nonilyon, desilyon]
52 changes: 52 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.ua.yml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,52 @@
ua:
numbers:
ones_male: [нуль, один, два, три, чотири, п’ять, шiсть, сiм, вiсiм, дев’ять]
ones_female: [нуль, однa, двi, три, чотири, п’ять, шiсть, сiм, вiсiм, дев’ять]
teens: [десять, одинадцять, дванадцять, тринадцять, чотирнадцять, п’ятнадцять, шiстнадцять, сiмнадцять, вiсiмнадцять, дев’ятнадцять]
tens: [нуль, десять, двадцять, тридцять, сорок, п’ятдесят, шiстдесят, сiмдесят, вiсiмдесят, дев’яносто]
hundreds: [нуль, сто, двiстi, триста, чотириста, п’ятсот, шiстсот, сiмсот, вiсiмсот, дев’ятсот]
thousands:
one: тисяча
few: тисячi
many: тисяч
millions:
one: мiльйон
few: мiльйона
many: мiльйонiв
billions:
one: мiльярд
few: мiльярда
many: мiльярдiв
trillions:
one: трильйон
few: трильйона
many: трильйонiв
quadrillions:
one: квадрильйон
few: квадрильйона
many: квадрильйонiв
quintillions:
one: квiнтильйон
few: квiнтильйона
many: квiнтильйонiв
sextillions:
one: секстильйон
few: секстильйона
many: секстильйонiв
septillions:
one: септильйон
few: септильйона
many: септильйонiв
octillions:
one: октильйон
few: октильйона
many: октильйонiв
nonillions:
one: нонильйон
few: нонильйона
many: нонильйонiв
decillions:
one: децильйон
few: децильйона
many: децильйонiв
mega: [ones, thousands, millions, billions, trillions, quadrillions, quintillion, sextillions, septillions, octillions, nonillions, decillions]
31 changes: 31 additions & 0 deletions lib/numbers_and_words/i18n/pluralization.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'numbers_and_words/i18n/plurals/ru'
require 'numbers_and_words/i18n/plurals/ua'

module NumbersAndWords
module I18n
module Pluralization
extend self

def init
::I18n.load_path << config_file
::I18n::Backend::Simple.send :include, ::I18n::Backend::Pluralization
end

def files
I18n.files 'plurals', '*.*'
end

def config_file
I18n.files('plurals', 'plurals.rb').first
end

def plurals_files
files - [config_file]
end

def languages
plurals_files.map{|path| path.split(/[\/.]/)[-2]}
end
end
end
end
7 changes: 7 additions & 0 deletions lib/numbers_and_words/i18n/plurals/plurals.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
Hash[
NumbersAndWords::I18n::Pluralization.languages.map { |language|
[language.to_sym, {:i18n => {:plural => {
:rule => "NumbersAndWords::I18n::Plurals::#{language.titleize}::RULE".constantize
}}}]
}
]
28 changes: 28 additions & 0 deletions lib/numbers_and_words/i18n/plurals/ru.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
module NumbersAndWords
module I18n
module Plurals
module Ru
RULE = lambda do |n|
one_conditions(n) ?
:one : few_conditions(n) ?
:few : many_conditions(n) ?
:many : :other
end

extend self

def one_conditions n
n % 10 == 1 && n % 100 != 11
end

def few_conditions n
[2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100)
end

def many_conditions n
n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100)
end
end
end
end
end
9 changes: 9 additions & 0 deletions lib/numbers_and_words/i18n/plurals/ua.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
module NumbersAndWords
module I18n
module Plurals
module Ua
RULE = Ru::RULE
end
end
end
end
2 changes: 0 additions & 2 deletions lib/numbers_and_words/pluralization.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/numbers_and_words/strategies.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'numbers_and_words/strategies/base' require 'numbers_and_words/strategies/base'
require 'numbers_and_words/strategies/ru' require 'numbers_and_words/strategies/ru'
require 'numbers_and_words/strategies/en' require 'numbers_and_words/strategies/en'
require 'numbers_and_words/strategies/ua'
require 'numbers_and_words/strategies/tr'
2 changes: 1 addition & 1 deletion lib/numbers_and_words/strategies/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Base
attr_accessor :figures, :words attr_accessor :figures, :words


def self.factory def self.factory
"NumbersAndWords::Strategies::#{I18n.locale.to_s.titleize}".constantize.new "NumbersAndWords::Strategies::#{::I18n.locale.to_s.titleize}".constantize.new
end end
end end
end end
Expand Down
Loading

0 comments on commit 79c6ece

Please sign in to comment.