-
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 #87 from koei1025/TraditionalChinese-
add new language: Traditional Chinese
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
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 fr_ch id ms pt ru th tr jp vi].each do |locale| | ||
%w[az de en es fr fr_ch id ms pt ru th tr jp vi zh_tw].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,30 @@ | ||
require_relative 'constants/zh_tw' | ||
|
||
module Humanize | ||
class ZhTw | ||
def humanize(number) | ||
iteration = 0 | ||
parts = [] | ||
until number.zero? | ||
number, remainder = number.divmod(10_000) | ||
unless remainder.zero? | ||
add_grouping(parts, iteration) | ||
parts << SUB_ONE_GROUPING[remainder] | ||
end | ||
|
||
iteration += 1 | ||
end | ||
|
||
parts | ||
end | ||
|
||
private | ||
|
||
def add_grouping(parts, iteration) | ||
grouping = LOTS[iteration] | ||
return unless grouping | ||
|
||
parts << grouping.to_s | ||
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,55 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Humanize, 'zh tw locale' do | ||
before do | ||
Humanize.configure do |config| | ||
config.default_locale = :'zh-tw' | ||
end | ||
end | ||
|
||
tests = [ | ||
[1, '壹'], | ||
[48, '肆拾捌'], | ||
[100, '佰'], | ||
[101, '佰壹'], | ||
[110, '佰拾'], | ||
[199, '佰玖拾玖'], | ||
[999, '玖佰玖拾玖'], | ||
[1000, '壹仟'], | ||
[3456, '参仟肆佰伍拾陸'], | ||
[9999, '玖仟玖佰玖拾玖'], | ||
[21_111, '貳萬壹仟佰拾壹'], | ||
[99_999, '玖萬玖仟玖佰玖拾玖'], | ||
[9_876_543, '玖佰捌拾柒萬陸仟伍佰肆拾参'], | ||
[10_000_000, '壹仟萬'], | ||
[100_000_000, '壹億'], | ||
[765_432_109, '柒億陸仟伍佰肆拾参萬貳仟佰玖'], | ||
[-123_422_223.48_948_753, '負壹億貳仟参佰肆拾貳萬貳仟貳佰貳拾参・肆捌玖肆捌捌'] | ||
] | ||
|
||
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.1592 | ||
expect(num.humanize).to eq('捌・壹伍玖貳') | ||
expect(num.humanize(decimals_as: :number)).to eq('捌・壹仟伍佰玖拾貳') | ||
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('無限大') | ||
expect(neg_inf.humanize).to eql('負無限大') | ||
expect(nan.humanize).to eql('未定義') | ||
end | ||
end | ||
end |