Skip to content

Commit

Permalink
feat: add support for danish language (kslazarev#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Franta1205 authored May 17, 2024
1 parent 3bba757 commit 91f0f27
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
pkg
Gemfile.lock
.bundle
.idea
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.11.13 (Next)
## 0.12.0 (Next)

### Features
* Add support for Danish language. \[[#197](https://github.com/kslazarev/numbers_and_words/pull/197)\] \([@franta](https://github.com/Franta1205)\)
* Upgrade RuboCop to 1.63.5. \[[#198](https://github.com/kslazarev/numbers_and_words/pull/198)\]
* Your contribution here.

Expand Down
20 changes: 20 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
* Português Brasileiro [pt-BR]
* հայերեն (Armenian) [hy]
* Қазақша [kz]
* Dansk [da]

** Experimental

Expand Down Expand Up @@ -93,6 +94,9 @@ Deletrea números en varios idiomas utilizando la gema I18n.
I18n.with_locale(:kz) { 42.to_words }
=> "қырық екi"

I18n.with_locale(:da) { 42.to_words }
=> "toogfyrre"

21.to_words
=> "twenty-one"
=> "veintiuno"
Expand All @@ -114,6 +118,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "hai mươi mốt"
=> "քսան մեկ"
=> "жиырма бiр"
=> "enogtyve"

231.to_words
=> "two hundred thirty-one"
Expand All @@ -136,6 +141,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "hai trăm ba mươi mốt"
=> "երկու հարյուր երեսուն մեկ"
=> "екi жүз отыз бiр"
=> "to hundrede enogtredive"

4030.to_words
=> "four thousand thirty"
Expand All @@ -157,6 +163,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "bốn nghìn không trăm ba mươi"
=> "չորս հազար երեսուն"
=> "төрт мың отыз"
=> "fire tusinde tredive"

1000100.to_words
=> "one million one hundred"
Expand All @@ -178,6 +185,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> "một triệu một trăm"
=> "մեկ միլիոն հարյուր"
=> "бiр миллион бiр жүз"
=> "en million et hundrede"

1000000000000000000000000000000000.to_words
=> "one decillion"
Expand Down Expand Up @@ -211,6 +219,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> ["một", "hai", "ba"]
=> ["մեկ", "երկու", "երեք"]
=> ["бiр", "екi", "үш"]
=> ["et", "to", "tre"]

[11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"]
Expand All @@ -232,6 +241,7 @@ Deletrea números en varios idiomas utilizando la gema I18n.
=> ["mười một", "hai mươi hai", "một trăm ba mươi ba"]
=> ["տասնմեկ", "քսան երկու", "հարյուր երեսուն երեք"]
=> ["он бiр", "жиырма екi", "бiр жүз отыз үш"]
=> ["elleve", "toogtyve", "et hundrede treogtredive"]

21.77.to_words
=> "twenty-one and seventy-seven hundredths"
Expand Down Expand Up @@ -353,6 +363,16 @@ Deletrea números en varios idiomas utilizando la gema I18n.
I18n.with_locale(:es) { 0.7.to_words remove_zero: true }
=> "siete décimas"

* Danish

Change gender from: (gender: [:neuter || :common])

I18n.with_locale(:da) { 1.to_words gender: :common }
=> "en"

I18n.with_locale(:da) { 1.to_words gender: :neuter }
=> "et"

== Other options / Другие опции

* Precision
Expand Down
52 changes: 52 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.da.yml
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require 'numbers_and_words/strategies/figures_converter/languages/tr'
require 'numbers_and_words/strategies/figures_converter/languages/hy'
require 'numbers_and_words/strategies/figures_converter/languages/kz'
require 'numbers_and_words/strategies/figures_converter/languages/da'

require 'numbers_and_words/strategies/figures_converter/languages/families/cyrillic'
require 'numbers_and_words/strategies/figures_converter/languages/ru'
Expand Down
56 changes: 56 additions & 0 deletions lib/numbers_and_words/strategies/figures_converter/languages/da.rb
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'numbers_and_words/strategies/figures_converter/options/ru'
require 'numbers_and_words/strategies/figures_converter/options/ua'
require 'numbers_and_words/strategies/figures_converter/options/cs'
require 'numbers_and_words/strategies/figures_converter/options/da'

module NumbersAndWords
module Strategies
Expand Down
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'
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
1 change: 1 addition & 0 deletions lib/numbers_and_words/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require 'numbers_and_words/translations/vi'
require 'numbers_and_words/translations/hy'
require 'numbers_and_words/translations/kz'
require 'numbers_and_words/translations/da'

module NumbersAndWords
module Translations
Expand Down
37 changes: 37 additions & 0 deletions lib/numbers_and_words/translations/da.rb
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
2 changes: 1 addition & 1 deletion lib/numbers_and_words/version.rb
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
9 changes: 7 additions & 2 deletions numbers_and_words.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
# stub: numbers_and_words 0.11.12 ruby lib
# stub: numbers_and_words 0.12.0 ruby lib

Gem::Specification.new do |s|
s.name = "numbers_and_words".freeze
Expand All @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Kirill Lazarev".freeze]
s.date = "2023-04-22"
s.date = "2023-11-15"
s.description = "This gem spells out numbers in several languages using the I18n gem.".freeze
s.email = "k.s.lazarev@gmail.com".freeze
s.extra_rdoc_files = [
Expand All @@ -32,6 +32,7 @@ Gem::Specification.new do |s|
"lib/numbers_and_words/i18n.rb",
"lib/numbers_and_words/i18n/initialization.rb",
"lib/numbers_and_words/i18n/locales/numbers.cs.yml",
"lib/numbers_and_words/i18n/locales/numbers.da.yml",
"lib/numbers_and_words/i18n/locales/numbers.de.yml",
"lib/numbers_and_words/i18n/locales/numbers.en-GB.yml",
"lib/numbers_and_words/i18n/locales/numbers.en.yml",
Expand Down Expand Up @@ -121,6 +122,7 @@ Gem::Specification.new do |s|
"lib/numbers_and_words/strategies/figures_converter/languages.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/base.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/cs.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/da.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/de.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/en-GB.rb",
"lib/numbers_and_words/strategies/figures_converter/languages/en.rb",
Expand Down Expand Up @@ -182,9 +184,12 @@ Gem::Specification.new do |s|
"lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb",
"lib/numbers_and_words/strategies/figures_converter/options/ua.rb",
"lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb",
"lib/numbers_and_words/strategies/figures_converter/options/da/gender.rb",
"lib/numbers_and_words/strategies/figures_converter/options/da.rb",
"lib/numbers_and_words/translations.rb",
"lib/numbers_and_words/translations/base.rb",
"lib/numbers_and_words/translations/cs.rb",
"lib/numbers_and_words/translations/da.rb",
"lib/numbers_and_words/translations/de.rb",
"lib/numbers_and_words/translations/en-GB.rb",
"lib/numbers_and_words/translations/en.rb",
Expand Down
47 changes: 47 additions & 0 deletions spec/numbers_and_words/array/fixture_examples/da.yml
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

5 changes: 5 additions & 0 deletions spec/numbers_and_words/integer/fixture_examples/da.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
to_words:
ones:
0: nul
1: et
9: ni

0 comments on commit 91f0f27

Please sign in to comment.