forked from kslazarev/numbers_and_words
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for danish language (kslazarev#197)
- Loading branch information
1 parent
3bba757
commit 91f0f27
Showing
15 changed files
with
248 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ coverage | |
pkg | ||
Gemfile.lock | ||
.bundle | ||
.idea |
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,52 @@ | ||
da: | ||
numbers: | ||
ones: [nul, et, to, tre, fire, fem, seks, syv, otte, ni] | ||
common: [nul, en, to, tre, fire, fem, seks, syv, otte, ni] | ||
neuter: [nul, et, to, tre, fire, fem, seks, syv, otte, ni] | ||
teens: [_, elleve, tolv, tretten, fjorten, femten, seksten, sytten, atten, nitten] | ||
tens: [_, ti, tyve, tredive, fyrre, halvtreds, tres, halvfjerds, firs, halvfems] | ||
hundreds: [ _, et hundrede, to hundrede, tre hundrede, fire hundrede, fem hundrede, seks hundrede, syv hundrede, otte hundrede, ni hundrede ] | ||
one_hundred: et hundrede | ||
mega: [_, tusinde, million, milliard, billion, billiard, trillion] | ||
tusinde: | ||
one: tusinde | ||
other: tusinde | ||
million: | ||
one: million | ||
other: millioner | ||
milliard: | ||
one: milliard | ||
other: milliarder | ||
billion: | ||
one: billion | ||
other: billioner | ||
billiard: | ||
one: billiard | ||
other: billiarder | ||
trillion: | ||
one: trillion | ||
other: trillioner | ||
ordinal: | ||
ones: [nulte, første, anden, tredje, fjerde, femte, sjette, syvende, ottende, niende] | ||
teens: [tiende, ellevte, tolvte, trettende, fjortende, femtende, sekstende, syttende, attende, nittende] | ||
tens: [_, tiende, tyvende, tredive, fyrre, halvtreds, tres, halvfjerds, firs, halvfems] | ||
hundreds: hundredende | ||
micro: [_, tiendedele, hundrededele, tusindedele, milliontedele] | ||
tenths: | ||
one: tiendedel | ||
other: tiendedele | ||
hundredths: | ||
one: hundrededel | ||
other: hundrededele | ||
thousandths: | ||
one: tusindedel | ||
other: tusindedele | ||
millionths: | ||
one: milliontedel | ||
other: milliontedele | ||
micro_separator: og | ||
micro_prefix: | ||
tens: ti | ||
hundreds: hundrede | ||
union: '-' | ||
union: og |
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
56 changes: 56 additions & 0 deletions
56
lib/numbers_and_words/strategies/figures_converter/languages/da.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,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Languages | ||
class Da < Base | ||
def print_words | ||
complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join(' ') | ||
end | ||
|
||
def ones | ||
super({ gender: gender }) | ||
end | ||
|
||
def hundreds | ||
super({ is_hundred: hundred?, is_one_hundred: one_hundred? }) | ||
end | ||
|
||
def megs | ||
super({ number: @figures.number_in_capacity(@current_capacity) }) | ||
end | ||
|
||
private | ||
|
||
def simple_part | ||
@strings.reject { |f| f.is_a?(Array) } | ||
end | ||
|
||
def complex_part | ||
@strings - simple_part | ||
end | ||
|
||
def hundred? | ||
figures[0].zero? && figures[1].zero? && simple_number_to_words.empty? | ||
end | ||
|
||
def one_hundred? | ||
hundred? && figures[2] == 1 | ||
end | ||
|
||
def gender | ||
@current_capacity ||= 0 | ||
if @current_capacity.zero? | ||
@options.gender.result | ||
elsif @current_capacity == 1 | ||
:neuter | ||
else | ||
:common | ||
end | ||
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
3 changes: 3 additions & 0 deletions
3
lib/numbers_and_words/strategies/figures_converter/options/da.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 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'numbers_and_words/strategies/figures_converter/options/da/gender' |
14 changes: 14 additions & 0 deletions
14
lib/numbers_and_words/strategies/figures_converter/options/da/gender.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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Options | ||
module Da | ||
class Gender < Base::Gender | ||
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module NumbersAndWords | ||
module Translations | ||
class Da < Base | ||
include NumbersAndWords::Translations::Families::Base | ||
|
||
DEFAULT_POSTFIX = nil | ||
|
||
def ones(number, options = {}) | ||
return t(:common)[number] if options[:gender] == :common | ||
return t(:neuter)[number] if options[:gender] == :neuter | ||
|
||
t([options[:prefix], :ones, options[:postfix] || DEFAULT_POSTFIX].join('.'))[number] | ||
end | ||
|
||
def tens(number, _options = {}) | ||
t(:tens)[number] | ||
end | ||
|
||
def tens_with_ones(numbers, _options = {}) | ||
[ones(numbers[0], { gender: :common }), tens(numbers[1])].join(union) | ||
end | ||
|
||
def hundreds(number, options = {}) | ||
return t(:one_hundred) if options[:is_one_hundred] | ||
return t(:hundreds)[number] if options[:is_hundred] | ||
|
||
t(:hundreds)[number] | ||
end | ||
|
||
def zero(_options = {}) | ||
ones 0 | ||
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module NumbersAndWords | ||
VERSION = '0.11.13' | ||
VERSION = '0.12.0' | ||
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,47 @@ | ||
to_words: | ||
simple_example: | ||
? | ||
- 1 | ||
- 2 | ||
- 3 | ||
: | ||
- et | ||
- to | ||
- tre | ||
complex_example: | ||
? | ||
- 100 | ||
- 21 | ||
- 13 | ||
: | ||
- et hundrede | ||
- enogtyve | ||
- tretten | ||
complex_example2: | ||
? | ||
- 101 | ||
- 203 | ||
- 209 | ||
: | ||
- et hundrede et | ||
- to hundrede tre | ||
- to hundrede ni | ||
complex_example3: | ||
? | ||
- 561 | ||
- 422 | ||
- 932 | ||
: | ||
- fem hundrede enogtres | ||
- fire hundrede toogtyve | ||
- ni hundrede toogtredive | ||
complex_example4: | ||
? | ||
- 1111 | ||
- 2222 | ||
- 6398 | ||
: | ||
- et tusinde et hundrede elleve | ||
- to tusinde to hundrede toogtyve | ||
- seks tusinde tre hundrede otteoghalvfems | ||
|
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,5 @@ | ||
to_words: | ||
ones: | ||
0: nul | ||
1: et | ||
9: ni |