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 1 commit
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
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
39 changes: 39 additions & 0 deletions lib/numbers_and_words/i18n/plurals/pl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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

4 changes: 2 additions & 2 deletions lib/numbers_and_words/i18n/plurals/plurals.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

NumbersAndWords::I18n::Pluralization.languages.to_h do |language|
NumbersAndWords::I18n::Pluralization.languages.map do |language|
[language.to_sym, {
i18n: {
plural: {
rule: Object.const_get("NumbersAndWords::I18n::Plurals::#{language.split('-').collect(&:capitalize).join}::RULE")
}
}
}]
end
end.to_h
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(strategy)

def words
@strings = strings_logic
(@strings.empty? && zero) || print_words
@strings.empty? && zero || print_words
end

def print_words
Expand Down
Loading