Permalink
Browse files

Merge branch 'release/0.4.0'

  • Loading branch information...
2 parents 507df3a + 6f18014 commit 79c6ece8a3289cf01fdcc13ca963cf0cd4d7e964 @kslazarev committed Jun 24, 2012
Showing with 556 additions and 100 deletions.
  1. +11 −1 CHANGELOG.md
  2. +16 −1 README.rdoc
  3. +0 −2 lib/initializers/i18n.rb
  4. +0 −23 lib/locales/plurals.rb
  5. +5 −21 lib/numbers_and_words.rb
  6. +2 −0 lib/numbers_and_words/core_ext.rb
  7. +12 −0 lib/numbers_and_words/i18n.rb
  8. +22 −0 lib/numbers_and_words/i18n/initialization.rb
  9. 0 lib/{ → numbers_and_words/i18n}/locales/numbers.en.yml
  10. 0 lib/{ → numbers_and_words/i18n}/locales/numbers.ru.yml
  11. +7 −0 lib/numbers_and_words/i18n/locales/numbers.tr.yml
  12. +52 −0 lib/numbers_and_words/i18n/locales/numbers.ua.yml
  13. +31 −0 lib/numbers_and_words/i18n/pluralization.rb
  14. +7 −0 lib/numbers_and_words/i18n/plurals/plurals.rb
  15. +28 −0 lib/numbers_and_words/i18n/plurals/ru.rb
  16. +9 −0 lib/numbers_and_words/i18n/plurals/ua.rb
  17. +0 −2 lib/numbers_and_words/pluralization.rb
  18. +2 −0 lib/numbers_and_words/strategies.rb
  19. +1 −1 lib/numbers_and_words/strategies/base.rb
  20. +71 −0 lib/numbers_and_words/strategies/tr.rb
  21. +6 −0 lib/numbers_and_words/strategies/ua.rb
  22. +1 −0 lib/numbers_and_words/translations_helpers.rb
  23. +1 −1 lib/numbers_and_words/translations_helpers/base.rb
  24. +41 −0 lib/numbers_and_words/translations_helpers/tr.rb
  25. +1 −1 lib/numbers_and_words/version.rb
  26. +15 −6 numbers_and_words.gemspec
  27. +18 −0 spec/numbers_and_words/array/tr_spec.rb
  28. +18 −0 spec/numbers_and_words/array/ua_spec.rb
  29. +2 −2 spec/numbers_and_words/{i18n_spec.rb → i18n/initialization_spec.rb}
  30. +24 −0 spec/numbers_and_words/i18n/pluralization/ru_spec.rb
  31. +4 −0 spec/numbers_and_words/i18n/pluralization_spec.rb
  32. +6 −13 spec/numbers_and_words/integer/en_spec.rb
  33. +51 −0 spec/numbers_and_words/integer/fixture_examples/tr.yml
  34. +50 −0 spec/numbers_and_words/integer/fixture_examples/ua.yml
  35. +5 −13 spec/numbers_and_words/integer/ru_spec.rb
  36. +0 −12 spec/numbers_and_words/integer/shared_examples/correct_examples.rb
  37. +16 −0 spec/numbers_and_words/integer/shared_examples/correct_fixture_examples.rb
  38. +10 −0 spec/numbers_and_words/integer/tr_spec.rb
  39. +10 −0 spec/numbers_and_words/integer/ua_spec.rb
  40. +1 −1 spec/support/helpers.rb
View
@@ -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
* Ломает плюрализацию russian. \[[#22](https://github.com/kslazarev/numbers_and_words/issues/22)\] \([@kslazarev](https://github.com/kslazarev)\)
View
@@ -8,6 +8,8 @@ Convert numbers to words using the I18n library.
* English
* Русский
+* Українська
+* Türkçe
== Examples / Примеры
@@ -20,22 +22,32 @@ Convert numbers to words using the I18n library.
21.to_words
=> "twenty-one"
=> "двадцать один"
+ => "двадцять один"
+ => "yirmi bir"
231.to_words
=> "two hundred thirty-one"
=> "двести тридцать один"
+ => "двiстi тридцять один"
+ => "iki yüz otuz bir"
4030.to_words
=> "four thousand thirty"
=> "четыре тысячи тридцать"
+ => "чотири тисячi тридцять"
+ => "dört bin otuz"
1000100.to_words
=> "one million one hundred"
=> "один миллион сто"
+ => "один мiльйон сто"
+ => "bir milyon bir yüz"
1000000000000000000000000000000000.to_words
=> "one decillion"
=> "один дециллион"
+ => "один децильйон"
+ => "bir desilyon"
[1, 2, 3].to_words
=> ["one", "two", "three"]
@@ -44,7 +56,9 @@ Convert numbers to words using the I18n library.
[11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"]
=> ["одиннадцать", "двадцать два", "сто тридцать три"]
-
+ => ["одинадцять", "двадцять два", "сто тридцять три"]
+ => ["on bir", "yirmi iki", "bir yüz otuz üç"]
+
== Requirements / Требования
* 1.8.7 <= Ruby (compatible with/совместимость с Ruby 1.9, JRuby and/и Rubinius);
@@ -70,3 +84,4 @@ Send a pull request. Bonus points for topic branches.
* Kirill Lazarev (mailto:k.s.lazarev@gmail.com)
* Daniel Doubrovkine (link:http://github.com/dblock)
+* Sergey Shkirando (mailto:shkirando.s@yandex.ru)
View
@@ -1,2 +0,0 @@
-require "i18n/backend/pluralization"
-I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
View
@@ -1,23 +0,0 @@
-module NumbersAndWords
- module Locales
- module Plurals
-
- RU = lambda do |n|
- n % 10 == 1 && n % 100 != 11 ?
- :one :
- [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100) ?
- :few :
- n % 10 == 0 || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100) ?
- :many : :other
- end
-
- EN = lambda { |count| 1 == count ? :one : :other }
-
- end
- end
-end
-
-{
- :ru => {:i18n => {:plural => {:rule => NumbersAndWords::Locales::Plurals::RU}}},
- :en => {:i18n => {:plural => {:rule => NumbersAndWords::Locales::Plurals::EN}}}
-}
View
@@ -1,30 +1,14 @@
require 'rubygems'
require 'i18n'
-require 'initializers/i18n'
+require 'i18n/backend/pluralization'
require 'active_support/inflector'
-require 'numbers_and_words/version'
-
require 'numbers_and_words/translations_helpers'
require 'numbers_and_words/strategies'
require 'numbers_and_words/array_additions'
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'
-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
+NumbersAndWords::I18n::Initialization.init
@@ -0,0 +1,2 @@
+require 'numbers_and_words/core_ext/integer'
+require 'numbers_and_words/core_ext/array'
@@ -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
@@ -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
@@ -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]
@@ -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]
@@ -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
@@ -0,0 +1,7 @@
+Hash[
+ NumbersAndWords::I18n::Pluralization.languages.map { |language|
+ [language.to_sym, {:i18n => {:plural => {
+ :rule => "NumbersAndWords::I18n::Plurals::#{language.titleize}::RULE".constantize
+ }}}]
+ }
+]
@@ -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
@@ -0,0 +1,9 @@
+module NumbersAndWords
+ module I18n
+ module Plurals
+ module Ua
+ RULE = Ru::RULE
+ end
+ end
+ end
+end
@@ -1,2 +0,0 @@
-require "i18n/backend/pluralization"
-I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
@@ -1,3 +1,5 @@
require 'numbers_and_words/strategies/base'
require 'numbers_and_words/strategies/ru'
require 'numbers_and_words/strategies/en'
+require 'numbers_and_words/strategies/ua'
+require 'numbers_and_words/strategies/tr'
@@ -4,7 +4,7 @@ class Base
attr_accessor :figures, :words
def self.factory
- "NumbersAndWords::Strategies::#{I18n.locale.to_s.titleize}".constantize.new
+ "NumbersAndWords::Strategies::#{::I18n.locale.to_s.titleize}".constantize.new
end
end
end
Oops, something went wrong.

0 comments on commit 79c6ece

Please sign in to comment.