Skip to content

Commit

Permalink
Merge branch 'master' into strings
Browse files Browse the repository at this point in the history
  • Loading branch information
kkonieczny committed Jan 18, 2019
2 parents 446e918 + 83cfcdc commit e459021
Show file tree
Hide file tree
Showing 75 changed files with 2,501 additions and 1,446 deletions.
26 changes: 26 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Changelog
=========

Version 0.5.9 -- 2019/01/10
---------------------------

* Fix encoding issue on release 0.5.8 (#229)
* Improve Polish localization (#228)


Version 0.5.8 -- 2018/11/17
---------------------------

* Add Portuguese (Portugal) localization (#198)
* Add a command line tool to use num2words
* Use language iso code for Vietnamese
* Improve Korean localization (#219)
* Improve Serbian (Latin) localization (#207)
* Improve testing setup (#220)
* Improve German localization (#214) (#222)
* Improve Romanian localization (#215)
* Improve Spanish localization (#187) (#200)
* Improve Russian localization (#211) (#212)
* Improve French localization (23902ab)
* Improve Arabic localization (#176)
* Improve Lithuanian and Latvian localization (#185)
* Improve Ukrainian localization (#183)


Version 0.5.7 -- 2018/06/27
---------------------------

Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Command line::

$ num2words 10001
ten thousand and one
$ num2words 10123123 --lang es
diez millones ciento veintitrés mil ciento veintitrés
$ num2words 24,120.10
twenty-four thousand, one hundred and twenty point one
$ num2words 24,120.10 -l es
Expand Down Expand Up @@ -97,12 +95,15 @@ Besides the numerical argument, there are two main optional arguments.
* ``id`` (Indonesian)
* ``it`` (Italian)
* ``ja`` (Japanese)
* ``ko`` (Korean)
* ``lt`` (Lithuanian)
* ``lv`` (Latvian)
* ``no`` (Norwegian)
* ``pl`` (Polish)
* ``pt`` (Portuguese)
* ``pt_BR`` (Portuguese - Brazilian)
* ``sl`` (Slovene)
* ``sr`` (Serbian)
* ``ro`` (Romanian)
* ``ru`` (Russian)
* ``sl`` (Slovene)
Expand Down
22 changes: 18 additions & 4 deletions bin/num2words
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

"""num2words: convert numbers into words.
Usage:
Expand All @@ -22,9 +38,6 @@ Options:
Examples:
$ num2words 10001
ten thousand and one
$ num2words 10123123 --lang es
diez millones ciento veintitrés mil ciento veintitrés
$ num2words 24,120.10
twenty-four thousand, one hundred and twenty point one
Expand All @@ -35,13 +48,14 @@ Examples:
$num2words 2.14 -l es --to currency
dos euros con catorce centimos
"""

from __future__ import print_function, unicode_literals
import os
import sys
from docopt import docopt
import num2words

__version__ = "0.5.7"
__version__ = "0.5.9"
__license__ = "LGPL"


Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.0'
services:
web:
image: python:3-alpine
command: python3 -m http.server 8080
volumes:
- .:/num2words
5 changes: 5 additions & 0 deletions num2words/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down Expand Up @@ -47,7 +48,9 @@
from . import lang_NL
from . import lang_UK
from . import lang_SL
from . import lang_SR
from . import lang_TH
from . import lang_KO

CONVERTER_CLASSES = {
'ar': lang_AR.Num2Word_AR(),
Expand All @@ -65,12 +68,14 @@
'es_VE': lang_ES_VE.Num2Word_ES_VE(),
'id': lang_ID.Num2Word_ID(),
'ja': lang_JA.Num2Word_JA(),
'ko': lang_KO.Num2Word_KO(),
'lt': lang_LT.Num2Word_LT(),
'lv': lang_LV.Num2Word_LV(),
'pl': lang_PL.Num2Word_PL(),
'ro': lang_RO.Num2Word_RO(),
'ru': lang_RU.Num2Word_RU(),
'sl': lang_SL.Num2Word_SL(),
'sr': lang_SR.Num2Word_SR(),
'no': lang_NO.Num2Word_NO(),
'dk': lang_DK.Num2Word_DK(),
'pt': lang_PT.Num2Word_PT(),
Expand Down
1 change: 1 addition & 0 deletions num2words/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
3 changes: 2 additions & 1 deletion num2words/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2016, Savoir-faire Linux inc. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down
17 changes: 17 additions & 0 deletions num2words/currency.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import division

from decimal import ROUND_HALF_UP, Decimal
Expand Down
7 changes: 6 additions & 1 deletion num2words/lang_CZ.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand All @@ -14,6 +14,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import unicode_literals

from .base import Num2Word_Base
Expand Down Expand Up @@ -130,6 +131,10 @@ def _int2word(self, n):
i = len(chunks)
for x in chunks:
i -= 1

if x == 0:
continue

n1, n2, n3 = get_digits(x)

if n3 > 0:
Expand Down
45 changes: 35 additions & 10 deletions num2words/lang_DE.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from __future__ import print_function, unicode_literals

import re

from .lang_EU import Num2Word_EU


Expand Down Expand Up @@ -45,7 +47,7 @@ def setup(self):
self.errmsg_toobig = "Die Zahl %s muss kleiner als %s sein."
self.exclude_title = []

lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
lows = ["Non", "Okt", "Sept", "Sext", "Quint", "Quadr", "Tr", "B", "M"]
units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept",
"okto", "novem"]
tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
Expand Down Expand Up @@ -78,7 +80,9 @@ def merge(self, curr, next):
ctext, cnum, ntext, nnum = curr + next

if cnum == 1:
if nnum < 10 ** 6:
if nnum == 100 or nnum == 1000:
return ("ein" + ntext, nnum)
elif nnum < 10 ** 6:
return next
ctext = "eine"

Expand All @@ -105,26 +109,47 @@ def merge(self, curr, next):

def to_ordinal(self, value):
self.verify_ordinal(value)
outword = self.to_cardinal(value)
outword = self.to_cardinal(value).lower()
for key in self.ords:
if outword.endswith(key):
outword = outword[:len(outword) - len(key)] + self.ords[key]
break
return outword + "te"

res = outword + "te"

# Exception: "hundertste" is usually preferred over "einhundertste"
if res == "eintausendste" or res == "einhundertste":
res = res.replace("ein", "", 1)
# ... similarly for "millionste" etc.
res = re.sub(r'eine ([a-z]+(illion|illiard)ste)$',
lambda m: m.group(1), res)
# Ordinals involving "Million" etc. are written without a space.
# see https://de.wikipedia.org/wiki/Million#Sprachliches
res = re.sub(r' ([a-z]+(illion|illiard)ste)$',
lambda m: m.group(1), res)

return res

def to_ordinal_num(self, value):
self.verify_ordinal(value)
return str(value) + "."

def to_currency(self, val, longval=True, old=False):
hightxt = "euro"
lowtxt = "cent"
hightxt = "Euro"
lowtxt = "Cent"
if old:
hightxt = "mark"
lowtxt = "pfennig/e"
hightxt = "Mark"
lowtxt = "Pfennig/e"

cents = int(round(val*100))
res = self.to_splitnum(cents, hightxt=hightxt, lowtxt=lowtxt,
jointxt="und", longval=longval)

# Handle exception, in german is "ein Euro" and not "eins Euro"
if res.startswith("eins "):
res = res.replace("eins ", "ein ", 1)

return self.to_splitnum(val, hightxt=hightxt, lowtxt=lowtxt,
jointxt="und", longval=longval)
return res

def to_year(self, val, longval=True):
if not (val // 100) % 10:
Expand Down
1 change: 1 addition & 0 deletions num2words/lang_DK.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
1 change: 1 addition & 0 deletions num2words/lang_EN.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
1 change: 1 addition & 0 deletions num2words/lang_EN_IN.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
3 changes: 1 addition & 2 deletions num2words/lang_ES.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8

# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
3 changes: 1 addition & 2 deletions num2words/lang_ES_CO.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8

# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
3 changes: 1 addition & 2 deletions num2words/lang_ES_VE.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: UTF-8

# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
2 changes: 1 addition & 1 deletion num2words/lang_EU.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
4 changes: 2 additions & 2 deletions num2words/lang_FR.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down Expand Up @@ -89,7 +89,7 @@ def to_ordinal(self, value):
def to_ordinal_num(self, value):
self.verify_ordinal(value)
out = str(value)
out += {"1": "er"}.get(out[-1], "me")
out += "er" if value == 1 else "me"
return out

def to_currency(self, val, longval=True, old=False):
Expand Down
2 changes: 1 addition & 1 deletion num2words/lang_FR_BE.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
3 changes: 1 addition & 2 deletions num2words/lang_FR_CH.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand All @@ -14,7 +14,6 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA

from __future__ import print_function, unicode_literals

from .lang_FR import Num2Word_FR
Expand Down
1 change: 1 addition & 0 deletions num2words/lang_FR_DZ.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.

Expand Down
Loading

0 comments on commit e459021

Please sign in to comment.