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

Full support for Brazilian Portuguese #139

Merged
merged 6 commits into from Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
## 0.10.6 (Next)

* Add full support for Brazilian Portuguese. \[[#139](https://github.com/kslazarev/numbers_and_words/pull/139)\]

### Features
* Your contribution here.
* Add option `precision` to `to_words`. \[[#134](https://github.com/kslazarev/numbers_and_words/issues/134)\] \([@neodelf](https://github.com/neodelf)\) \(assignee: [@neodelf](https://github.com/neodelf)\)
Expand Down
13 changes: 13 additions & 0 deletions README.rdoc
Expand Up @@ -16,6 +16,8 @@ Számok betűvel írva az I18n könyvtár segítségével.

I18n kütüphanesi ile sayıları yazıya çevirir.

Converte números em letras utilizando a biblioteca I18n.

== Supported Languages / Языки / Langues Supportées

* English [en]
Expand All @@ -34,6 +36,8 @@ I18n kütüphanesi ile sayıları yazıya çevirir.
* Nederlands** [nl]
* Swedish** [se]
* English (British)** [en-GB]
* Português [pt]
* Português Brasileiro [pt-BR]

** Experimental

Expand Down Expand Up @@ -90,6 +94,7 @@ I18n kütüphanesi ile sayıları yazıya çevirir.
=> "ventiuno"
=> "éénentwintig"
=> "tjugo-en"
=> "vinte e um"

231.to_words
=> "two hundred thirty-one"
Expand All @@ -107,6 +112,7 @@ I18n kütüphanesi ile sayıları yazıya çevirir.
=> "2 cento trentauno"
=> "tweehonderdéénendertig"
=> "två hundra trettio-en"
=> "duzentos e trinta e um"

4030.to_words
=> "four thousand thirty"
Expand Down Expand Up @@ -241,6 +247,13 @@ I18n kütüphanesi ile sayıları yazıya çevirir.
I18n.with_locale(:hu) { 21.to_words ordinal: true }
=> "huszonegyedik"

* Brazilian Portuguese

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

I18n.with_locale(:'pt-BR') { 1000000001.to_words gender: :female }
=> "um bilhão e uma"

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

* precision
Expand Down
13 changes: 13 additions & 0 deletions lib/numbers_and_words/helper_classes/array_extensions/helpers.rb
Expand Up @@ -23,6 +23,19 @@ def number_in_capacity capacity
figures_array_in_capacity(capacity).reverse.join.to_i
end

def number_under_capacity capacity
figures_array_under_capacity(capacity).reverse.join.to_i
end

def is_opaque? capacity
figures_under = figures_array_under_capacity(capacity)
figures_under.count(0) == figures_under.length
end

def figures_array_under_capacity capacity
self[0..(capacity * FIGURES_IN_CAPACITY) - ONES_SHIFT]
end

def ones
self[0].to_i if 0 < self[0].to_i
end
Expand Down
92 changes: 92 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.pt-BR.yml
@@ -0,0 +1,92 @@
pt-BR:
numbers:
union: e
union_separator: e
integral:
one: inteiro
other: inteiros
ones:
male: [zero, um, dois, três, quatro, cinco, seis, sete, oito, nove]
female: [zero, uma, duas, três, quatro, cinco, seis, sete, oito, nove]
ones_twenties: [zero, um, dois, três, quatro, cinco, seis, sete, oito, nove]
one: um
teens: [dez, onze, doze, treze, quatorze, quinze, dezesseis, dezessete, dezoito, dezenove]
tens: [zero, dez, vinte, trinta, quarenta, cinquenta, sessenta, setenta, oitenta, noventa]
hundreds:
male: [cento, duzentos, trezentos, quatrocentos, quinhentos, seiscentos, setecentos, oitocentos, novecentos]
female: [cento, duzentas, trezentas, quatrocentas, quinhentas, seiscentas, setecentas, oitocentas, novecentas]
one_hundred: cem
mega: [_, mil, milhão, bilhão, trilhão, quadrilhão, quintilhão, sextilhão, septilhão, octilhão, nonilhão, decilhão]
megas: [_, mil, milhões, bilhões, trilhões, quadrilhões, quintilhões, sextilhões, septilhões, octilhões, nonilhões, decilhões]
ordinal:
ones:
male: [zero, primeiro, segundo, terceiro, quarto, quinto, sexto, sétimo, oitavo, nono]
female: [zera, primeira, segunda, terceira, quarta, quinta, sexta, sétima, oitava, nona]
tens:
male: [_, décimo, vigésimo, trigésimo, quadragésimo, quinquagésimo, sexagésimo, septuagésimo, octogésimo, nonagésimo]
female: [_, décima, vigésima, trigésima, quadragésima, quinquagésima, sexagésima, septuagésima, octogésima, nonagésima]
hundreds:
male: [centésimo, ducentésimo, trecentésimo, quadringentésimo, quingentésimo, sexcentésimo, septingentésimo, octingentésimo, noningentésimo]
female: [centésima, ducentésima, trecentésima, quadringentésima, quingentésima, sexcentésima, septingentésima, octingentésima, noningentésima]
mega:
male: [_, milésimo, milionésimo, bilionésimo, trilionésimo, quadrilionésimo, sextilionésimo, septilionésimo, octilionésimo, nonilionésimo]
female: [_, milésima, milionésima, bilionésima, trilionésima, quadrilionésima, sextilionésima, septilionésima, octilionésima, nonilionésima]
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths, undecillionths, duodecillionths, tredecillionths, quattuordecillionths]
micro_prefix:
tens:
one: décimo
other: décimos
hundreds:
one: centésimo
other: centésimos
tenths:
one: décimo
other: décimos
hundredths:
one: centésimo
other: centésimos
thousandths:
one: milésimo
other: milésimos
millionths:
one: milionésimo
other: milionésimos
billionths:
one: bilionésimo
other: bilionésimos
trillionths:
one: trilionésimo
other: trilionésimo
quadrillionths:
one: quadrilionésimo
other: quadrilionésimos
quintillionths:
one: quintilionésimo
other: quintilionésimos
sextillionths:
one: sextilionésimo
other: sextilionésimos
septillionths:
one: septilionésimo
other: septilionésimos
octillionths:
one: octilionésimo
other: octilionésimos
nonillionths:
one: nonilionésimo
other: nonilionésimos
decillionths:
one: decilionésimo
other: decilionésimos
undecillionths:
one: undecilionésimo
other: undecilionésimos
duodecillion:
one: duodecilionésimo
other: duodecilionésimos
tredecillion:
one: trecentilionésimo
other: trecentilionésimos
quattuordecillion:
one: quadringentilionésimo
other: quadringentilionésimos
1 change: 1 addition & 0 deletions lib/numbers_and_words/i18n/pluralization.rb
Expand Up @@ -3,6 +3,7 @@
require 'numbers_and_words/i18n/plurals/fr'
require 'numbers_and_words/i18n/plurals/lv'
require 'numbers_and_words/i18n/plurals/lt'
require 'numbers_and_words/i18n/plurals/pt_br'

module NumbersAndWords
module I18n
Expand Down
2 changes: 1 addition & 1 deletion lib/numbers_and_words/i18n/plurals/plurals.rb
@@ -1,7 +1,7 @@
Hash[
NumbersAndWords::I18n::Pluralization.languages.map { |language|
[language.to_sym, {:i18n => {:plural => {
:rule => "NumbersAndWords::I18n::Plurals::#{language.titleize}::RULE".constantize
:rule => "NumbersAndWords::I18n::Plurals::#{language.titleize.gsub(/ /, '')}::RULE".constantize
}}}]
}
]
15 changes: 15 additions & 0 deletions lib/numbers_and_words/i18n/plurals/pt_br.rb
@@ -0,0 +1,15 @@
module NumbersAndWords
module I18n
module Plurals
module PtBr
RULE = lambda { |n| one_conditions(n) ? :one : :other }

extend self

def one_conditions n
n == 1
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/numbers_and_words/strategies/array_joiner/languages.rb
Expand Up @@ -7,6 +7,7 @@
require 'numbers_and_words/strategies/array_joiner/languages/hu'
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'

module NumbersAndWords
module Strategies
Expand All @@ -20,4 +21,4 @@ def factory strategy
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages/pt_br.rb
@@ -0,0 +1,10 @@
module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class PtBr < Base
end
end
end
end
end
Expand Up @@ -2,6 +2,7 @@
require 'numbers_and_words/strategies/figures_converter/decorators/en'
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb'
require 'numbers_and_words/strategies/figures_converter/decorators/ru'
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'

Expand Down Expand Up @@ -33,4 +34,4 @@ def decorator_class_name method_name
end
end
end
end
end
@@ -0,0 +1,3 @@
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/base'
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/integral'
require 'numbers_and_words/strategies/figures_converter/decorators/pt_br/fractional'
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module PtBr
class Base < Decorators::Base
end
end
end
end
end
end
@@ -0,0 +1,38 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module PtBr
class Fractional < Base

def run
"#{super} #{fraction_significance}"
end

private

def fraction_significance
@strategy.translations.micros full_fraction.fraction_capacity, figures.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.reverse
end

def zero_length
fraction_length - figures.length
end

def fraction_length
@options[:fractional][:length].to_i
end
end
end
end
end
end
end
@@ -0,0 +1,29 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module PtBr
class Integral < Base
def run
"#{super}#{integral_significance}"
end

private

def integral_significance
" #{@strategy.translations.integral quantity}" if @options[:remove_zero].nil?
end

def quantity
figures.reverse.join.to_i
end

def figures
@strategy.language.figures
end
end
end
end
end
end
end
Expand Up @@ -24,6 +24,7 @@
require 'numbers_and_words/strategies/figures_converter/languages/ru'
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/ka'

Expand Down