Skip to content

Commit

Permalink
Add vi locale
Browse files Browse the repository at this point in the history
  • Loading branch information
luathn committed Oct 22, 2020
1 parent 63752e3 commit 033cd46
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Currently supported locales:
* Portuguese: `:pt`
* Malaysia `:ms`
* Japanese `:jp`
* Vietnamese `:vi`

## Testing

Expand Down
2 changes: 1 addition & 1 deletion lib/humanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def humanize(locale: Humanize.config.default_locale,
def self.for_locale(locale)
case locale.to_sym
# NOTE: add locales here in ealphabetical order
when :az, :de, :en, :es, :fr, :id, :ms, :pt, :ru
when :az, :de, :en, :es, :fr, :id, :ms, :pt, :ru, :vi
[Object.const_get("Humanize::#{locale.capitalize}"), SPACE]
when :th
[Humanize::Th, EMPTY]
Expand Down
2 changes: 1 addition & 1 deletion lib/humanize/locales.rb
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].each do |locale|
%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"
end
end
11 changes: 11 additions & 0 deletions lib/humanize/locales/constants/vi.rb

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions lib/humanize/locales/vi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative 'constants/vi'

module Humanize
class Vi
def humanize(number)
iteration = 0
parts = []
until number.zero?
number, remainder = number.divmod(1000)

if !remainder.zero?
parts << LOTS[iteration] if iteration.positive?
parts << SUB_ONE_GROUPING[remainder]
add_linked_word(parts, remainder) if number.positive?
elsif iteration.positive? && (iteration % 3).zero?
parts << LOTS[3]
end

iteration += 1
end

parts
end

private

def add_linked_word(parts, remainder)
if remainder < 10
parts << LINKED_WORDS[0]
elsif remainder < 100
parts << LINKED_WORDS[1]
end
end
end
end
Loading

0 comments on commit 033cd46

Please sign in to comment.