Skip to content

Commit

Permalink
Czech language support fixed and improved (#148)
Browse files Browse the repository at this point in the history
* Czech Language Support
  • Loading branch information
foton authored and jlduran committed Aug 9, 2017
1 parent 3355822 commit 20a8ade
Show file tree
Hide file tree
Showing 28 changed files with 696 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features
* Your contribution here.
* Add full support for Czech language. \[[#148](https://github.com/kslazarev/numbers_and_words/pull/148)\]

## 0.11.1 (July 23, 2017)

Expand Down
41 changes: 41 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Converte números em letras utilizando a biblioteca I18n.
* Nederlands** [nl]
* Swedish** [se]
* English (British)** [en-GB]
* Česky [cs]
* Português [pt]
* Português Brasileiro [pt-BR]

Expand Down Expand Up @@ -78,6 +79,9 @@ Converte números em letras utilizando a biblioteca I18n.
I18n.with_locale(:ka) { 42.to_words }
=> "ორმოცდაორი"

I18n.with_locale(:cs) { 42.to_words }
=> "čtyřicetdva"

21.to_words
=> "twenty-one"
=> "veintiuno"
Expand All @@ -94,6 +98,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> "ventiuno"
=> "éénentwintig"
=> "tjugo-en"
=> "dvacetjedna"
=> "vinte e um"

231.to_words
Expand All @@ -112,6 +117,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> "2 cento trentauno"
=> "tweehonderdéénendertig"
=> "två hundra trettio-en"
=> "dvě stě třicetjedna"
=> "duzentos e trinta e um"

4030.to_words
Expand All @@ -130,6 +136,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> "quattro mille trenta"
=> "vierthousanddertig"
=> "fyra tusen trettio"
=> "čtyři tisíce třicet"

1000100.to_words
=> "one million one hundred"
Expand All @@ -147,6 +154,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> "uno milione 1 cento"
=> "één miljoen honderd"
=> "en miljoner en hundra"
=> "jeden milión jedno sto"

1000000000000000000000000000000000.to_words
=> "one decillion"
Expand All @@ -163,6 +171,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> "uno decillion"
=> "één decillion"
=> "en decillion"
=> "decilijon"

[1, 2, 3].to_words
=> ["one", "two", "three"]
Expand All @@ -174,6 +183,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> ["viens", "divi", "trīs"]
=> ["üks", "kaks", "kolm"]
=> ["ერთი", "ორი", "სამი"]
=> ["jedna", "dva", "tři"]

[11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"]
Expand All @@ -191,6 +201,7 @@ Converte números em letras utilizando a biblioteca I18n.
=> ["undici", "ventidue", "1 cento trentatre"]
=> ["elf", "tweeentwintig", "honderddrieendertig"]
=> ["elva", "tjugo-två", "en hundra trettio-tre"]
=> ["jedenáct", "dvacetdva", "jedno sto třicettři"]

21.77.to_words
=> "twenty-one and seventy-seven hundredths"
Expand Down Expand Up @@ -254,6 +265,36 @@ Converte números em letras utilizando a biblioteca I18n.
I18n.with_locale(:'pt-BR') { 1000000001.to_words gender: :female }
=> "um bilhão e uma"

* Czech

Change gender form: (gender: [:female || :male || :neuter])

I18n.with_locale(:'cs') { 1.to_words gender: :female }
=> "jedna"

I18n.with_locale(:'cs') { 1.to_words gender: :male }
=> "jeden"

I18n.with_locale(:'cs') { 1.to_words gender: :neuter }
=> "jedno"


Remove 'zero' from integral part of float: (remove_zero: [true || false])

I18n.with_locale(:cs) { 0.7.to_words }
=> "nula celých sedm desetin"

I18n.with_locale(:cs) { 0.7.to_words remove_zero: true }
=> "sedm desetin"

Ordinal form: (ordinal: [true || false])

I18n.with_locale(:cs) { 21.to_words ordinal: true }
=> "dvacátý první"

I18n.with_locale(:cs) { 21.to_words gender: :female, ordinal: true }
=> "dvacátá první"

== Other options / Другие опции

* precision
Expand Down
84 changes: 84 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cs:
numbers:
union: ''
union_separator: ''
integral: celých
ones:
male: [nula, jeden, dva, tři, čtyři, pět, šest, sedm, osm, devět]
female: [nula, jedna, dvě, tři, čtyři, pět, šest, sedm, osm, devět]
neuter: [nula, jedno, dvě, tři, čtyři, pět, šest, sedm, osm, devět]
teens: [deset, jedenáct, dvanáct, třináct, čtrnáct, patnáct, šestnáct, sedmnáct, osmnáct, devatenáct]
tens: [_, deset, dvacet, třicet, čtyřicet, padesát, šedesát, sedmdesát, osmdesát, devadesát]
hundreds: [_, jedno sto, dvě stě, tři sta, čtyři sta, pět set, šest set, sedm set, osm set, devět set]
# gem pouziva se deleni po 10^3, http://www.converter.cz/prevody/velka-cisla.htm
# mega: [ones, thousands, miliony, miliardy, biliony, biliardy, triliony, triliardy, quadriliony, quadriliardy]
micro:
one: [_, desetina, setina, tisícina, milióntina, miliardtina, bilióntina]
few: [_, desetiny, setiny, tisíciny, milióntiny, miliardtiny, bilióntiny]
many: [_, desetin, setin, tisícin, milióntin, miliardtin, bilióntin]
sub_micro: [_, deseti, sto]
thousands:
one: tisíc
few: tisíce
many: tisíc
millions:
one: milión
few: milióny
many: miliónů
billions:
one: miliarda
few: miliardy
many: miliard
trillions:
one: bilion
few: biliony
many: bilionů
quadrillions:
one: biliarda
few: biliardy
many: biliard
quintillion:
one: trilion
few: triliony
many: trilionů
sextillions:
one: triliarda
few: triliardy
many: triliard
septillions:
one: kvadrilion
few: kvadriliony
many: kvadrilionů
octillions:
one: kvadriliarda
few: kvadriliardy
many: kvadriliard
mega:
- ones
- thousands
- millions
- billions
- trillions
- quadrillions
- quintillion
- sextillions
- septillions
- octillions
ordinal:
ones:
male: [nultý, první, druhý, třetí, čtvrtý, pátý, šestý, sedmý, osmý, devátý]
female: [nultá, první, druhá, třetí, čtvrtá, pátá, šestá, sedmá, osmá, devátá]
neuter: [nulté, první, druhé, třetí, čtvrté, páté, šesté, sedmé, osmé, deváté]
teens:
male: [desátý, jedenáctý, dvanáctý, třináctý, čtrnáctý, patnáctý, šestnáctý, sedmnáctý, osmnáctý, devatenáctý]
female: [desátá, jedenáctá, dvanáctá, třináctá, čtrnáctá, patnáctá, šestnáctá, sedmnáctá, osmnáctá, devatenáctá]
neuter: [desáté, jedenácté, dvanácté, třinácté, čtrnácté, patnácté, šestnácté, sedmnácté, osmnácté, devatenácté]
tens:
male: [_, desátý, dvacátý, třicátý, čtyřicátý, padesátý, šedesátý, sedmdesátý, osmdesátý, devadesátý]
female: [_, desátá, dvacátá, třicátá, čtyřicátá, padesátá, šedesátá, sedmdesátá, osmdesátá, devadesátá]
neuter: [_, desáté, dvacáté, třicáté, čtyřicáté, padesáté, šedesáté, sedmdesáté, osmdesáté, devadesáté]
hundreds:
male: [_, stý, dvoustý, třístý, čtyřstý, pětistý, šestistý, sedmistý, osmistý, devítistý]
female: [_, stá, dvoustá, třístá, čtyřstá, pětistá, šestistá, sedmistá, osmistá, devítistá]
neuter: [_, sté, dvousté, třísté, čtyřsté, pětisté, šestisté, sedmisté, osmisté, devítisté]

1 change: 1 addition & 0 deletions lib/numbers_and_words/i18n/pluralization.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'numbers_and_words/i18n/plurals/cs'
require 'numbers_and_words/i18n/plurals/ru'
require 'numbers_and_words/i18n/plurals/ua'
require 'numbers_and_words/i18n/plurals/fr'
Expand Down
33 changes: 33 additions & 0 deletions lib/numbers_and_words/i18n/plurals/cs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module NumbersAndWords
module I18n
module Plurals
module Cs
module_function

RULE = lambda do |n|
if one_conditions(n)
:one
elsif few_conditions(n)
:few
elsif many_conditions(n)
:many
else
:other
end
end

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).zero? || [5, 6, 7, 8, 9].include?(n % 10) || [11, 12, 13, 14].include?(n % 100)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'numbers_and_words/strategies/array_joiner/languages/ru'
require 'numbers_and_words/strategies/array_joiner/languages/ua'
require 'numbers_and_words/strategies/array_joiner/languages/pt-BR'
require 'numbers_and_words/strategies/array_joiner/languages/cs'

module NumbersAndWords
module Strategies
Expand Down
10 changes: 10 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages/cs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class Cs < Base
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'numbers_and_words/strategies/figures_converter/decorators/pt-BR'
require 'numbers_and_words/strategies/figures_converter/decorators/hu'
require 'numbers_and_words/strategies/figures_converter/decorators/ua'
require 'numbers_and_words/strategies/figures_converter/decorators/cs'

module NumbersAndWords
module Strategies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/decorators/cs/base'
require 'numbers_and_words/strategies/figures_converter/decorators/cs/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/cs/integral'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Cs
class Base < Decorators::Base
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Cs
class Fractional < Base
def run
@options[:gender] = :female
"#{super} #{fraction_significance}"
end

private

def fraction_significance
@strategy.translations.micros full_fraction.fraction_capacity, figures.reverse.join.to_i
end

def full_fraction
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift '0' }.to_figures
end

def figures
@strategy.figures
end

def zero_length
fraction_length - figures.length
end

def fraction_length
@options[:fractional][:length].to_i
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Cs
class Integral < Base
def run
@options[:gender] = :female
[super, integral_significance].compact.join(' ')
end

private

def integral_significance
figs = figures.reverse.join.to_i
return nil if @options[:remove_zero] && figs.zero?
@strategy.translations.integral figs
end

def figures
@strategy.language.figures
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'numbers_and_words/strategies/figures_converter/languages/ua'
require 'numbers_and_words/strategies/figures_converter/languages/pt'
require 'numbers_and_words/strategies/figures_converter/languages/pt-BR'
require 'numbers_and_words/strategies/figures_converter/languages/cs'

require 'numbers_and_words/strategies/figures_converter/languages/ka'

Expand Down
Loading

0 comments on commit 20a8ade

Please sign in to comment.