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

feat: ✨ support for polish language #189

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.11.12 wasn't released, move your feature to the section below


### Features
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go under Next below, that's our unreleased.

* Add polish language support \[[#189](https://github.com/kslazarev/numbers_and_words/pull/189)\]

## 0.11.12 (Next)

### Features
Expand Down
27 changes: 27 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Soletra números em vários idiomas utilizando a biblioteca I18n.

Deletrea números en varios idiomas utilizando la gema I18n.

Przeliteruj liczby w kilku językach za pomocą gemu I18n.

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

* English [en]
Expand All @@ -42,6 +44,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
* Português Brasileiro [pt-BR]
* հայերեն (Armenian) [hy]
* Қазақша [kz]
* Polish [pl]

** Experimental

Expand Down Expand Up @@ -93,6 +96,9 @@ Deletrea números en varios idiomas utilizando la gema I18n.
I18n.with_locale(:kz) { 42.to_words }
=> "қырық екi"

18n.with_locale(:pl) { 42.to_words }
=> "czterdzieści dwa"

21.to_words
=> "twenty-one"
=> "veintiuno"
Expand All @@ -114,6 +120,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "hai mươi mốt"
=> "քսան մեկ"
=> "жиырма бiр"
=> "dwadzieścia jeden"

231.to_words
=> "two hundred thirty-one"
Expand All @@ -136,6 +143,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "hai trăm ba mươi mốt"
=> "երկու հարյուր երեսուն մեկ"
=> "екi жүз отыз бiр"
=> "dwieście trzydzieści jeden"

4030.to_words
=> "four thousand thirty"
Expand All @@ -157,6 +165,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "bốn nghìn không trăm ba mươi"
=> "չորս հազար երեսուն"
=> "төрт мың отыз"
=> "cztery tysiące trzydzieści"

1000100.to_words
=> "one million one hundred"
Expand All @@ -178,6 +187,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "một triệu một trăm"
=> "մեկ միլիոն հարյուր"
=> "бiр миллион бiр жүз"
=> "milion sto"

1000000000000000000000000000000000.to_words
=> "one decillion"
Expand All @@ -196,6 +206,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "en decillion"
=> "decilijon"
=> "бiр дециллион"
=> "decylion"

[1, 2, 3].to_words
=> ["one", "two", "three"]
Expand All @@ -211,6 +222,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> ["một", "hai", "ba"]
=> ["մեկ", "երկու", "երեք"]
=> ["бiр", "екi", "үш"]
=> ["jeden", "dwa", "trzy"]

[11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"]
Expand All @@ -232,6 +244,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> ["mười một", "hai mươi hai", "một trăm ba mươi ba"]
=> ["տասնմեկ", "քսան երկու", "հարյուր երեսուն երեք"]
=> ["он бiр", "жиырма екi", "бiр жүз отыз үш"]
=> ["jedenaście", "dwadzieścia dwa", "sto trzydzieści trzy"]

21.77.to_words
=> "twenty-one and seventy-seven hundredths"
Expand All @@ -240,6 +253,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "huszonegy egész hetvenhét század"
=> "twenty-one point seven seven"
=> "hai mươi mốt phẩy bảy mươi bảy"
=> "dwadzieścia jeden"

== Language options / Языковые опции

Expand Down Expand Up @@ -353,6 +367,19 @@ Deletrea números en varios idiomas utilizando la gema I18n.
I18n.with_locale(:es) { 0.7.to_words remove_zero: true }
=> "siete décimas"

* Polish

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

I18n.with_locale(:'cs') { 1.to_words gender: :female }
sectasy0 marked this conversation as resolved.
Show resolved Hide resolved
=> "jeden"

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

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

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

* Precision
Expand Down
92 changes: 92 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.pl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
pl:
numbers:
ones: [zero, jeden, dwa, trzy, cztery, pięć, sześć, siedem, osiem, dziewięć]
teens: [_, jedenaście, dwanaście, trzynaście, czternaście, piętnaście, szesnaście, siedemnaście, osiemnaście, dziewiętnaście]
tens: [_, dziesięć, dwadzieścia, trzydzieści, czterdzieści, pięćdziesiąt, sześćdziesiąt, siedemdziesiąt, osiemdziesiąt, dziewięćdziesiąt]
hundreds: [_, sto, dwieście, trzysta, czterysta, pięćset, sześćset, siedemset, osiemset, dziewięćset]
mega: [_, thousands, millions, billions, trillions, quadrillions, quintillions, sextillions, septillions, octillions]
thousands:
one: tysiąc
few: tysiące
many: tysięcy
millions:
one: milion
few: miliony
many: milionów
billions:
one: miliard
few: miliardy
many: miliardów
trillions:
one: bilion
few: biliony
many: bilionów
quadrillions:
one: biliard
few: biliardy
many: biliardów
quintillion:
one: trylion
few: tryliony
many: trylionów
sextillions:
one: tryliard
few: tryliardy
many: tryliardów
septillions:
one: sekstilion
few: sekstiliony
many: sekstilionów
octillions:
one: kvadriliarda
few: kvadriliardy
many: kvadriliard
ordinal:
ones:
male: [zerowy, pierwszy, drugi, trzeci, czwarty, pięty, szósty, siódmy, ósmy, dziewiąty]
female: [zerowa, pierwsza, druga, trzecia, czwarta, piąta, szósta, siódma, ósma, dziewiąta]
neuter: [zerowe, pierwsze, drugie, trzecie, czwarte, piąte, szóste, siódme, ósme, dziewiąte]
teens:
male: [_, jedenasty, dwunasty, trzynasty, czternasty, piętnasty, szesnasty, siedemnasty, osiemnasty]
female: [_, jedenasta, dwunasta, trzynasta, czternasta, piętnasta, szesnasta, siedemnasta, osiemnasta]
neuter: [_, jedenaste, dwunaste, trzynaste, czternaste, piętnaste, szesnaste, siedemnaste, osiemnaste]
tens:
male: [_, dwudziesty, trzydziesty, czterdziesty, pięćdziesiąty, sześćdziesiąty, siedemdziesiąty, osiemdziesiąty, dziewięcdziesiąty]
female: [_, dwudziesta, trzydziesta, czterdziesta, pięćdziesiąta, sześćdziesiąta, siedemdziesiąta, osiemdziesiąta, dziewięcdziesiąta]
neuter: [_, dwudzieste, trzydzieste, czterdzieste, pięćdziesiąte, sześćdziesiąte, siedemdziesiąte, osiemdziesiąte, dziewięcdziesiąte]
hundreds:
male: [_, setny, dwusetny, trzysetny, czterysetny, pięćsetny, sześćsetny, siedemsetny, osiemsetny, dziewięćsetny]
female: [_, setna, dwuseta, trzysetna, czterysetna, pięćsetna, sześćsetna, siedemsetna, osiemsetna, dziewięćsetna]
neuter: [_, setne, dwusete, trzysetne, czterysetne, pięćsetne, sześćsetne, siedemsetne, osiemsetne, dziewięćsetne]
integral: całych
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths]
tenths:
one: dziesiętna
few: dziesiętnych
many: dziesiętnych
hundredths:
one: setna
few: setnych
many: setnych
thousandths:
one: tysięczna
few: tysięcznych
many: tysięcznych
millionths:
one: milionowa
few: milionowych
many: milionowych
billionths:
one: miliardowa
few: miliardowych
many: miliardowych
trillionths:
one: bilionowa
few: bilionowych
many: bilionowych
micro_separator: ''
micro_prefix:
tens: dziesięć
hundreds: sto
union: ''
union: 'i'
1 change: 1 addition & 0 deletions lib/numbers_and_words/i18n/pluralization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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/pl'

module NumbersAndWords
module I18n
Expand Down
38 changes: 38 additions & 0 deletions lib/numbers_and_words/i18n/plurals/pl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module NumbersAndWords
module I18n
module Plurals
module Pl
module_function

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

def one_conditions(number)
number % 10 == 1 && number % 100 != 11
end

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

def many_conditions(number)
(number % 10).zero? ||
[5, 6, 7, 8, 9].include?(number % 10) ||
[11, 12, 13, 14].include?(number % 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 @@ -14,6 +14,7 @@
require 'numbers_and_words/strategies/array_joiner/languages/pt-BR'
require 'numbers_and_words/strategies/array_joiner/languages/cs'
require 'numbers_and_words/strategies/array_joiner/languages/vi'
require 'numbers_and_words/strategies/array_joiner/languages/pl'

module NumbersAndWords
module Strategies
Expand Down
12 changes: 12 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages/pl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class Pl < Base
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'numbers_and_words/strategies/figures_converter/decorators/ua'
require 'numbers_and_words/strategies/figures_converter/decorators/cs'
require 'numbers_and_words/strategies/figures_converter/decorators/vi'
require 'numbers_and_words/strategies/figures_converter/decorators/pl'

module NumbersAndWords
module Strategies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require 'numbers_and_words/strategies/figures_converter/decorators/pl/base'
require 'numbers_and_words/strategies/figures_converter/decorators/pl/fractional'
require 'numbers_and_words/strategies/figures_converter/decorators/pl/integral'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Pl
class Base < Decorators::Base
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Pl
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,31 @@
# frozen_string_literal: true

module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Pl
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 @@ -28,6 +28,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/vi'
require 'numbers_and_words/strategies/figures_converter/languages/pl'

module NumbersAndWords
module Strategies
Expand Down
Loading