Skip to content

Commit

Permalink
Merge pull request #144 from fakenine/feature/add_support_for_french_…
Browse files Browse the repository at this point in the history
…float_numbers

Add support for french float numbers
  • Loading branch information
dblock authored Jul 6, 2017
2 parents 8795bcd + 651de7b commit 1c8d634
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
54 changes: 54 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages/fr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class Fr < Base
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Fr
class Base < Decorators::Base
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module Fr
class Integral < Base
end
end
end
end
end
end
8 changes: 8 additions & 0 deletions lib/numbers_and_words/translations/fr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/numbers_and_words/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NumbersAndWords
VERSION = '0.11.0'.freeze
VERSION = '0.11.1'.freeze
end
6 changes: 5 additions & 1 deletion numbers_and_words.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -194,4 +199,3 @@ Gem::Specification.new do |s|
s.add_dependency(%q<rake>.freeze, [">= 0"])
end
end

17 changes: 17 additions & 0 deletions spec/numbers_and_words/float/fixture_examples/fr.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/numbers_and_words/numbers_and_words_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }

Expand Down

0 comments on commit 1c8d634

Please sign in to comment.