Skip to content
Convert numbers to words using I18N.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec Include rubocop-performance and rubocop-rspec gems (#166) May 18, 2019
.editorconfig Add `.editorconfig` file Jun 8, 2017
.gitignore
.rubocop.yml Include rubocop-performance and rubocop-rspec gems (#166) May 18, 2019
.rubocop_todo.yml Include rubocop-performance and rubocop-rspec gems (#166) May 18, 2019
.travis.yml Do not test against Ruby 2.3 Apr 4, 2019
CHANGELOG.md Release 0.11.6 Apr 14, 2019
CONTRIBUTING.md Added CONTRIBUTING, closes #74. Mar 9, 2016
Gemfile Include rubocop-performance and rubocop-rspec gems (#166) May 18, 2019
LICENSE.txt Updated copyright year. Mar 24, 2012
README.rdoc Silence Jeweler warnings (#159) Apr 16, 2019
Rakefile Bump the gem's required ruby version May 3, 2019
numbers_and_words.gemspec Release 0.11.6 Apr 14, 2019

README.rdoc

numbers_and_words

Gem
Version Coverage Status

Spell out numbers in several languages using the I18n gem.

Перевод чисел в слова при помощи библиотеки I18n.

Converti les nombres en lettres en utilisant la librairie I18n.

Számok betűvel írva az I18n könyvtár segítségével.

I18n kütüphanesi ile sayıları yazıya çevirir.

Soletra números em vários idiomas utilizando a biblioteca I18n.

Supported Languages / Языки / Langues Supportées

  • English [en]

  • Spanish [es]

  • Русский [ru]

  • Français [fr]

  • Українська [ua]

  • Magyar [hu]

  • Lietuvių [lt]

  • Latviešu [lv]

  • Eesti [et]

  • ქართული (Georgian) [ka]

  • Türkçe [tr]

  • Deutsch** [de]

  • Italiano** [it]

  • Nederlands** [nl]

  • Swedish** [se]

  • English (British)** [en-GB]

  • Česky [cs]

  • Português [pt]

  • Português Brasileiro [pt-BR]

  • հայերեն (Armenian) [hy]

** Experimental

  • {[en-AU], [en-CA], [en-IN], [en-US]}*** => [en]

  • {[es-419], [es-AR], [es-CL], [es-CO], [es-MX], [es-PE], [es-VE]}*** => [es]

  • {[fr-CA], [fr-CH]}*** => [fr]

  • {[de], [de-AT], [de-CH]}*** => [de]

  • {[it-CH]}*** => [it]

*** Aliases

Examples / Примеры / Exemples

I18n.with_locale(:en) { 42.to_words }
=> "forty-two"

I18n.with_locale(:es) { 42.to_words }
=> "cuarenta y dos"

I18n.with_locale(:ru) { 42.to_words }
=> "сорок два"

I18n.with_locale(:fr) { 42.to_words }
=> "quarante-deux"

I18n.with_locale(:hu) { 42.to_words }
=> "negyvenkettő"

I18n.with_locale(:lt) { 42.to_words }
=> "keturiasdešimt du"

I18n.with_locale(:lv) { 42.to_words }
=> "četrdesmit divi"

I18n.with_locale(:et) { 42.to_words }
=> "nelikümmend kaks"

I18n.with_locale(:ka) { 42.to_words }
=> "ორმოცდაორი"

I18n.with_locale(:cs) { 42.to_words }
=> "čtyřicetdva"

I18n.with_locale(:vi) { 42.to_words }
=> "bốn mươi hai"

I18n.with_locale(:hy) { 42.to_words }
=> "քառասուն երկու"

21.to_words
=> "twenty-one"
=> "veintiuno"
=> "двадцать один"
=> "vingt et un"
=> "двадцять один"
=> "huszonegy"
=> "dvidešimt vienas"
=> "divdesmit viens"
=> "kakskümmend üks"
=> "yirmi bir"
=> "ოცდაერთი"
=> "einundzwanzig"
=> "ventiuno"
=> "éénentwintig"
=> "tjugo-en"
=> "dvacetjedna"
=> "vinte e um"
=> "hai mươi mốt"
=> "քսան մեկ"

231.to_words
=> "two hundred thirty-one"
=> "doscientos treinta y uno"
=> "двести тридцать один"
=> "deux cent trente et un"
=> "двiстi тридцять один"
=> "kettőszázharmincegy"
=> "du šimtai trisdešimt vienas"
=> "divi simti trīsdesmit viens"
=> "kakssada kolmkümmend üks"
=> "ორას ოცდათერთმეტი"
=> "iki yüz otuz bir"
=> "zweihunderteinunddreißig"
=> "2 cento trentauno"
=> "tweehonderdéénendertig"
=> "två hundra trettio-en"
=> "dvě stě třicetjedna"
=> "duzentos e trinta e um"
=> "hai trăm ba mươi mốt"
=> "երկու հարյուր երեսուն մեկ"

4030.to_words
=> "four thousand thirty"
=> "cuatro mil treinta"
=> "четыре тысячи тридцать"
=> "quatre mille trente"
=> "чотири тисячi тридцять"
=> "négyezer-harminc"
=> "keturi tūkstančiai trisdešimt"
=> "četri tūkstoši trīsdesmit"
=> "neli tuhat kolmkümmend"
=> "ოთხი ათას ოცდაათი"
=> "dört bin otuz"
=> "viertausenddreißig"
=> "quattro mille trenta"
=> "vierthousanddertig"
=> "fyra tusen trettio"
=> "čtyři tisíce třicet"
=> "bốn nghìn không trăm ba mươi"
=> "չորս հազար երեսուն"

1000100.to_words
=> "one million one hundred"
=> "un millón cien"
=> "один миллион сто"
=> "un million cent"
=> "один мiльйон сто"
=> "egymillió-egyszáz"
=> "milijonas šimtas"
=> "viens miljons simts"
=> "üks miljon ükssada"
=> "ერთი მილიონ ასი"
=> "bir milyon yüz"
=> "eine Million einhundert"
=> "uno milione 1 cento"
=> "één miljoen honderd"
=> "en miljoner en hundra"
=> "jeden milión jedno sto"
=> "một triệu một trăm"
=> "մեկ միլիոն հարյուր"

1000000000000000000000000000000000.to_words
=> "one decillion"
=> "mil quintillones"
=> "один дециллион"
=> "un quintilliard"
=> "один децильйон"
=> "egykvintilliárd"
=> "vienas decilijonas"
=> "viens deciljons"
=> "üks dekiljon"
=> "bir desilyon"
=> "eine Quintilliarde"
=> "uno decillion"
=> "één decillion"
=> "en decillion"
=> "decilijon"

[1, 2, 3].to_words
=> ["one", "two", "three"]
=> ["uno", "dos", "tres"]
=> ["один", "два", "три"]
=> ["un", "deux", "trois"]
=> ["egy", "kettő", "három"]
=> ["vienas", "du", "trys"]
=> ["viens", "divi", "trīs"]
=> ["üks", "kaks", "kolm"]
=> ["ერთი", "ორი", "სამი"]
=> ["jedna", "dva", "tři"]
=> ["một", "hai", "ba"]
=> ["մեկ", "երկու", "երեք"]

[11, 22, 133].to_words
=> ["eleven", "twenty-two", "one hundred thirty-three"]
=> ["once", "veintidós", "ciento treinta y tres"]
=> ["одиннадцать", "двадцать два", "сто тридцать три"]
=> ["onze", "vingt-deux", "cent trente-trois"]
=> ["одинадцять", "двадцять два", "сто тридцять три"]
=> ["tizenegy", "huszonkettő", "egyszázharminchárom"]
=> ["vienuolika", "dvidešimt du", "šimtas trisdešimt trys"]
=> ["vienpadsmit", "divdesmit divi", "simtu trīsdesmit trīs"]
=> ["üksteist", "kakskümmend kaks", "ükssada kolmkümmend kolm"]
=> ["თერთმეტი", "ოცდაორი", "ას ოცდაცამეტი"]
=> ["on bir", "yirmi iki", "yüz otuz üç"]
=> ["elf", "zweiundzwanzig", "einhundertdreiunddreißig"]
=> ["undici", "ventidue", "1 cento trentatre"]
=> ["elf", "tweeentwintig", "honderddrieendertig"]
=> ["elva", "tjugo-två", "en hundra trettio-tre"]
=> ["jedenáct", "dvacetdva", "jedno sto třicettři"]
=> ["mười một", "hai mươi hai", "một trăm ba mươi ba"]
=> ["տասնմեկ", "քսան երկու", "հարյուր երեսուն երեք"]

21.77.to_words
=> "twenty-one and seventy-seven hundredths"
=> "двадцать одна целая и семьдесят семь сотых"
=> "двадцять одна цiла i сiмдесят сiм сотих"
=> "huszonegy egész hetvenhét század"
=> "twenty-one point seven seven"
=> "hai mươi mốt phẩy bảy mươi bảy"

Language options / Языковые опции

  • English / British

    Ordinal form: (ordinal: [true || false])

    I18n.with_locale(:en) { 21.to_words ordinal: true }
    => "twenty-first"

    Remove hyphen between tens and ones: (remove_hyphen: [true || false])

    I18n.with_locale(:en) { 21.to_words remove_hyphen: true }
    => "twenty one"

    Add 'and' between hundreds and tens: (hundreds_with_union: [true || false])

    I18n.with_locale(:en) { 111.to_words hundreds_with_union: true }
    => "one hundred and eleven"

    Remove 'zero' from integral part of float: (remove_zero: [true || false])

    I18n.with_locale(:en) { 0.7.to_words remove_zero: true }
    => "seven tenths"
    
    I18n.with_locale(:en) { [0.1, 0.31, 0.12].to_words remove_zero: true }
    => ["one tenth", "thirty-one hundredths", "twelve hundredths"]
  • Russian

    Change gender form: (gender: [:female || :male || :neuter])

    I18n.with_locale(:ru) { 1001.to_words gender: :neuter }
    => "одна тысяча одно"
  • Ukranian

    Change gender form: (gender: [:female || :male || :neuter])

    I18n.with_locale(:ru) { 1001.to_words gender: :neuter }
    => "одна тисяча одне"
  • Hungarian

    Ordinal form: (ordinal: [true || false])

    I18n.with_locale(:hu) { 21.to_words ordinal: true }
    => "huszonegyedik"
  • Brazilian Portuguese

    Change gender form: (gender: [:female || :male || :neuter])

    I18n.with_locale(:'pt-BR') { 1000000001.to_words gender: :female }
    => "um bilhão e uma"
  • Czech

    Change gender form: (gender: [:female || :male || :neuter])

    I18n.with_locale(:'cs') { 1.to_words gender: :female }
    => "jedna"
    
    I18n.with_locale(:'cs') { 1.to_words gender: :male }
    => "jeden"
    
    I18n.with_locale(:'cs') { 1.to_words gender: :neuter }
    => "jedno"

    Remove 'zero' from integral part of float: (remove_zero: [true || false])

    I18n.with_locale(:cs) { 0.7.to_words }
    => "nula celých sedm desetin"
    
    I18n.with_locale(:cs) { 0.7.to_words remove_zero: true }
    => "sedm desetin"

    Ordinal form: (ordinal: [true || false])

    I18n.with_locale(:cs) { 21.to_words ordinal: true }
    => "dvacátý první"
    
    I18n.with_locale(:cs) { 21.to_words gender: :female, ordinal: true }
    => "dvacátá první"

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

  • precision

    You may pass argument :precision that added zeros to the end of float number:

    I18n.with_locale(:ru) { 0.1.to_words precision: 3 }
    => ноль целых и десять сотых

Requirements / Требования / Configuration Requise

  • 2.3 <= Ruby (compatible with/совместимость с/compatible avec Ruby 2.3 and/и/et JRuby);

  • 0.5.0 <= I18n (earlier versions not tested/ранние версии не тестировались/versions précédentes non testées);

Installation / Установка / Installation

gem install numbers_and_words

License / Лицензия / Licence

MIT License

Bugs and Language Support / Поправки и Новые Языки / Bugs et Support d'autres Langues

See CHANGELOG.md for last changes.

Fork the project. Make your feature addition or bug fix with tests.

Send a pull request. Bonus points for topic branches.

Contacts / Контакты / Contacts

You can’t perform that action at this time.