-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support Vietnamese
- Loading branch information
Showing
18 changed files
with
304 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
vi: | ||
numbers: | ||
ones: ['không', 'một', 'hai', 'ba', 'bốn', 'năm', 'sáu', 'bảy', 'tám', 'chín'] | ||
teens: [_, 'mười một', 'mười hai', 'mười ba', 'mười bốn', 'mười lăm', 'mười sáu', 'mười bảy', 'thứ mười tám', 'mười chín'] | ||
tens: [_, 'mười', 'hai mươi', 'ba mươi', 'bốn mươi', 'năm mươi', 'sáu mươi', 'bảy mươi', 'tám mươi', 'chín mươi'] | ||
hundreds: 'trăm' | ||
mega: [_, 'nghìn', 'triệu', 'tỷ', 'nghìn tỷ', 'triệu tỷ'] | ||
units: | ||
tens: | ||
one: 'mốt' | ||
five: 'lăm' | ||
ones_union: 'linh' | ||
micro_separator: 'phẩy' |
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
10 changes: 10 additions & 0 deletions
10
lib/numbers_and_words/strategies/array_joiner/languages/vi.rb
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,10 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class Vi < Base | ||
end | ||
end | ||
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
3 changes: 3 additions & 0 deletions
3
lib/numbers_and_words/strategies/figures_converter/decorators/vi.rb
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,3 @@ | ||
require 'numbers_and_words/strategies/figures_converter/decorators/vi/base' | ||
require 'numbers_and_words/strategies/figures_converter/decorators/vi/fractional' | ||
require 'numbers_and_words/strategies/figures_converter/decorators/vi/integral' |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/decorators/vi/base.rb
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,12 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Decorators | ||
module Vi | ||
class Base < Decorators::Base | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/decorators/vi/fractional.rb
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,12 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Decorators | ||
module Vi | ||
class Fractional < Base | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/decorators/vi/integral.rb
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,12 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Decorators | ||
module Vi | ||
class Integral < Base | ||
end | ||
end | ||
end | ||
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
96 changes: 96 additions & 0 deletions
96
lib/numbers_and_words/strategies/figures_converter/languages/vi.rb
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,96 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Languages | ||
class Vi < Base | ||
def print_words | ||
value = super | ||
remove_billion_noice(value) | ||
end | ||
|
||
def strings_logic | ||
if fractional? | ||
if fraction_number_zeros_leading.zero? | ||
@options.options[:integeral] = true | ||
integeral_string_logic | ||
else | ||
fractional_with_zero_leading_string_logic | ||
end | ||
else | ||
integeral_string_logic | ||
end | ||
end | ||
|
||
def fractional_with_zero_leading_string_logic | ||
leading_zeros = [0] * fraction_number_zeros_leading | ||
(@figures + leading_zeros).map(&:to_words) | ||
end | ||
|
||
def integeral_string_logic | ||
if @figures.capacity_count | ||
number_without_capacity_to_words + complex_number_to_words | ||
elsif hundreds? | ||
hundreds_number_to_words | ||
elsif @figures.tens || @figures.ones | ||
simple_number_to_words | ||
else | ||
[] | ||
end | ||
end | ||
|
||
def hundreds? | ||
@figures.hundreds || | ||
(@figures.size == 3 && (@figures.teens || @figures.tens || @figures.ones)) | ||
end | ||
|
||
def hundreds(options = {}) | ||
if @figures.hundreds.to_i.zero? | ||
translate :hundreds, 0, options | ||
else | ||
super | ||
end | ||
end | ||
|
||
def ones(options = {}) | ||
if @figures.capacity_length >= 2 | ||
ones_union(options) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def ones_union(options = {}) | ||
translate :ones_union, @figures.ones, options | ||
end | ||
|
||
def fractional? | ||
!@options.options[:fractional].nil? && !@options.options[:integeral] | ||
end | ||
|
||
def fraction_length | ||
return 0 unless @options.options[:fractional] | ||
@options.options[:fractional][:length] | ||
end | ||
|
||
def fraction_number_zeros_leading | ||
fraction_length - @figures.length | ||
end | ||
|
||
def remove_billion_noice(value) | ||
parts = value.split(billion_unit).map(&:strip) | ||
if value.end_with?(billion_unit) | ||
parts.insert(-1, billion_unit).join(' ') | ||
else | ||
return value if parts.size <= 2 | ||
parts.insert(-2, billion_unit).join(' ') | ||
end | ||
end | ||
|
||
def billion_unit | ||
translate :mega, 3 | ||
end | ||
end | ||
end | ||
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
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,21 @@ | ||
module NumbersAndWords | ||
module Translations | ||
class Vi < Base | ||
include NumbersAndWords::Translations::Families::Latin | ||
include NumbersAndWords::Translations::Extensions::FractionSignificance | ||
def ones_of_tens(number, options = {}) | ||
return t(%i[units tens one].join('.')) if number == 1 | ||
return t(%i[units tens five].join('.')) if number == 5 | ||
ones(number, options) | ||
end | ||
|
||
def tens_with_ones(numbers, options = {}) | ||
[tens(numbers[1]), ones_of_tens(numbers[0], options)].join options[:separator] || ' ' | ||
end | ||
|
||
def ones_union(number, options = {}) | ||
[t(:ones_union), ones(number, options)].join options[:separator] || ' ' | ||
end | ||
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,30 @@ | ||
to_words: | ||
simple_example: | ||
? | ||
- 1 | ||
- 2 | ||
- 3 | ||
: | ||
- một | ||
- hai | ||
- ba | ||
complex_example: | ||
? | ||
- 101 | ||
- 21 | ||
- 13 | ||
: | ||
- một trăm linh một | ||
- hai mươi mốt | ||
- mười ba | ||
complex_example_with_options: | ||
options: | ||
:remove_zero: true | ||
? | ||
- 0.1 | ||
- 0.31 | ||
- 0.012 | ||
: | ||
- không phẩy một | ||
- không phẩy ba mươi mốt | ||
- không phẩy không một hai |
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,19 @@ | ||
to_words: | ||
fractional: | ||
0.1: không phẩy một | ||
0.7: không phẩy bảy | ||
0.01: không phẩy không một | ||
0.012: không phẩy không một hai | ||
0.77: không phẩy bảy mươi bảy | ||
0.777: không phẩy bảy trăm bảy mươi bảy | ||
0.7777: không phẩy bảy nghìn bảy trăm bảy mươi bảy | ||
0.77777: không phẩy bảy mươi bảy nghìn bảy trăm bảy mươi bảy | ||
0.777777: không phẩy bảy trăm bảy mươi bảy nghìn bảy trăm bảy mươi bảy | ||
0.7777777: không phẩy bảy triệu bảy trăm bảy mươi bảy nghìn bảy trăm bảy mươi bảy | ||
0.77777777: không phẩy bảy mươi bảy triệu bảy trăm bảy mươi bảy nghìn bảy trăm bảy mươi bảy | ||
0.777777777: không phẩy bảy trăm bảy mươi bảy triệu bảy trăm bảy mươi bảy nghìn bảy trăm bảy mươi bảy | ||
0.2935174315119: không phẩy hai nghìn chín trăm ba mươi lăm tỷ một trăm bảy mươi bốn triệu ba trăm mười lăm nghìn một trăm mười chín | ||
21.77: hai mươi mốt phẩy bảy mươi bảy | ||
111.999: một trăm mười một phẩy chín trăm chín mươi chín | ||
4242.7463: bốn nghìn hai trăm bốn mươi hai phẩy bảy nghìn bốn trăm sáu mươi ba | ||
4242.07463: bốn nghìn hai trăm bốn mươi hai phẩy không bảy bốn sáu ba |
Oops, something went wrong.