-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from skyporter/swiss-french-support
Add Swiss French support
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Humanize | ||
%w[az de en es fr id ms pt ru th tr jp vi].each do |locale| | ||
autoload locale.capitalize.to_sym, "humanize/locales/#{locale}.rb" | ||
%w[az de en es fr fr_ch id ms pt ru th tr jp vi].each do |locale| | ||
autoload locale.split('_').map(&:capitalize).join.to_sym, "humanize/locales/#{locale}.rb" | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require_relative 'constants/fr_ch' | ||
|
||
module Humanize | ||
class FrCh | ||
def humanize(number) | ||
iteration = 0 | ||
parts = [] | ||
until number.zero? | ||
number, remainder = number.divmod(1000) | ||
unless remainder.zero? | ||
add_grouping(parts, iteration, remainder) | ||
|
||
parts << SUB_ONE_GROUPING[remainder] unless exactly_one_thousand?(remainder, parts) | ||
end | ||
|
||
iteration += 1 | ||
end | ||
|
||
parts | ||
end | ||
|
||
private | ||
|
||
def exactly_one_thousand?(remainder, parts) | ||
remainder == 1 && parts.last.to_s.strip == 'mille' | ||
end | ||
|
||
def plural_for_lots(remainder, word, iteration) | ||
if remainder > 1 && iteration >= 2 | ||
"#{word}s" | ||
else | ||
word | ||
end | ||
end | ||
|
||
def add_grouping(parts, iteration, remainder) | ||
grouping = plural_for_lots(remainder, LOTS[iteration], iteration) | ||
return unless grouping | ||
|
||
parts << grouping | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Humanize, "fr CH locale" do | ||
before do | ||
Humanize.configure do |config| | ||
config.default_locale = :'fr-CH' | ||
end | ||
end | ||
|
||
tests = [ | ||
[71, 'septante-et-un'], | ||
[80.15, 'huitante virgule un cinq'], | ||
[1090, 'mille nonante'], | ||
[2095, 'deux mille nonante-cinq'], | ||
[10_000, 'dix mille'], | ||
[1_000_000, "un million"], | ||
[2_000_000, "deux millions"], | ||
[5_000_000, "cinq millions"], | ||
[1_000_000_000, "un milliard"], | ||
[2_000_000_000, "deux milliards"], | ||
[5_000_000_000, "cinq milliards"] | ||
] | ||
|
||
tests.each do |num, output| | ||
it "#{num} equals #{output}" do | ||
expect(num.humanize).to eql(output) | ||
end | ||
end | ||
|
||
context 'decimals: number' do | ||
it 'returns the decimals as whole numbers' do | ||
num = 8.15 | ||
expect(num.humanize(decimals_as: :number)).to eq('huit virgule quinze') | ||
end | ||
end | ||
|
||
describe 'when called on conceptual number' do | ||
it 'reads correctly' do | ||
inf = Float::INFINITY | ||
neg_inf = -inf | ||
nan = inf + neg_inf | ||
|
||
expect(inf.humanize).to eql('infini') | ||
expect(neg_inf.humanize).to eql('négatif infini') | ||
expect(nan.humanize).to eql('indéfini') | ||
end | ||
end | ||
end |