Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality for spanish #51

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
es:
numbers:
ones: [cero, uno, dos, tres, cuatro, cinco, seis, siete, ocho, nueve]
one: un

teens: [diez, once, doce, trece, catorce, quince, dieciseis, diecisiete, dieciocho, diecinueve]
tens: [cero, diez, veinti, treinta, cuarenta, cincuenta, sesenta, setenta, ochenta, noventa]
twenty: veinte

hundreds: [ciento, doscientos, trescientos, cuatrocientos, quinientos, seiscientos, setecientos, ochocientos, novecientos]
one_hundred: cien

mega: [ones, mil, millón, millardo, billón, billardo, trillón, trillardo, quadrillón, quadrillardo, quintillón, quintillardo]
megas: [ones, mil, millones, millardos, billones, billardos, trillones, trillardos, quadrillones, quadrillardos, quintillones, quintillardos]

1 change: 1 addition & 0 deletions lib/numbers_and_words/strategies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
require 'numbers_and_words/strategies/nl'
require 'numbers_and_words/strategies/it'
require 'numbers_and_words/strategies/hu'
require 'numbers_and_words/strategies/es'
38 changes: 38 additions & 0 deletions lib/numbers_and_words/strategies/es.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module NumbersAndWords
module Strategies
class Es < Base
include Families::Latin
include NumbersAndWords::TranslationsHelpers::Es

def hundreds_number_to_words
is_hundred = figures[1,2]==[0,1] && simple_number_to_words.empty?
simple_number_to_words + [translation_hundreds( figures.hundreds, is_hundred )]
end

def hundreds_number_to_words_old
simple_number_to_words + [translation_hundreds( figures.hundreds, simple_number_to_words.empty? )]
end

def capacity_iteration capacity
words = []
capacity_words = words_in_capacity( capacity )
t_ones_1 = t(:ones)[1]

words.push( translation_megs( capacity, capacity_words == [t_ones_1] )) unless capacity_words.empty?

if capacity > 0
# eg 1000000 should be "un millon" not "uno millon"
# 501000 should be "quinientos un mil" not "quinientos uno mil"
# so we replace "uno" with "un" throughout
t_one = t(:one)
capacity_words = capacity_words.map{|word| word.gsub( t_ones_1, t_one ) }
end

words + capacity_words
end

end

end

end
1 change: 1 addition & 0 deletions lib/numbers_and_words/translations_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
require 'numbers_and_words/translations_helpers/nl'
require 'numbers_and_words/translations_helpers/it'
require 'numbers_and_words/translations_helpers/hu'
require 'numbers_and_words/translations_helpers/es'
33 changes: 33 additions & 0 deletions lib/numbers_and_words/translations_helpers/es.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module NumbersAndWords
module TranslationsHelpers
module Es
include NumbersAndWords::TranslationsHelpers::Base
include NumbersAndWords::TranslationsHelpers::Families::Latin

TENS_CASE = 2

def translation_ones number
t(:ones)[number]
end

def translation_tens( numbers, alone=true )
(numbers == TENS_CASE && alone) ? t(:twenty) : super( numbers )
end

def translation_tens_with_ones numbers
inter = numbers[1]==TENS_CASE ? "" : " y "
[translation_tens(numbers[1], false), translation_ones(numbers[0])].join( inter )
end

def translation_hundreds number, is_100=false
is_100 ? t(:one_hundred) : t(:hundreds)[number-1]
end

def translation_megs capacity, is_one=false
is_one ? t(:mega)[capacity] : t(:megas)[capacity]
end

end

end
end
19 changes: 19 additions & 0 deletions spec/numbers_and_words/array/fixture_examples/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
to_words:
simple_example:
?
- 1
- 2
- 3
:
- uno
- dos
- tres
complex_example:
?
- 101
- 21
- 13
:
- ciento uno
- veintiuno
- trece
51 changes: 51 additions & 0 deletions spec/numbers_and_words/integer/fixture_examples/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
to_words:
ones:
0: cero
1: uno
9: nueve
teens:
10: diez
11: once
19: diecinueve
20: veinte
21: veintiuno
80: ochenta
90: noventa
99: noventa y nueve
hundreds:
100: cien
101: ciento uno
111: ciento once
120: ciento veinte
121: ciento veintiuno
900: novecientos
909: novecientos nueve
919: novecientos diecinueve
990: novecientos noventa
999: novecientos noventa y nueve
thousands:
1000: un mil
2000: dos mil
4000: cuatro mil
5000: cinco mil
11000: once mil
21000: veintiun mil
999000: novecientos noventa y nueve mil
999999: novecientos noventa y nueve mil novecientos noventa y nueve
millions:
1000000: un millón
2000000: dos millones
4000000: cuatro millones
5000000: cinco millones
999000000: novecientos noventa y nueve millones
999000999: novecientos noventa y nueve millones novecientos noventa y nueve
999999000: novecientos noventa y nueve millones novecientos noventa y nueve mil
999999999: novecientos noventa y nueve millones novecientos noventa y nueve mil novecientos noventa y nueve
billions:
1174315110: un millardo ciento setenta y cuatro millones trescientos quince mil ciento diez
1174315119: un millardo ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
15174315119: quince millardos ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
35174315119: treinta y cinco millardos ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
935174315119: novecientos treinta y cinco millardos ciento setenta y cuatro millones trescientos quince mil ciento diecinueve
trillions:
2935174315119: dos billones novecientos treinta y cinco millardos ciento setenta y cuatro millones trescientos quince mil ciento diecinueve