From 62eec2df7c371eda0465ae9b515289ba851bbf71 Mon Sep 17 00:00:00 2001 From: Piotrek M Date: Thu, 30 Jun 2022 18:06:16 +0200 Subject: [PATCH 1/5] feat: :sparkles: support for polish language --- .../i18n/locales/numbers.pl.yml | 92 +++++++ lib/numbers_and_words/i18n/pluralization.rb | 1 + lib/numbers_and_words/i18n/plurals/pl.rb | 39 +++ lib/numbers_and_words/i18n/plurals/plurals.rb | 4 +- .../strategies/array_joiner/languages.rb | 1 + .../strategies/array_joiner/languages/pl.rb | 12 + .../figures_converter/decorators.rb | 1 + .../figures_converter/decorators/pl.rb | 5 + .../figures_converter/decorators/pl/base.rb | 14 ++ .../decorators/pl/fractional.rb | 40 +++ .../decorators/pl/integral.rb | 31 +++ .../strategies/figures_converter/languages.rb | 1 + .../figures_converter/languages/base.rb | 2 +- .../figures_converter/languages/de.rb | 132 +++++----- .../figures_converter/languages/es.rb | 156 ++++++------ .../figures_converter/languages/hu.rb | 126 +++++----- .../figures_converter/languages/pl.rb | 25 ++ .../figures_converter/languages/pt-BR.rb | 236 +++++++++--------- .../figures_converter/options/en/ordinal.rb | 2 +- lib/numbers_and_words/translations.rb | 1 + lib/numbers_and_words/translations/pl.rb | 8 + lib/numbers_and_words/version.rb | 2 +- numbers_and_words.gemspec | 9 + .../array/fixture_examples/pl.yml | 32 +++ .../float/fixture_examples/pl.yml | 19 ++ .../i18n/pluralization/pl_spec.rb | 24 ++ .../integer/fixture_examples/pl.yml | 144 +++++++++++ .../numbers_and_words_spec.rb | 2 +- 28 files changed, 830 insertions(+), 331 deletions(-) create mode 100644 lib/numbers_and_words/i18n/locales/numbers.pl.yml create mode 100644 lib/numbers_and_words/i18n/plurals/pl.rb create mode 100644 lib/numbers_and_words/strategies/array_joiner/languages/pl.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/pl.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/pl/base.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/pl/fractional.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/pl/integral.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/languages/pl.rb create mode 100644 lib/numbers_and_words/translations/pl.rb create mode 100644 spec/numbers_and_words/array/fixture_examples/pl.yml create mode 100644 spec/numbers_and_words/float/fixture_examples/pl.yml create mode 100644 spec/numbers_and_words/i18n/pluralization/pl_spec.rb create mode 100644 spec/numbers_and_words/integer/fixture_examples/pl.yml diff --git a/lib/numbers_and_words/i18n/locales/numbers.pl.yml b/lib/numbers_and_words/i18n/locales/numbers.pl.yml new file mode 100644 index 00000000..72013f0d --- /dev/null +++ b/lib/numbers_and_words/i18n/locales/numbers.pl.yml @@ -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' diff --git a/lib/numbers_and_words/i18n/pluralization.rb b/lib/numbers_and_words/i18n/pluralization.rb index 49984af7..0cfa0e09 100644 --- a/lib/numbers_and_words/i18n/pluralization.rb +++ b/lib/numbers_and_words/i18n/pluralization.rb @@ -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 diff --git a/lib/numbers_and_words/i18n/plurals/pl.rb b/lib/numbers_and_words/i18n/plurals/pl.rb new file mode 100644 index 00000000..d8d4a484 --- /dev/null +++ b/lib/numbers_and_words/i18n/plurals/pl.rb @@ -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 + \ No newline at end of file diff --git a/lib/numbers_and_words/i18n/plurals/plurals.rb b/lib/numbers_and_words/i18n/plurals/plurals.rb index 39f5f1e6..708c04e4 100644 --- a/lib/numbers_and_words/i18n/plurals/plurals.rb +++ b/lib/numbers_and_words/i18n/plurals/plurals.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -NumbersAndWords::I18n::Pluralization.languages.to_h do |language| +NumbersAndWords::I18n::Pluralization.languages.map do |language| [language.to_sym, { i18n: { plural: { @@ -8,4 +8,4 @@ } } }] -end +end.to_h diff --git a/lib/numbers_and_words/strategies/array_joiner/languages.rb b/lib/numbers_and_words/strategies/array_joiner/languages.rb index 5b029d5b..96b8d398 100644 --- a/lib/numbers_and_words/strategies/array_joiner/languages.rb +++ b/lib/numbers_and_words/strategies/array_joiner/languages.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb b/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb new file mode 100644 index 00000000..a1ea171b --- /dev/null +++ b/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module ArrayJoiner + module Languages + class Pl < Base + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators.rb b/lib/numbers_and_words/strategies/figures_converter/decorators.rb index a9f2dddc..b909c55a 100644 --- a/lib/numbers_and_words/strategies/figures_converter/decorators.rb +++ b/lib/numbers_and_words/strategies/figures_converter/decorators.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/pl.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/pl.rb new file mode 100644 index 00000000..97b000b0 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/pl.rb @@ -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' diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/pl/base.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/base.rb new file mode 100644 index 00000000..0e3b7106 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/base.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/pl/fractional.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/fractional.rb new file mode 100644 index 00000000..39a26f42 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/fractional.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/pl/integral.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/integral.rb new file mode 100644 index 00000000..7e881c8c --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/pl/integral.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/languages.rb b/lib/numbers_and_words/strategies/figures_converter/languages.rb index cbcfee8d..4b1d510f 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/base.rb b/lib/numbers_and_words/strategies/figures_converter/languages/base.rb index 75e2d197..02eb007a 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/base.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/de.rb b/lib/numbers_and_words/strategies/figures_converter/languages/de.rb index 8f6684a7..a46f1f2e 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/de.rb @@ -1,66 +1,66 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class De < Base - def print_words - complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join - end - - def print_megs_words - [print_megs, print_other].reject(&:empty?).join(' ') - end - - def complex_number_to_words - (1..@figures.capacity_count).map do |capacity| - @current_capacity = capacity - capacity_iteration - end - end - - def ones - super(postfix: postfix) - end - - def postfix - case (@current_capacity ||= 0) - when 1 then :combine - when 0 then :default - else :gender - end - end - - def megs - super({ number: @figures.number_in_capacity(@current_capacity) }) - end - - private - - def print_megs - complex_part[1..].map do |el| - [el[1..].to_a.reverse.join, el.first].join(' ') - end.reject(&:empty?).reverse.join(' ') - end - - def print_other - [print_thousands, simple_part.reverse.join].join - end - - def print_thousands - complex_part.first.reverse.join - end - - def simple_part - @strings.reject { |f| f.is_a?(Array) } - end - - def complex_part - @strings - simple_part - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class De < Base + def print_words + complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join + end + + def print_megs_words + [print_megs, print_other].reject(&:empty?).join(' ') + end + + def complex_number_to_words + (1..@figures.capacity_count).map do |capacity| + @current_capacity = capacity + capacity_iteration + end + end + + def ones + super(postfix: postfix) + end + + def postfix + case (@current_capacity ||= 0) + when 1 then :combine + when 0 then :default + else :gender + end + end + + def megs + super({ number: @figures.number_in_capacity(@current_capacity) }) + end + + private + + def print_megs + complex_part[1..].map do |el| + [el[1..].to_a.reverse.join, el.first].join(' ') + end.reject(&:empty?).reverse.join(' ') + end + + def print_other + [print_thousands, simple_part.reverse.join].join + end + + def print_thousands + complex_part.first.reverse.join + end + + def simple_part + @strings.reject { |f| f.is_a?(Array) } + end + + def complex_part + @strings - simple_part + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb index feac854f..afb7a8e2 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb @@ -1,78 +1,78 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class Es < Base - def capacity_iteration - super.compact - end - - def zero - super unless maybe_remove_zero - end - - def ones - super({ gender: gender, - is_one_thousand: one_thousand?, - is_apocopated: one_apocopated? }) - end - - def tens_with_ones - options = { gender: gender, is_apocopated: one_apocopated? } - return @translations.twenties_with_ones(@figures, options) if @figures.tens == 2 - - super(options) - end - - def hundreds - super({ gender: gender, - is_apocopated: hundred_apocopated? }) - end - - def megs - return @translations.megs(1, number: 1) if long_scale_thousand? - - super({ number: @figures.number_in_capacity(@current_capacity) }) - end - - private - - def one_thousand? - @current_capacity.odd? && - @figures.ones == 1 && - @figures.tens.nil? && - @figures.hundreds.nil? - end - - def long_scale_thousand? - @current_capacity.odd? && - !@figures.number_in_capacity(@current_capacity - 1).zero? - end - - def one_apocopated? - (@current_capacity.positive? && @figures.ones == 1) || - @options.apocopated.result - end - - def hundred_apocopated? - @figures.hundreds == 1 && @figures.round_hundred? - end - - def gender - @current_capacity ||= 0 - - return :male if @current_capacity >= 2 - - @options.gender.result - end - - def maybe_remove_zero - @options.remove_zero.result - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Es < Base + def capacity_iteration + super.compact + end + + def zero + super unless maybe_remove_zero + end + + def ones + super({ gender: gender, + is_one_thousand: one_thousand?, + is_apocopated: one_apocopated? }) + end + + def tens_with_ones + options = { gender: gender, is_apocopated: one_apocopated? } + return @translations.twenties_with_ones(@figures, options) if @figures.tens == 2 + + super(options) + end + + def hundreds + super({ gender: gender, + is_apocopated: hundred_apocopated? }) + end + + def megs + return @translations.megs(1, number: 1) if long_scale_thousand? + + super({ number: @figures.number_in_capacity(@current_capacity) }) + end + + private + + def one_thousand? + @current_capacity.odd? && + @figures.ones == 1 && + @figures.tens.nil? && + @figures.hundreds.nil? + end + + def long_scale_thousand? + @current_capacity.odd? && + !@figures.number_in_capacity(@current_capacity - 1).zero? + end + + def one_apocopated? + (@current_capacity.positive? && @figures.ones == 1) || + @options.apocopated.result + end + + def hundred_apocopated? + @figures.hundreds == 1 && @figures.round_hundred? + end + + def gender + @current_capacity ||= 0 + + return :male if @current_capacity >= 2 + + @options.gender.result + end + + def maybe_remove_zero + @options.remove_zero.result + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb b/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb index adb38125..8d08448a 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb @@ -1,63 +1,63 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class Hu < Base - def print_words - inner_reverse_words.reverse.join(greater_than_2000? ? '-' : '') - end - - def inner_reverse_words - @strings.collect { |iteration| iteration.reverse.join } - end - - def greater_than_2000? - @figures.length > 4 || (@figures.length == 4 && @figures.last >= 2) - end - - def strings_logic - if @figures.capacity_count - number_without_capacity_to_words + complex_number_to_words - elsif @figures.hundreds - [hundreds_number_to_words] - elsif @figures.tens || @figures.ones - [simple_number_to_words] - else - [] - end - end - - def complex_number_to_words - count = @figures.capacity_count - (1..count).map do |capacity| - @current_capacity = capacity - capacity_iteration.flatten - end.reject(&:empty?) - end - - def simple_number_to_words - if @figures.teens || @figures.tens - [complex_tens] - elsif @figures.ones - [ones] - else - [] - end - end - - %i[zero ones teens tens tens_with_ones hundreds megs].each do |method_name| - define_method(method_name) do - super({ prefix: maybe_ordinal(method_name) }) - end - end - - def maybe_ordinal(type) - @options.ordinal.result type - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Hu < Base + def print_words + inner_reverse_words.reverse.join(greater_than_2000? ? '-' : '') + end + + def inner_reverse_words + @strings.collect { |iteration| iteration.reverse.join } + end + + def greater_than_2000? + @figures.length > 4 || (@figures.length == 4 && @figures.last >= 2) + end + + def strings_logic + if @figures.capacity_count + number_without_capacity_to_words + complex_number_to_words + elsif @figures.hundreds + [hundreds_number_to_words] + elsif @figures.tens || @figures.ones + [simple_number_to_words] + else + [] + end + end + + def complex_number_to_words + count = @figures.capacity_count + (1..count).map do |capacity| + @current_capacity = capacity + capacity_iteration.flatten + end.reject(&:empty?) + end + + def simple_number_to_words + if @figures.teens || @figures.tens + [complex_tens] + elsif @figures.ones + [ones] + else + [] + end + end + + %i[zero ones teens tens tens_with_ones hundreds megs].each do |method_name| + define_method(method_name) do + super({ prefix: maybe_ordinal(method_name) }) + end + end + + def maybe_ordinal(type) + @options.ordinal.result type + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb b/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb new file mode 100644 index 00000000..63d51276 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb @@ -0,0 +1,25 @@ +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Pl < Base + + def megs + super({:number => @figures.number_in_capacity(@current_capacity)}) + end + + private + + def one? + words_in_capacity(@current_capacity) == [translations.ones(1)] + end + + def thousand? + FiguresArray::THOUSAND_CAPACITY == @current_capacity + end + + end + end + end + end + end \ No newline at end of file diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb b/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb index fd4ec6d1..cdf75928 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb @@ -1,118 +1,118 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class PtBr < Base - %i[teens tens tens_with_ones].each do |method_name| - define_method(method_name) do - super(internal_options) - end - end - - def zero - super unless maybe_remove_zero - end - - def words - super.strip - end - - def complex_number_to_words - super.compact - end - - def capacity_iteration - words = [] - capacity_words = words_in_capacity(current_capacity) - words.push(megs) unless capacity_words.empty? || (capacity_words.empty? && figures[0] == 1) - words + capacity_words - end - - def ones - super internal_options.merge(is_one_thousand: one_thousand?) - end - - def hundreds - super(internal_options.merge(is_hundred: hundred?, is_one_hundred: one_hundred?, gender: gender)) - end - - def megs - super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity), - is_opaque: opaque?, - is_without_connector: without_connector?, - is_with_comma: with_comma?)) - end - - private - - def internal_options - { gender: gender, prefix: maybe_ordinal } - end - - def maybe_ordinal - @options.ordinal.result - end - - def gender - return (options.gender.result || :male) if maybe_ordinal - - if current_capacity&.positive? && figures[0] == 1 - :male - else - options.gender.result - end - end - - def hundred? - figures[0].zero? && figures[1].zero? && simple_number_to_words.empty? - end - - def one_hundred? - hundred? && figures[2] == 1 - end - - def opaque? - figures.opaque? current_capacity - end - - def one_thousand? - current_capacity == 1 && - figures.ones == 1 && - figures.tens.nil? && - figures.hundreds.nil? - end - - def without_connector? - return false if with_comma? - return true if figures.hundreds && - (figures.tens_with_ones || - figures.tens || - figures.ones) - - false - end - - def with_comma? - return false unless @current_capacity > 1 - - # if any lower capacity is single word, in portuguese only tens are single words - number_under_capacity = figures.number_under_capacity(@current_capacity) - return false if number_under_capacity < 20 - - figures_under_capacity = figures.figures_array_under_capacity(@current_capacity) - return false if figures_under_capacity.count(0) == (figures_under_capacity.size - 1) - - # else use comma - true - end - - def maybe_remove_zero - @options.remove_zero.result - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class PtBr < Base + %i[teens tens tens_with_ones].each do |method_name| + define_method(method_name) do + super(internal_options) + end + end + + def zero + super unless maybe_remove_zero + end + + def words + super.strip + end + + def complex_number_to_words + super.compact + end + + def capacity_iteration + words = [] + capacity_words = words_in_capacity(current_capacity) + words.push(megs) unless capacity_words.empty? || (capacity_words.empty? && figures[0] == 1) + words + capacity_words + end + + def ones + super internal_options.merge(is_one_thousand: one_thousand?) + end + + def hundreds + super(internal_options.merge(is_hundred: hundred?, is_one_hundred: one_hundred?, gender: gender)) + end + + def megs + super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity), + is_opaque: opaque?, + is_without_connector: without_connector?, + is_with_comma: with_comma?)) + end + + private + + def internal_options + { gender: gender, prefix: maybe_ordinal } + end + + def maybe_ordinal + @options.ordinal.result + end + + def gender + return (options.gender.result || :male) if maybe_ordinal + + if current_capacity&.positive? && figures[0] == 1 + :male + else + options.gender.result + end + end + + def hundred? + figures[0].zero? && figures[1].zero? && simple_number_to_words.empty? + end + + def one_hundred? + hundred? && figures[2] == 1 + end + + def opaque? + figures.opaque? current_capacity + end + + def one_thousand? + current_capacity == 1 && + figures.ones == 1 && + figures.tens.nil? && + figures.hundreds.nil? + end + + def without_connector? + return false if with_comma? + return true if figures.hundreds && + (figures.tens_with_ones || + figures.tens || + figures.ones) + + false + end + + def with_comma? + return false unless @current_capacity > 1 + + # if any lower capacity is single word, in portuguese only tens are single words + number_under_capacity = figures.number_under_capacity(@current_capacity) + return false if number_under_capacity < 20 + + figures_under_capacity = figures.figures_array_under_capacity(@current_capacity) + return false if figures_under_capacity.count(0) == (figures_under_capacity.size - 1) + + # else use comma + true + end + + def maybe_remove_zero + @options.remove_zero.result + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb b/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb index c431a40f..4af0fed7 100644 --- a/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +++ b/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb @@ -28,7 +28,7 @@ def check_megs_numbers def simple_numbers_condition current_capacity.nil? && (HUNDRED_TYPE != @type || - (HUNDRED_TYPE == @type && simple_number_to_words.empty?)) + HUNDRED_TYPE == @type && simple_number_to_words.empty?) end def megs_numbers_condition diff --git a/lib/numbers_and_words/translations.rb b/lib/numbers_and_words/translations.rb index c4c949fa..b1649fd4 100644 --- a/lib/numbers_and_words/translations.rb +++ b/lib/numbers_and_words/translations.rb @@ -27,6 +27,7 @@ require 'numbers_and_words/translations/vi' require 'numbers_and_words/translations/hy' require 'numbers_and_words/translations/kz' +require 'numbers_and_words/translations/pl' module NumbersAndWords module Translations diff --git a/lib/numbers_and_words/translations/pl.rb b/lib/numbers_and_words/translations/pl.rb new file mode 100644 index 00000000..c5d74f30 --- /dev/null +++ b/lib/numbers_and_words/translations/pl.rb @@ -0,0 +1,8 @@ +module NumbersAndWords + module Translations + class Pl < Base + include NumbersAndWords::Translations::Families::Latin + include NumbersAndWords::Translations::Extensions::FractionSignificance + end + end + end \ No newline at end of file diff --git a/lib/numbers_and_words/version.rb b/lib/numbers_and_words/version.rb index ca655a97..d65e47a5 100644 --- a/lib/numbers_and_words/version.rb +++ b/lib/numbers_and_words/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module NumbersAndWords - VERSION = '0.11.12' + VERSION = '0.11.11' end diff --git a/numbers_and_words.gemspec b/numbers_and_words.gemspec index 36645341..3488d9d9 100644 --- a/numbers_and_words.gemspec +++ b/numbers_and_words.gemspec @@ -52,6 +52,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/i18n/locales/numbers.tr.yml", "lib/numbers_and_words/i18n/locales/numbers.ua.yml", "lib/numbers_and_words/i18n/locales/numbers.vi.yml", + "lib/numbers_and_words/i18n/locales/numbers.pl.yml", "lib/numbers_and_words/i18n/pluralization.rb", "lib/numbers_and_words/i18n/plurals/cs.rb", "lib/numbers_and_words/i18n/plurals/fr.rb", @@ -60,6 +61,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/i18n/plurals/plurals.rb", "lib/numbers_and_words/i18n/plurals/ru.rb", "lib/numbers_and_words/i18n/plurals/ua.rb", + "lib/numbers_and_words/i18n/plurals/pl.rb", "lib/numbers_and_words/strategies.rb", "lib/numbers_and_words/strategies/array_joiner.rb", "lib/numbers_and_words/strategies/array_joiner/languages.rb", @@ -75,6 +77,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/strategies/array_joiner/languages/ru.rb", "lib/numbers_and_words/strategies/array_joiner/languages/ua.rb", "lib/numbers_and_words/strategies/array_joiner/languages/vi.rb", + "lib/numbers_and_words/strategies/array_joiner/languages/pl.rb", "lib/numbers_and_words/strategies/figures_converter.rb", "lib/numbers_and_words/strategies/figures_converter/decorators.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/base.rb", @@ -118,6 +121,10 @@ Gem::Specification.new do |s| "lib/numbers_and_words/strategies/figures_converter/decorators/vi/base.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/vi/fractional.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/vi/integral.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/vi.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/pl/base.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/pl/fractional.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/pl/integral.rb", "lib/numbers_and_words/strategies/figures_converter/languages.rb", "lib/numbers_and_words/strategies/figures_converter/languages/base.rb", "lib/numbers_and_words/strategies/figures_converter/languages/cs.rb", @@ -145,6 +152,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/strategies/figures_converter/languages/tr.rb", "lib/numbers_and_words/strategies/figures_converter/languages/ua.rb", "lib/numbers_and_words/strategies/figures_converter/languages/vi.rb", + "lib/numbers_and_words/strategies/figures_converter/languages/pl.rb", "lib/numbers_and_words/strategies/figures_converter/options.rb", "lib/numbers_and_words/strategies/figures_converter/options/base.rb", "lib/numbers_and_words/strategies/figures_converter/options/base/gender.rb", @@ -208,6 +216,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/translations/tr.rb", "lib/numbers_and_words/translations/ua.rb", "lib/numbers_and_words/translations/vi.rb", + "lib/numbers_and_words/translations/pl.rb", "lib/numbers_and_words/version.rb", "lib/numbers_and_words/wrappers.rb", "lib/numbers_and_words/wrappers/float.rb", diff --git a/spec/numbers_and_words/array/fixture_examples/pl.yml b/spec/numbers_and_words/array/fixture_examples/pl.yml new file mode 100644 index 00000000..a2828111 --- /dev/null +++ b/spec/numbers_and_words/array/fixture_examples/pl.yml @@ -0,0 +1,32 @@ +to_words: + simple_example: + ? + - 1 + - 2 + - 3 + : + - jeden + - dwa + - trzy + complex_example: + ? + - 1001 + - 101 + - 21 + - 13 + : + - tysiąc jeden + - sto jeden + - dwadzieścia jeden + - trzynaście + complex_example_with_options: + options: + :remove_zero: true + ? + - 0.1 + - 0.31 + - 0.12 + : + - jedna dziesiętna + - trzydzieści i jedna setna + - dwanaście setnych diff --git a/spec/numbers_and_words/float/fixture_examples/pl.yml b/spec/numbers_and_words/float/fixture_examples/pl.yml new file mode 100644 index 00000000..776ab884 --- /dev/null +++ b/spec/numbers_and_words/float/fixture_examples/pl.yml @@ -0,0 +1,19 @@ +to_words: + fractional: + 0.1: jedna dziesiąta + 0.7: siedem dziesiątych + 0.01: jedna setna + 0.77: siedemdesąt siedem setnych + 0.777: siedemset siedemdesąt siedem tysięcznych + 0.7777: siedem tysięcy siedemset siedemdesąt siedem dziesięciotysięcznych + 0.21021: nula celých dvacet jeden tisíc dvacet jedna stotisícina + 0.293517431: zero dwa biliony dziewięćset trzydzieści pięć miliardów sto siedemdziesiąt cztery miliony trzysta piętnaście tysięcy sto dziewiętnaście dziesięciobilionowych + 21.77: dwadzieścia jeden całych i siedemdesąt siedem setnych + 111.999: sto jedenaście całych dziewięćset dziewięćdziesiąt dziewięć tysięcznych + 4242.7463: cztery tysiące dwieście czterdzieści dwa całych i siedem tysięcy czterysta sześćdziesiąt trzy dziesięciotysięcznych + fractions_without_zero: + options: + :remove_zero: true + 0.1: jedna dziesiąta + 0.7: siedem dziesiątych + 42.1: czterdzieści dwie całe i jedna dziesiąta diff --git a/spec/numbers_and_words/i18n/pluralization/pl_spec.rb b/spec/numbers_and_words/i18n/pluralization/pl_spec.rb new file mode 100644 index 00000000..e456382e --- /dev/null +++ b/spec/numbers_and_words/i18n/pluralization/pl_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe I18n, '#pl' do + it 'pluralizes correctly' do + hash = {} + %w[one few many other].each { |key| hash[key.to_sym] = key } + + expect(described_class.backend.send(:pluralize, :pl, hash, 1)).to eq('one') + expect(described_class.backend.send(:pluralize, :pl, hash, 2)).to eq('few') + expect(described_class.backend.send(:pluralize, :pl, hash, 3)).to eq('few') + expect(described_class.backend.send(:pluralize, :pl, hash, 5)).to eq('many') + expect(described_class.backend.send(:pluralize, :pl, hash, 10)).to eq('many') + expect(described_class.backend.send(:pluralize, :pl, hash, 11)).to eq('many') + expect(described_class.backend.send(:pluralize, :pl, hash, 21)).to eq('one') + expect(described_class.backend.send(:pluralize, :pl, hash, 29)).to eq('many') + expect(described_class.backend.send(:pluralize, :pl, hash, 52)).to eq('few') + expect(described_class.backend.send(:pluralize, :pl, hash, 131)).to eq('one') + expect(described_class.backend.send(:pluralize, :pl, hash, 1.31)).to eq('other') + expect(described_class.backend.send(:pluralize, :pl, hash, 2.31)).to eq('other') + expect(described_class.backend.send(:pluralize, :pl, hash, 3.31)).to eq('other') + end +end \ No newline at end of file diff --git a/spec/numbers_and_words/integer/fixture_examples/pl.yml b/spec/numbers_and_words/integer/fixture_examples/pl.yml new file mode 100644 index 00000000..1b035779 --- /dev/null +++ b/spec/numbers_and_words/integer/fixture_examples/pl.yml @@ -0,0 +1,144 @@ +to_words: + ones: + 0: zero + 1: jeden + 2: dwa + 3: trzy + 4: cztery + 5: pięć + 6: sześć + 7: siedem + 8: osiem + 9: dziewięć + "female ones": + options: + :gender: female + 0: zero + 1: jedna + 2: dwie + 3: trzy + 4: cztery + 5: pięć + 6: sześć + 7: siedem + 8: osiem + 9: dziewięć + "male ones": + options: + :gender: male + 0: zero + 1: jeden + 2: dwa + 3: trzy + 4: cztery + 5: pięć + 6: sześć + 7: siedem + 8: osiem + 9: dziewięć + "neuter ones": + options: + :gender: neuter + 0: zero + 1: jedno + 2: dwa + 3: trzy + 4: cztery + 5: pięć + 6: sześć + 7: siedem + 8: osiem + 9: dziewięć + teens: + 10: dziesięć + 11: jedenaście + 19: dziewiętnaście + 20: dwadzieścia + 21: dwadzieścia jeden + 80: osiemdziesiąt + 90: dziewięćdziesiąt + 99: dziewięćdziesiąt dziewięć + hundreds: + 100: sto + 101: sto jeden + 111: sto jedenaście + 120: sto dwadzieścia + 121: sto dwadzieścia jeden + 900: dziewięćset + 909: dziewięćset dziewięć + 919: dziewięćset dziewiętnaście + 990: dziewięćset dziewięćdziesiąt + 999: dziewięćset dziewięćdziesiąt dziewięć + thousands: + 1_000: tysiąc + 2_000: dwa tysiące + 4_000: cztery tysiące + 5_000: pięć tysięcy + 11_000: jedenaście tysięcy + 21_000: dwadzieścia jeden tysięcy + 21_345: dwadzieścia jeden tysięcy trzysta czterdzieści pięć + 999_999: dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć + miliony: + 1_000_000: milion + 2_000_000: dwa miliony + 4_000_000: cztery miliony + 5_000_000: pięć milionów + 999_000_000: dziewięćset dziewięćdziesiąt dziewięć milionów + 999_000_999: dziewięćset dziewięćdziesiąt dziewięć milionów dziewięćset dziewięćdziesiąt dziewięć + 999_999_000: dziewięćset dziewięćdziesiąt dziewięć milionów dziewięćset dziewięćdziesiąt dziewięć tysięcy + 999_999_999: dziewięćset dziewięćdziesiąt dziewięć milionów dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć + 123_456_789: sto dwadzieścia trzy miliony czterysta pięćdziesiąt sześć tysięcy siedemset osiemdziesiąt dziewięć + miliardy: + 1_174_315_110: miliard sto siedemdziesiąt cztery miliony trzysta pięćdziesiąt jeden tysięcy sto dziesięć + 35_568_717_692: trzydzieści pięć miliardów pięcset sześćdziesiąt osiem milionów siedemset siedemnaście tysięcy sześćset dziewięćdziesiąt dwa + biliony: + 2_935_174_315_119: dwa biliony dziewięćset trzydzieści pięć miliardów sto siedemdziesiąt cztery miliony trzysta piętnaście tysięcy sto dziewiętnaście + + "male ordinals": + options: + :ordinal: true + :gender: male + 0: zerowy + 1: pierwszy + 2: drugi + 3: trzeci + 4: czwarty + 5: piąty + 6: szósty + 7: siódmy + 8: ósmy + 9: dziewiąty + 10: dziesiąty + 11: jedenasty + 12: dwunasty + 13: trzynasty + 14: czternasty + 15: piętnasty + 16: szesnasty + 17: siedemnasty + 18: osiemnasty + 19: dziewiętnasty + 20: dwudziesty + 30: trzydziesty + 40: czterdziesty + 50: pięćdziesiąty + 60: sześćdziesiąty + 70: siedemdziesiąty + 80: osiemdziesiąty + 90: dziewięćdziesiąty + 100: setny + 21: dwudziesty pierwszy + 42: czterdziesty drugi + 133: sto trzydziesty trzeci + + "female ordinals": + options: + :ordinal: true + :gender: female + 2: druga + 3: trzecia + 8: ósma + 18: osiemnasta + 36: trzydziesta szósta + 100: setna + 999: dziewięćset dziewięćdziesiąta dziewiąta diff --git a/spec/numbers_and_words/numbers_and_words_spec.rb b/spec/numbers_and_words/numbers_and_words_spec.rb index d4b4667a..7281faca 100644 --- a/spec/numbers_and_words/numbers_and_words_spec.rb +++ b/spec/numbers_and_words/numbers_and_words_spec.rb @@ -15,7 +15,7 @@ end end -FLOAT_CAPABLE_LANGUAGES = %i[cs en-GB en es fr hu pt-BR ru ua vi].freeze +FLOAT_CAPABLE_LANGUAGES = %i[cs en-GB en es fr hu pt-BR ru ua vi pl].freeze [Float].each do |type| describe type do FLOAT_CAPABLE_LANGUAGES.each do |locale| From adee1a72a39ea7cf6cdfa23a397a4309b917fc3e Mon Sep 17 00:00:00 2001 From: Piotrek M Date: Thu, 30 Jun 2022 19:41:58 +0200 Subject: [PATCH 2/5] refactor: :recycle: correct rubocop errors. update CHANGELOG.md and README.rdoc --- CHANGELOG.md | 5 ++ README.rdoc | 27 +++++++ lib/numbers_and_words/i18n/plurals/pl.rb | 77 +++++++++---------- lib/numbers_and_words/i18n/plurals/plurals.rb | 4 +- .../strategies/array_joiner/languages/pl.rb | 24 +++--- .../figures_converter/languages/base.rb | 2 +- .../figures_converter/languages/pl.rb | 50 ++++++------ .../figures_converter/options/en/ordinal.rb | 2 +- lib/numbers_and_words/translations/pl.rb | 18 +++-- .../i18n/pluralization/pl_spec.rb | 2 +- 10 files changed, 122 insertions(+), 89 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3739686c..09d45c49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Features + * Add polish language support \[[#189](https://github.com/kslazarev/numbers_and_words/pull/189)\] + ## 0.11.12 (Next) ### Features diff --git a/README.rdoc b/README.rdoc index 5b62c3b5..30959461 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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] @@ -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 @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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"] @@ -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"] @@ -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" @@ -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 / Языковые опции @@ -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 } + => "jeden" + + I18n.with_locale(:'cs') { 1.to_words gender: :male } + => "jedna" + + I18n.with_locale(:'cs') { 1.to_words gender: :neuter } + => "jedno" + == Other options / Другие опции * Precision diff --git a/lib/numbers_and_words/i18n/plurals/pl.rb b/lib/numbers_and_words/i18n/plurals/pl.rb index d8d4a484..d2220e2b 100644 --- a/lib/numbers_and_words/i18n/plurals/pl.rb +++ b/lib/numbers_and_words/i18n/plurals/pl.rb @@ -1,39 +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 - \ No newline at end of file +# 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 diff --git a/lib/numbers_and_words/i18n/plurals/plurals.rb b/lib/numbers_and_words/i18n/plurals/plurals.rb index 708c04e4..39f5f1e6 100644 --- a/lib/numbers_and_words/i18n/plurals/plurals.rb +++ b/lib/numbers_and_words/i18n/plurals/plurals.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -NumbersAndWords::I18n::Pluralization.languages.map do |language| +NumbersAndWords::I18n::Pluralization.languages.to_h do |language| [language.to_sym, { i18n: { plural: { @@ -8,4 +8,4 @@ } } }] -end.to_h +end diff --git a/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb b/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb index a1ea171b..376d4410 100644 --- a/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb +++ b/lib/numbers_and_words/strategies/array_joiner/languages/pl.rb @@ -1,12 +1,12 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module ArrayJoiner - module Languages - class Pl < Base - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module ArrayJoiner + module Languages + class Pl < Base + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/base.rb b/lib/numbers_and_words/strategies/figures_converter/languages/base.rb index 02eb007a..75e2d197 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/base.rb @@ -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 diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb b/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb index 63d51276..4fcd9393 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/pl.rb @@ -1,25 +1,25 @@ -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class Pl < Base - - def megs - super({:number => @figures.number_in_capacity(@current_capacity)}) - end - - private - - def one? - words_in_capacity(@current_capacity) == [translations.ones(1)] - end - - def thousand? - FiguresArray::THOUSAND_CAPACITY == @current_capacity - end - - end - end - end - end - end \ No newline at end of file +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Pl < Base + def megs + super({ number: @figures.number_in_capacity(@current_capacity) }) + end + + private + + def one? + words_in_capacity(@current_capacity) == [translations.ones(1)] + end + + def thousand? + FiguresArray::THOUSAND_CAPACITY == @current_capacity + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb b/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb index 4af0fed7..c431a40f 100644 --- a/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +++ b/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb @@ -28,7 +28,7 @@ def check_megs_numbers def simple_numbers_condition current_capacity.nil? && (HUNDRED_TYPE != @type || - HUNDRED_TYPE == @type && simple_number_to_words.empty?) + (HUNDRED_TYPE == @type && simple_number_to_words.empty?)) end def megs_numbers_condition diff --git a/lib/numbers_and_words/translations/pl.rb b/lib/numbers_and_words/translations/pl.rb index c5d74f30..69e12dae 100644 --- a/lib/numbers_and_words/translations/pl.rb +++ b/lib/numbers_and_words/translations/pl.rb @@ -1,8 +1,10 @@ -module NumbersAndWords - module Translations - class Pl < Base - include NumbersAndWords::Translations::Families::Latin - include NumbersAndWords::Translations::Extensions::FractionSignificance - end - end - end \ No newline at end of file +# frozen_string_literal: true + +module NumbersAndWords + module Translations + class Pl < Base + include NumbersAndWords::Translations::Families::Latin + include NumbersAndWords::Translations::Extensions::FractionSignificance + end + end +end diff --git a/spec/numbers_and_words/i18n/pluralization/pl_spec.rb b/spec/numbers_and_words/i18n/pluralization/pl_spec.rb index e456382e..daa48dc7 100644 --- a/spec/numbers_and_words/i18n/pluralization/pl_spec.rb +++ b/spec/numbers_and_words/i18n/pluralization/pl_spec.rb @@ -21,4 +21,4 @@ expect(described_class.backend.send(:pluralize, :pl, hash, 2.31)).to eq('other') expect(described_class.backend.send(:pluralize, :pl, hash, 3.31)).to eq('other') end -end \ No newline at end of file +end From 18766ed5b36731660466e916ae49398a57047785 Mon Sep 17 00:00:00 2001 From: Piotrek M Date: Thu, 21 Jul 2022 16:17:47 +0200 Subject: [PATCH 3/5] style: change line endings to unix LF --- .../figures_converter/languages/de.rb | 132 +++++----- .../figures_converter/languages/es.rb | 156 ++++++------ .../figures_converter/languages/hu.rb | 126 +++++----- .../figures_converter/languages/pt-BR.rb | 236 +++++++++--------- 4 files changed, 325 insertions(+), 325 deletions(-) diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/de.rb b/lib/numbers_and_words/strategies/figures_converter/languages/de.rb index a46f1f2e..8f6684a7 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/de.rb @@ -1,66 +1,66 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class De < Base - def print_words - complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join - end - - def print_megs_words - [print_megs, print_other].reject(&:empty?).join(' ') - end - - def complex_number_to_words - (1..@figures.capacity_count).map do |capacity| - @current_capacity = capacity - capacity_iteration - end - end - - def ones - super(postfix: postfix) - end - - def postfix - case (@current_capacity ||= 0) - when 1 then :combine - when 0 then :default - else :gender - end - end - - def megs - super({ number: @figures.number_in_capacity(@current_capacity) }) - end - - private - - def print_megs - complex_part[1..].map do |el| - [el[1..].to_a.reverse.join, el.first].join(' ') - end.reject(&:empty?).reverse.join(' ') - end - - def print_other - [print_thousands, simple_part.reverse.join].join - end - - def print_thousands - complex_part.first.reverse.join - end - - def simple_part - @strings.reject { |f| f.is_a?(Array) } - end - - def complex_part - @strings - simple_part - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class De < Base + def print_words + complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join + end + + def print_megs_words + [print_megs, print_other].reject(&:empty?).join(' ') + end + + def complex_number_to_words + (1..@figures.capacity_count).map do |capacity| + @current_capacity = capacity + capacity_iteration + end + end + + def ones + super(postfix: postfix) + end + + def postfix + case (@current_capacity ||= 0) + when 1 then :combine + when 0 then :default + else :gender + end + end + + def megs + super({ number: @figures.number_in_capacity(@current_capacity) }) + end + + private + + def print_megs + complex_part[1..].map do |el| + [el[1..].to_a.reverse.join, el.first].join(' ') + end.reject(&:empty?).reverse.join(' ') + end + + def print_other + [print_thousands, simple_part.reverse.join].join + end + + def print_thousands + complex_part.first.reverse.join + end + + def simple_part + @strings.reject { |f| f.is_a?(Array) } + end + + def complex_part + @strings - simple_part + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb index afb7a8e2..feac854f 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/es.rb @@ -1,78 +1,78 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class Es < Base - def capacity_iteration - super.compact - end - - def zero - super unless maybe_remove_zero - end - - def ones - super({ gender: gender, - is_one_thousand: one_thousand?, - is_apocopated: one_apocopated? }) - end - - def tens_with_ones - options = { gender: gender, is_apocopated: one_apocopated? } - return @translations.twenties_with_ones(@figures, options) if @figures.tens == 2 - - super(options) - end - - def hundreds - super({ gender: gender, - is_apocopated: hundred_apocopated? }) - end - - def megs - return @translations.megs(1, number: 1) if long_scale_thousand? - - super({ number: @figures.number_in_capacity(@current_capacity) }) - end - - private - - def one_thousand? - @current_capacity.odd? && - @figures.ones == 1 && - @figures.tens.nil? && - @figures.hundreds.nil? - end - - def long_scale_thousand? - @current_capacity.odd? && - !@figures.number_in_capacity(@current_capacity - 1).zero? - end - - def one_apocopated? - (@current_capacity.positive? && @figures.ones == 1) || - @options.apocopated.result - end - - def hundred_apocopated? - @figures.hundreds == 1 && @figures.round_hundred? - end - - def gender - @current_capacity ||= 0 - - return :male if @current_capacity >= 2 - - @options.gender.result - end - - def maybe_remove_zero - @options.remove_zero.result - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Es < Base + def capacity_iteration + super.compact + end + + def zero + super unless maybe_remove_zero + end + + def ones + super({ gender: gender, + is_one_thousand: one_thousand?, + is_apocopated: one_apocopated? }) + end + + def tens_with_ones + options = { gender: gender, is_apocopated: one_apocopated? } + return @translations.twenties_with_ones(@figures, options) if @figures.tens == 2 + + super(options) + end + + def hundreds + super({ gender: gender, + is_apocopated: hundred_apocopated? }) + end + + def megs + return @translations.megs(1, number: 1) if long_scale_thousand? + + super({ number: @figures.number_in_capacity(@current_capacity) }) + end + + private + + def one_thousand? + @current_capacity.odd? && + @figures.ones == 1 && + @figures.tens.nil? && + @figures.hundreds.nil? + end + + def long_scale_thousand? + @current_capacity.odd? && + !@figures.number_in_capacity(@current_capacity - 1).zero? + end + + def one_apocopated? + (@current_capacity.positive? && @figures.ones == 1) || + @options.apocopated.result + end + + def hundred_apocopated? + @figures.hundreds == 1 && @figures.round_hundred? + end + + def gender + @current_capacity ||= 0 + + return :male if @current_capacity >= 2 + + @options.gender.result + end + + def maybe_remove_zero + @options.remove_zero.result + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb b/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb index 8d08448a..adb38125 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb @@ -1,63 +1,63 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class Hu < Base - def print_words - inner_reverse_words.reverse.join(greater_than_2000? ? '-' : '') - end - - def inner_reverse_words - @strings.collect { |iteration| iteration.reverse.join } - end - - def greater_than_2000? - @figures.length > 4 || (@figures.length == 4 && @figures.last >= 2) - end - - def strings_logic - if @figures.capacity_count - number_without_capacity_to_words + complex_number_to_words - elsif @figures.hundreds - [hundreds_number_to_words] - elsif @figures.tens || @figures.ones - [simple_number_to_words] - else - [] - end - end - - def complex_number_to_words - count = @figures.capacity_count - (1..count).map do |capacity| - @current_capacity = capacity - capacity_iteration.flatten - end.reject(&:empty?) - end - - def simple_number_to_words - if @figures.teens || @figures.tens - [complex_tens] - elsif @figures.ones - [ones] - else - [] - end - end - - %i[zero ones teens tens tens_with_ones hundreds megs].each do |method_name| - define_method(method_name) do - super({ prefix: maybe_ordinal(method_name) }) - end - end - - def maybe_ordinal(type) - @options.ordinal.result type - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class Hu < Base + def print_words + inner_reverse_words.reverse.join(greater_than_2000? ? '-' : '') + end + + def inner_reverse_words + @strings.collect { |iteration| iteration.reverse.join } + end + + def greater_than_2000? + @figures.length > 4 || (@figures.length == 4 && @figures.last >= 2) + end + + def strings_logic + if @figures.capacity_count + number_without_capacity_to_words + complex_number_to_words + elsif @figures.hundreds + [hundreds_number_to_words] + elsif @figures.tens || @figures.ones + [simple_number_to_words] + else + [] + end + end + + def complex_number_to_words + count = @figures.capacity_count + (1..count).map do |capacity| + @current_capacity = capacity + capacity_iteration.flatten + end.reject(&:empty?) + end + + def simple_number_to_words + if @figures.teens || @figures.tens + [complex_tens] + elsif @figures.ones + [ones] + else + [] + end + end + + %i[zero ones teens tens tens_with_ones hundreds megs].each do |method_name| + define_method(method_name) do + super({ prefix: maybe_ordinal(method_name) }) + end + end + + def maybe_ordinal(type) + @options.ordinal.result type + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb b/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb index cdf75928..fd4ec6d1 100644 --- a/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +++ b/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb @@ -1,118 +1,118 @@ -# frozen_string_literal: true - -module NumbersAndWords - module Strategies - module FiguresConverter - module Languages - class PtBr < Base - %i[teens tens tens_with_ones].each do |method_name| - define_method(method_name) do - super(internal_options) - end - end - - def zero - super unless maybe_remove_zero - end - - def words - super.strip - end - - def complex_number_to_words - super.compact - end - - def capacity_iteration - words = [] - capacity_words = words_in_capacity(current_capacity) - words.push(megs) unless capacity_words.empty? || (capacity_words.empty? && figures[0] == 1) - words + capacity_words - end - - def ones - super internal_options.merge(is_one_thousand: one_thousand?) - end - - def hundreds - super(internal_options.merge(is_hundred: hundred?, is_one_hundred: one_hundred?, gender: gender)) - end - - def megs - super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity), - is_opaque: opaque?, - is_without_connector: without_connector?, - is_with_comma: with_comma?)) - end - - private - - def internal_options - { gender: gender, prefix: maybe_ordinal } - end - - def maybe_ordinal - @options.ordinal.result - end - - def gender - return (options.gender.result || :male) if maybe_ordinal - - if current_capacity&.positive? && figures[0] == 1 - :male - else - options.gender.result - end - end - - def hundred? - figures[0].zero? && figures[1].zero? && simple_number_to_words.empty? - end - - def one_hundred? - hundred? && figures[2] == 1 - end - - def opaque? - figures.opaque? current_capacity - end - - def one_thousand? - current_capacity == 1 && - figures.ones == 1 && - figures.tens.nil? && - figures.hundreds.nil? - end - - def without_connector? - return false if with_comma? - return true if figures.hundreds && - (figures.tens_with_ones || - figures.tens || - figures.ones) - - false - end - - def with_comma? - return false unless @current_capacity > 1 - - # if any lower capacity is single word, in portuguese only tens are single words - number_under_capacity = figures.number_under_capacity(@current_capacity) - return false if number_under_capacity < 20 - - figures_under_capacity = figures.figures_array_under_capacity(@current_capacity) - return false if figures_under_capacity.count(0) == (figures_under_capacity.size - 1) - - # else use comma - true - end - - def maybe_remove_zero - @options.remove_zero.result - end - end - end - end - end -end +# frozen_string_literal: true + +module NumbersAndWords + module Strategies + module FiguresConverter + module Languages + class PtBr < Base + %i[teens tens tens_with_ones].each do |method_name| + define_method(method_name) do + super(internal_options) + end + end + + def zero + super unless maybe_remove_zero + end + + def words + super.strip + end + + def complex_number_to_words + super.compact + end + + def capacity_iteration + words = [] + capacity_words = words_in_capacity(current_capacity) + words.push(megs) unless capacity_words.empty? || (capacity_words.empty? && figures[0] == 1) + words + capacity_words + end + + def ones + super internal_options.merge(is_one_thousand: one_thousand?) + end + + def hundreds + super(internal_options.merge(is_hundred: hundred?, is_one_hundred: one_hundred?, gender: gender)) + end + + def megs + super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity), + is_opaque: opaque?, + is_without_connector: without_connector?, + is_with_comma: with_comma?)) + end + + private + + def internal_options + { gender: gender, prefix: maybe_ordinal } + end + + def maybe_ordinal + @options.ordinal.result + end + + def gender + return (options.gender.result || :male) if maybe_ordinal + + if current_capacity&.positive? && figures[0] == 1 + :male + else + options.gender.result + end + end + + def hundred? + figures[0].zero? && figures[1].zero? && simple_number_to_words.empty? + end + + def one_hundred? + hundred? && figures[2] == 1 + end + + def opaque? + figures.opaque? current_capacity + end + + def one_thousand? + current_capacity == 1 && + figures.ones == 1 && + figures.tens.nil? && + figures.hundreds.nil? + end + + def without_connector? + return false if with_comma? + return true if figures.hundreds && + (figures.tens_with_ones || + figures.tens || + figures.ones) + + false + end + + def with_comma? + return false unless @current_capacity > 1 + + # if any lower capacity is single word, in portuguese only tens are single words + number_under_capacity = figures.number_under_capacity(@current_capacity) + return false if number_under_capacity < 20 + + figures_under_capacity = figures.figures_array_under_capacity(@current_capacity) + return false if figures_under_capacity.count(0) == (figures_under_capacity.size - 1) + + # else use comma + true + end + + def maybe_remove_zero + @options.remove_zero.result + end + end + end + end + end +end From b85fa233bbf613172c345f80afd41c5e979f4115 Mon Sep 17 00:00:00 2001 From: Piotrek M Date: Thu, 21 Jul 2022 20:23:08 +0200 Subject: [PATCH 4/5] chore: correct CHANGELOG.md --- CHANGELOG.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d45c49..2678e86e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,9 @@ -## Unreleased - -### Features - * Add polish language support \[[#189](https://github.com/kslazarev/numbers_and_words/pull/189)\] - ## 0.11.12 (Next) ### Features * Add support for Ruby 3.1. \[[#187](https://github.com/kslazarev/numbers_and_words/pull/187)\] * Drop support for Ruby 2.5. \[[#180](https://github.com/kslazarev/numbers_and_words/pull/180)\] - * Your contribution here. + * Add polish language support \[[#189](https://github.com/kslazarev/numbers_and_words/pull/189)\] ## 0.11.11 (July 5, 2021) From 1e2672c3501f82fefffc61c5391b33d3159b68d2 Mon Sep 17 00:00:00 2001 From: Piotrek M Date: Fri, 22 Jul 2022 10:21:34 +0200 Subject: [PATCH 5/5] docs: update CHANGELOG.md and README.rdoc --- CHANGELOG.md | 1 + README.rdoc | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2678e86e..9a762e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Add support for Ruby 3.1. \[[#187](https://github.com/kslazarev/numbers_and_words/pull/187)\] * Drop support for Ruby 2.5. \[[#180](https://github.com/kslazarev/numbers_and_words/pull/180)\] * Add polish language support \[[#189](https://github.com/kslazarev/numbers_and_words/pull/189)\] + * Your contribution here. ## 0.11.11 (July 5, 2021) diff --git a/README.rdoc b/README.rdoc index 30959461..4f9a3247 100644 --- a/README.rdoc +++ b/README.rdoc @@ -314,13 +314,13 @@ Przeliteruj liczby w kilku językach za pomocą gemu I18n. Change gender form: (gender: [:female || :male || :neuter]) - I18n.with_locale(:'cs') { 1.to_words gender: :female } + I18n.with_locale(:cs) { 1.to_words gender: :female } => "jedna" - I18n.with_locale(:'cs') { 1.to_words gender: :male } + I18n.with_locale(:cs) { 1.to_words gender: :male } => "jeden" - I18n.with_locale(:'cs') { 1.to_words gender: :neuter } + I18n.with_locale(:cs) { 1.to_words gender: :neuter } => "jedno" Remove 'zero' from integral part of float: (remove_zero: [true || false]) @@ -367,17 +367,17 @@ Przeliteruj liczby w kilku językach za pomocą gemu I18n. I18n.with_locale(:es) { 0.7.to_words remove_zero: true } => "siete décimas" - * Polish +* Polish Change gender form: (gender: [:female || :male || :neuter]) - I18n.with_locale(:'cs') { 1.to_words gender: :female } - => "jeden" - - I18n.with_locale(:'cs') { 1.to_words gender: :male } + I18n.with_locale(:pl) { 1.to_words gender: :female } => "jedna" - I18n.with_locale(:'cs') { 1.to_words gender: :neuter } + I18n.with_locale(:pl) { 1.to_words gender: :male } + => "jeden" + + I18n.with_locale(:pl) { 1.to_words gender: :neuter } => "jedno" == Other options / Другие опции