From 651de7b7ff625c149feff2fb2e4c537e18208cf1 Mon Sep 17 00:00:00 2001 From: Samy KACIMI Date: Thu, 6 Jul 2017 17:10:12 +0200 Subject: [PATCH] Add support for french float numbers --- CHANGELOG.md | 1 + .../i18n/locales/numbers.fr.yml | 54 +++++++++++++++++++ .../strategies/array_joiner/languages.rb | 1 + .../strategies/array_joiner/languages/fr.rb | 10 ++++ .../figures_converter/decorators.rb | 1 + .../figures_converter/decorators/fr.rb | 3 ++ .../figures_converter/decorators/fr/base.rb | 12 +++++ .../decorators/fr/fractional.rb | 37 +++++++++++++ .../decorators/fr/integral.rb | 12 +++++ lib/numbers_and_words/translations/fr.rb | 8 +++ lib/numbers_and_words/version.rb | 2 +- numbers_and_words.gemspec | 6 ++- .../float/fixture_examples/fr.yml | 17 ++++++ .../numbers_and_words_spec.rb | 2 +- 14 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 lib/numbers_and_words/strategies/array_joiner/languages/fr.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb create mode 100644 lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb create mode 100644 spec/numbers_and_words/float/fixture_examples/fr.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index ff076fce..84bfec25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## 0.11.1 (Next) + * Add support for French floating numbers \[[#144](https://github.com/kslazarev/numbers_and_words/pull/144)\] ### Features * Your contribution here. diff --git a/lib/numbers_and_words/i18n/locales/numbers.fr.yml b/lib/numbers_and_words/i18n/locales/numbers.fr.yml index dbc57635..aff5db57 100644 --- a/lib/numbers_and_words/i18n/locales/numbers.fr.yml +++ b/lib/numbers_and_words/i18n/locales/numbers.fr.yml @@ -5,6 +5,60 @@ fr: tens: [zéro, dix, vingt, trente, quarante, cinquante, soixante, soixante-dix, quatre-vingt, quatre-vingt-dix] mega: [ones, thousands, millions, billions, trillions, quadrillions, quintillion, sextillions, septillions, octillions, nonillions, decillions] eighty: quatre-vingts + union_separator: et + union: et + micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths, undecillionths, duodecillionths, tredecillionths, quattuordecillionths] + tenths: + one: dixième + other: dixièmes + hundredths: + one: centième + other: centièmes + thousandths: + one: millième + other: millièmes + millionths: + one: millionième + other: millionièmes + billionths: + one: milliardième + other: milliardièmes + trillionths: + one: billionième + other: billionièmes + quadrillionths: + one: billiardième + other: billiardièmes + quintillionths: + one: trillionième + other: trillionièmes + sextillionths: + one: trilliardième + other: trilliardièmes + septillionths: + one: quadrillionième + other: quadrillionièmes + octillionths: + one: quadrilliardième + other: quadrilliardièmes + nonillions: + one: quintillionième + other: quintillionièmes + decillions: + one: quintilliardième + other: quintilliardièmes + undecillionths: + one: sextillionième + other: sextillionièmes + duodecillion: + one: sextilliardième + other: sextilliardièmes + tredecillion: + one: septillionième + other: septillionièmes + quattuordecillion: + one: septilliardième + other: septilliardièmes hundreds: one: cent other: cents diff --git a/lib/numbers_and_words/strategies/array_joiner/languages.rb b/lib/numbers_and_words/strategies/array_joiner/languages.rb index 04d45fee..64fdcb82 100644 --- a/lib/numbers_and_words/strategies/array_joiner/languages.rb +++ b/lib/numbers_and_words/strategies/array_joiner/languages.rb @@ -4,6 +4,7 @@ require 'numbers_and_words/strategies/array_joiner/languages/en' require 'numbers_and_words/strategies/array_joiner/languages/en-GB' +require 'numbers_and_words/strategies/array_joiner/languages/fr' 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' diff --git a/lib/numbers_and_words/strategies/array_joiner/languages/fr.rb b/lib/numbers_and_words/strategies/array_joiner/languages/fr.rb new file mode 100644 index 00000000..e22858f9 --- /dev/null +++ b/lib/numbers_and_words/strategies/array_joiner/languages/fr.rb @@ -0,0 +1,10 @@ +module NumbersAndWords + module Strategies + module ArrayJoiner + module Languages + class Fr < 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 e236a4c5..1e671e4e 100644 --- a/lib/numbers_and_words/strategies/figures_converter/decorators.rb +++ b/lib/numbers_and_words/strategies/figures_converter/decorators.rb @@ -1,6 +1,7 @@ require 'numbers_and_words/strategies/figures_converter/decorators/base' 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/fr' 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' diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb new file mode 100644 index 00000000..e0a22f41 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb @@ -0,0 +1,3 @@ +require 'numbers_and_words/strategies/figures_converter/decorators/fr/base' +require 'numbers_and_words/strategies/figures_converter/decorators/fr/fractional' +require 'numbers_and_words/strategies/figures_converter/decorators/fr/integral' diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb new file mode 100644 index 00000000..3d86e525 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb @@ -0,0 +1,12 @@ +module NumbersAndWords + module Strategies + module FiguresConverter + module Decorators + module Fr + class Base < Decorators::Base + end + end + end + end + end +end diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb new file mode 100644 index 00000000..e18339e6 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb @@ -0,0 +1,37 @@ +module NumbersAndWords + module Strategies + module FiguresConverter + module Decorators + module Fr + 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 diff --git a/lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb new file mode 100644 index 00000000..e140e395 --- /dev/null +++ b/lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb @@ -0,0 +1,12 @@ +module NumbersAndWords + module Strategies + module FiguresConverter + module Decorators + module Fr + class Integral < Base + end + end + end + end + end +end diff --git a/lib/numbers_and_words/translations/fr.rb b/lib/numbers_and_words/translations/fr.rb index bda63957..c62023d1 100644 --- a/lib/numbers_and_words/translations/fr.rb +++ b/lib/numbers_and_words/translations/fr.rb @@ -2,6 +2,7 @@ module NumbersAndWords module Translations class Fr < Base include NumbersAndWords::Translations::Families::Latin + include NumbersAndWords::Translations::Extensions::FractionSignificance SPECIAL_TENS_CASE = 8 @@ -24,6 +25,13 @@ def hundreds(number, options = {}) hundreds = t(:hundreds, count: options[:pluralize] ? number : 1) number == 1 ? hundreds : [t(:ones)[number], hundreds].join(' ') end + + def micro_prefix(capacity) + case capacity + when 2 then t(:hundreds, count: 1) + when 1 then tens(1) + end + end end end end diff --git a/lib/numbers_and_words/version.rb b/lib/numbers_and_words/version.rb index cbdf28f4..930bf3c7 100644 --- a/lib/numbers_and_words/version.rb +++ b/lib/numbers_and_words/version.rb @@ -1,3 +1,3 @@ module NumbersAndWords - VERSION = '0.11.0'.freeze + VERSION = '0.11.1'.freeze end diff --git a/numbers_and_words.gemspec b/numbers_and_words.gemspec index c3b604ef..76781ddb 100644 --- a/numbers_and_words.gemspec +++ b/numbers_and_words.gemspec @@ -64,6 +64,7 @@ Gem::Specification.new do |s| "lib/numbers_and_words/strategies/array_joiner/languages/en-GB.rb", "lib/numbers_and_words/strategies/array_joiner/languages/en.rb", "lib/numbers_and_words/strategies/array_joiner/languages/families/base.rb", + "lib/numbers_and_words/strategies/array_joiner/languages/fr.rb", "lib/numbers_and_words/strategies/array_joiner/languages/hu.rb", "lib/numbers_and_words/strategies/array_joiner/languages/pt-BR.rb", "lib/numbers_and_words/strategies/array_joiner/languages/ru.rb", @@ -79,6 +80,10 @@ Gem::Specification.new do |s| "lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb", + "lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb", "lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb", @@ -194,4 +199,3 @@ Gem::Specification.new do |s| s.add_dependency(%q.freeze, [">= 0"]) end end - diff --git a/spec/numbers_and_words/float/fixture_examples/fr.yml b/spec/numbers_and_words/float/fixture_examples/fr.yml new file mode 100644 index 00000000..3f779d59 --- /dev/null +++ b/spec/numbers_and_words/float/fixture_examples/fr.yml @@ -0,0 +1,17 @@ +to_words: + fractional: + 0.1: zéro et un dixième + 0.7: zéro et sept dixièmes + 0.01: zéro et un centième + 0.77: zéro et soixante-dix-sept centièmes + 0.777: zéro et sept cent soixante-dix-sept millièmes + 0.7777: zéro et sept mille sept cent soixante-dix-sept dix-millièmes + 0.77777: zéro et soixante-dix-sept mille sept cent soixante-dix-sept cent-millièmes + 0.777777: zéro et sept cent soixante-dix-sept mille sept cent soixante-dix-sept millionièmes + 0.7777777: zéro et sept millions sept cent soixante-dix-sept mille sept cent soixante-dix-sept dix-millionièmes + 0.77777777: zéro et soixante-dix-sept millions sept cent soixante-dix-sept mille sept cent soixante-dix-sept cent-millionièmes + 0.777777777: zéro et sept cent soixante-dix-sept millions sept cent soixante-dix-sept mille sept cent soixante-dix-sept milliardièmes + 0.2935174315119: zéro et deux billions neuf cent trente-cinq milliards cent soixante-quatorze millions trois cent quinze mille cent dix-neuf dix-billionièmes + 21.77: vingt et un et soixante-dix-sept centièmes + 111.999: cent onze et neuf cent quatre-vingt-dix-neuf millièmes + 4242.7463: quatre mille deux cent quarante-deux et sept mille quatre cent soixante-trois dix-millièmes diff --git a/spec/numbers_and_words/numbers_and_words_spec.rb b/spec/numbers_and_words/numbers_and_words_spec.rb index 1f2353b7..27b9098b 100644 --- a/spec/numbers_and_words/numbers_and_words_spec.rb +++ b/spec/numbers_and_words/numbers_and_words_spec.rb @@ -17,7 +17,7 @@ [Float].each do |type| describe type do - [:en, 'en-GB', 'pt-BR', :hu, :ru, :ua].each do |locale| + [:en, 'en-GB', 'pt-BR', :hu, :ru, :ua, :fr].each do |locale| context locale do around(:each) { |example| ::I18n.with_locale(locale) { example.run } }