mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge branch 'master' into patch-1
This commit is contained in:
@@ -107,6 +107,7 @@ Besides the numerical argument, there are two main optional arguments.
|
||||
* ``pt_BR`` (Portuguese - Brazilian)
|
||||
* ``sl`` (Slovene)
|
||||
* ``sr`` (Serbian)
|
||||
* ``sv`` (Swedish)
|
||||
* ``ro`` (Romanian)
|
||||
* ``ru`` (Russian)
|
||||
* ``te`` (Telugu)
|
||||
|
||||
@@ -22,8 +22,8 @@ from . import (lang_AR, lang_CZ, lang_DE, lang_DK, lang_EN, lang_EN_IN,
|
||||
lang_FR_BE, lang_FR_CH, lang_FR_DZ, lang_HE, lang_HU, lang_ID,
|
||||
lang_IT, lang_JA, lang_KN, lang_KO, lang_KZ, lang_LT, lang_LV,
|
||||
lang_NL, lang_NO, lang_PL, lang_PT, lang_PT_BR, lang_RO,
|
||||
lang_RU, lang_SL, lang_SR, lang_TE, lang_TH, lang_TR, lang_UK,
|
||||
lang_VI)
|
||||
lang_RU, lang_SL, lang_SR, lang_SV, lang_TE, lang_TH, lang_TR,
|
||||
lang_UK, lang_VI)
|
||||
|
||||
CONVERTER_CLASSES = {
|
||||
'ar': lang_AR.Num2Word_AR(),
|
||||
@@ -52,6 +52,7 @@ CONVERTER_CLASSES = {
|
||||
'ru': lang_RU.Num2Word_RU(),
|
||||
'sl': lang_SL.Num2Word_SL(),
|
||||
'sr': lang_SR.Num2Word_SR(),
|
||||
'sv': lang_SV.Num2Word_SV(),
|
||||
'no': lang_NO.Num2Word_NO(),
|
||||
'dk': lang_DK.Num2Word_DK(),
|
||||
'pt': lang_PT.Num2Word_PT(),
|
||||
@@ -67,7 +68,6 @@ CONVERTER_CLASSES = {
|
||||
'hu': lang_HU.Num2Word_HU()
|
||||
}
|
||||
|
||||
|
||||
CONVERTES_TYPES = ['cardinal', 'ordinal', 'ordinal_num', 'year', 'currency']
|
||||
|
||||
|
||||
|
||||
@@ -21,13 +21,190 @@ import math
|
||||
|
||||
from .lang_EU import Num2Word_EU
|
||||
|
||||
GENERIC_DOLLARS = ('dolar', 'dólares')
|
||||
GENERIC_CENTS = ('centavo', 'centavos')
|
||||
CURRENCIES_UNA = ('SLL', 'SEK', 'NOK', 'CZK', 'DKK', 'ISK',
|
||||
'SKK', 'GBP', 'CYP', 'EGP', 'FKP', 'GIP',
|
||||
'LBP', 'SDG', 'SHP', 'SSP', 'SYP', 'INR',
|
||||
'IDR', 'LKR', 'MUR', 'NPR', 'PKR', 'SCR',
|
||||
'ESP')
|
||||
|
||||
|
||||
class Num2Word_ES(Num2Word_EU):
|
||||
CURRENCY_FORMS = {
|
||||
'EUR': (('euro', 'euros'), ('céntimo', 'céntimos')),
|
||||
'ESP': (('peseta', 'pesetas'), ('céntimo', 'céntimos')),
|
||||
'USD': (('dolar', 'dólares'), ('centavo', 'centavos')),
|
||||
'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'PEN': (('sol', 'soles'), ('céntimo', 'céntimos')),
|
||||
'CRC': (('colón', 'colones'), GENERIC_CENTS),
|
||||
'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'GBP': (('libra', 'libras'), ('penny', 'pence')),
|
||||
'RUB': (('rublo', 'rublos'), ('kopeyka', 'kopeykas')),
|
||||
'SEK': (('corona', 'coronas'), ('öre', 'öre')),
|
||||
'NOK': (('corona', 'coronas'), ('øre', 'øre')),
|
||||
'PLN': (('zloty', 'zlotys'), ('grosz', 'groszy')),
|
||||
'MXN': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'RON': (('leu', 'leus'), ('ban', 'bani')),
|
||||
'INR': (('rupia', 'rupias'), ('paisa', 'paisas')),
|
||||
'HUF': (('florín', 'florines'), ('fillér', 'fillér')),
|
||||
'FRF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'CNY': (('yuan', 'yuanes'), ('fen', 'jiaos')),
|
||||
'CZK': (('corona', 'coronas'), ('haléř', 'haléř')),
|
||||
'NIO': (('córdoba', 'córdobas'), GENERIC_CENTS),
|
||||
'VES': (('bolívar', 'bolívares'), ('céntimo', 'céntimos')),
|
||||
'BRL': (('real', 'reales'), GENERIC_CENTS),
|
||||
'CHF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'JPY': (('yen', 'yenes'), ('sen', 'sen')),
|
||||
'KRW': (('won', 'wones'), ('jeon', 'jeon')),
|
||||
'KPW': (('won', 'wones'), ('chon', 'chon')),
|
||||
'TRY': (('lira', 'liras'), ('kuruş', 'kuruş')),
|
||||
'ZAR': (('rand', 'rands'), ('céntimo', 'céntimos')),
|
||||
'KZT': (('tenge', 'tenges'), ('tïın', 'tïın')),
|
||||
'UAH': (('hryvnia', 'hryvnias'), ('kopiyka', 'kopiykas')),
|
||||
'THB': (('baht', 'bahts'), ('satang', 'satang')),
|
||||
'AED': (('dirham', 'dirhams'), ('fils', 'fils')),
|
||||
'AFN': (('afghani', 'afghanis'), ('pul', 'puls')),
|
||||
'ALL': (('lek ', 'leke'), ('qindarkë', 'qindarka')),
|
||||
'AMD': (('dram', 'drams'), ('luma', 'lumas')),
|
||||
'ANG': (('florín', 'florines'), GENERIC_CENTS),
|
||||
'AOA': (('kwanza', 'kwanzas'), ('céntimo', 'céntimos')),
|
||||
'ARS': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'AWG': (('florín', 'florines'), GENERIC_CENTS),
|
||||
'AZN': (('manat', 'manat'), ('qəpik', 'qəpik')),
|
||||
'BBD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'BDT': (('taka', 'takas'), ('paisa', 'paisas')),
|
||||
'BGN': (('lev', 'leva'), ('stotinka', 'stotinki')),
|
||||
'BHD': (('dinar', 'dinares'), ('fils', 'fils')),
|
||||
'BIF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'BMD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'BND': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'BOB': (('boliviano', 'bolivianos'), GENERIC_CENTS),
|
||||
'BSD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'BTN': (('ngultrum', 'ngultrum'), ('chetrum', 'chetrum')),
|
||||
'BWP': (('pula', 'pulas'), ('thebe', 'thebes')),
|
||||
'BYN': (('rublo', 'rublos'), ('kópek', 'kópeks')),
|
||||
'BYR': (('rublo', 'rublos'), ('kópek', 'kópeks')),
|
||||
'BZD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'CDF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'CLP': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'COP': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'CUP': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'CVE': (('escudo', 'escudos'), GENERIC_CENTS),
|
||||
'CYP': (('libra', 'libras'), ('céntimo', 'céntimos')),
|
||||
'DJF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'DKK': (('corona', 'coronas'), ('øre', 'øre')),
|
||||
'DOP': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'DZD': (('dinar', 'dinares'), ('céntimo', 'céntimos')),
|
||||
'ECS': (('sucre', 'sucres'), GENERIC_CENTS),
|
||||
'EGP': (('libra', 'libras'), ('piastra', 'piastras')),
|
||||
'ERN': (('nakfa', 'nakfas'), ('céntimo', 'céntimos')),
|
||||
'ETB': (('birr', 'birrs'), ('céntimo', 'céntimos')),
|
||||
'FJD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'FKP': (('libra', 'libras'), ('penny', 'peniques')),
|
||||
'GEL': (('lari', 'laris'), ('tetri', 'tetris')),
|
||||
'GHS': (('cedi', 'cedis'), ('pesewa', 'pesewas')),
|
||||
'GIP': (('libra', 'libras'), ('penique', 'peniques')),
|
||||
'GMD': (('dalasi', 'dalasis'), ('butut', 'bututs')),
|
||||
'GNF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'GTQ': (('quetzal', 'quetzales'), GENERIC_CENTS),
|
||||
'GYD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'HKD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'HNL': (('lempira', 'lempiras'), GENERIC_CENTS),
|
||||
'HRK': (('kuna', 'kunas'), ('lipa', 'lipas')),
|
||||
'HTG': (('gourde', 'gourdes'), ('céntimo', 'céntimos')),
|
||||
'IDR': (('rupia', 'rupias'), ('céntimo', 'céntimos')),
|
||||
'ILS': (('séquel', 'séqueles'), ('agora', 'agoras')),
|
||||
'IQD': (('dinar', 'dinares'), ('fils', 'fils')),
|
||||
'IRR': (('rial', 'riales'), ('dinar', 'dinares')),
|
||||
'ISK': (('corona', 'coronas'), ('eyrir', 'aurar')),
|
||||
'ITL': (('lira', 'liras'), ('céntimo', 'céntimos')),
|
||||
'JMD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'JOD': (('dinar', 'dinares'), ('piastra', 'piastras')),
|
||||
'KES': (('chelín', 'chelines'), ('céntimo', 'céntimos')),
|
||||
'KGS': (('som', 'som'), ('tyiyn', 'tyiyn')),
|
||||
'KHR': (('riel', 'rieles'), ('céntimo', 'céntimos')),
|
||||
'KMF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'KWD': (('dinar', 'dinares'), ('fils', 'fils')),
|
||||
'KYD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'LAK': (('kip', 'kips'), ('att', 'att')),
|
||||
'LBP': (('libra', 'libras'), ('piastra', 'piastras')),
|
||||
'LKR': (('rupia', 'rupias'), ('céntimo', 'céntimos')),
|
||||
'LRD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'LSL': (('loti', 'lotis'), ('céntimo', 'céntimos')),
|
||||
'LTL': (('lita', 'litas'), ('céntimo', 'céntimos')),
|
||||
'LVL': (('lat', 'lats'), ('céntimo', 'céntimos')),
|
||||
'LYD': (('dinar', 'dinares'), ('dírham', 'dírhams')),
|
||||
'MAD': (('dírham', 'dirhams'), ('céntimo', 'céntimos')),
|
||||
'MDL': (('leu', 'lei'), ('ban', 'bani')),
|
||||
'MGA': (('ariary', 'ariaris'), ('iraimbilanja', 'iraimbilanja')),
|
||||
'MKD': (('denar', 'denares'), ('deni', 'denis')),
|
||||
'MMK': (('kiat', 'kiats'), ('pya', 'pyas')),
|
||||
'MNT': (('tugrik', 'tugriks'), ('möngö', 'möngö')),
|
||||
'MOP': (('pataca', 'patacas'), ('avo', 'avos')),
|
||||
'MRO': (('ouguiya', 'ouguiyas'), ('khoums', 'khoums')),
|
||||
'MRU': (('ouguiya', 'ouguiyas'), ('khoums', 'khoums')),
|
||||
'MUR': (('rupia', 'rupias'), ('céntimo', 'céntimos')),
|
||||
'MVR': (('rufiyaa', 'rufiyaas'), ('laari', 'laari')),
|
||||
'MWK': (('kuacha', 'kuachas'), ('tambala', 'tambalas')),
|
||||
'MYR': (('ringgit', 'ringgit'), ('céntimo', 'céntimos')),
|
||||
'MZN': (('metical', 'metical'), GENERIC_CENTS),
|
||||
'NAD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'NGN': (('naira', 'nairas'), ('kobo', 'kobo')),
|
||||
'NPR': (('rupia', 'rupias'), ('paisa', 'paisas')),
|
||||
'NZD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||
'OMR': (('rial', 'riales'), ('baisa', 'baisa')),
|
||||
'PAB': (('balboa', 'balboas'), ('centésimo', 'centésimos')),
|
||||
'PGK': (('kina', 'kinas'), ('toea', 'toea')),
|
||||
'PHP': (('peso', 'pesos'), GENERIC_CENTS),
|
||||
'PKR': (('rupia', 'rupias'), ('paisa', 'paisas')),
|
||||
'PLZ': (('zloty', 'zlotys'), ('grosz', 'groszy')),
|
||||
'PYG': (('guaraní', 'guaranís'), ('céntimo', 'céntimos')),
|
||||
'QAR': (('rial', 'riales'), ('dírham', 'dírhams')),
|
||||
'QTQ': (('quetzal', 'quetzales'), GENERIC_CENTS),
|
||||
'RSD': (('dinar', 'dinares'), ('para', 'para')),
|
||||
'RUR': (('rublo', 'rublos'), ('kopek', 'kopeks')),
|
||||
'RWF': (('franco', 'francos'), ('céntimo', 'céntimos')),
|
||||
'SAR': (('riyal', 'riales'), ('halala', 'halalas')),
|
||||
'SBD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'SCR': (('rupia', 'rupias'), ('céntimo', 'céntimos')),
|
||||
'SDG': (('libra', 'libras'), ('piastra', 'piastras')),
|
||||
'SGD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'SHP': (('libra', 'libras'), ('penny', 'peniques')),
|
||||
'SKK': (('corona', 'coronas'), ('halier', 'haliers')),
|
||||
'SLL': (('leona', 'leonas'), ('céntimo', 'céntimos')),
|
||||
'SRD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'SSP': (('libra', 'libras'), ('piastra', 'piastras')),
|
||||
'STD': (('dobra', 'dobras'), ('céntimo', 'céntimos')),
|
||||
'SVC': (('colón', 'colones'), GENERIC_CENTS),
|
||||
'SYP': (('libra', 'libras'), ('piastra', 'piastras')),
|
||||
'SZL': (('lilangeni', 'emalangeni'), ('céntimo', 'céntimos')),
|
||||
'TJS': (('somoni', 'somonis'), ('dirame', 'dirames')),
|
||||
'TMT': (('manat', 'manat'), ('tenge', 'tenge')),
|
||||
'TND': (('dinar', 'dinares'), ('milésimo', 'milésimos')),
|
||||
'TOP': (('paanga', 'paangas'), ('céntimo', 'céntimos')),
|
||||
'TTD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'TWD': (('nuevo dólar', 'nuevos dolares'), ('céntimo', 'céntimos')),
|
||||
'TZS': (('chelín', 'chelines'), ('céntimo', 'céntimos')),
|
||||
'UAG': (('hryvnia', 'hryvnias'), ('kopiyka', 'kopiykas')),
|
||||
'UGX': (('chelín', 'chelines'), ('céntimo', 'céntimos')),
|
||||
'UYU': (('peso', 'pesos'), ('centésimo', 'centésimos')),
|
||||
'UZS': (('sum', 'sum'), ('tiyin', 'tiyin')),
|
||||
'VEF': (('bolívar fuerte', 'bolívares fuertes'),
|
||||
('céntimo', 'céntimos')),
|
||||
'VND': (('dong', 'dongs'), ('xu', 'xu')),
|
||||
'VUV': (('vatu', 'vatu'), ('nenhum', 'nenhum')),
|
||||
'WST': (('tala', 'tala'), GENERIC_CENTS),
|
||||
'XAF': (('franco CFA', 'francos CFA'), ('céntimo', 'céntimos')),
|
||||
'XCD': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'XOF': (('franco CFA', 'francos CFA'), ('céntimo', 'céntimos')),
|
||||
'XPF': (('franco CFP', 'francos CFP'), ('céntimo', 'céntimos')),
|
||||
'YER': (('rial', 'riales'), ('fils', 'fils')),
|
||||
'YUM': (('dinar', 'dinares'), ('para', 'para')),
|
||||
'ZMW': (('kwacha', 'kwachas'), ('ngwee', 'ngwee')),
|
||||
'ZRZ': (('zaire', 'zaires'), ('likuta', 'makuta')),
|
||||
'ZWL': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
'ZWL': (GENERIC_DOLLARS, ('céntimo', 'céntimos')),
|
||||
}
|
||||
|
||||
# //CHECK: Is this sufficient??
|
||||
@@ -176,4 +353,14 @@ class Num2Word_ES(Num2Word_EU):
|
||||
val, currency=currency, cents=cents, separator=separator,
|
||||
adjective=adjective)
|
||||
# Handle exception, in spanish is "un euro" and not "uno euro"
|
||||
return result.replace("uno", "un")
|
||||
# except in this currencies: leona, corona,
|
||||
# libra, rupia, lempira, peseta, is 'una'
|
||||
# but only when it's first word, otherwise
|
||||
# it's replaced in others words like 'veintiun'
|
||||
if currency in CURRENCIES_UNA:
|
||||
list_result = result.split(" ")
|
||||
if list_result[0] == "uno":
|
||||
list_result[0] = list_result[0].replace("uno", "una")
|
||||
result = " ".join(list_result)
|
||||
result = result.replace("uno", "un")
|
||||
return result
|
||||
|
||||
117
num2words/lang_SV.py
Normal file
117
num2words/lang_SV.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# -*- 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, print_function, unicode_literals
|
||||
|
||||
from . import lang_EU
|
||||
|
||||
|
||||
class Num2Word_SV(lang_EU.Num2Word_EU):
|
||||
GIGA_SUFFIX = "iljarder"
|
||||
MEGA_SUFFIX = "iljoner"
|
||||
|
||||
def set_high_numwords(self, high):
|
||||
cap = 3 + 6 * len(high)
|
||||
|
||||
for word, n in zip(high, range(cap, 3, -6)):
|
||||
if self.GIGA_SUFFIX:
|
||||
self.cards[10 ** n] = word + self.GIGA_SUFFIX
|
||||
|
||||
if self.MEGA_SUFFIX:
|
||||
self.cards[10 ** (n - 3)] = word + self.MEGA_SUFFIX
|
||||
|
||||
def setup(self):
|
||||
super(Num2Word_SV, self).setup()
|
||||
|
||||
self.negword = "minus "
|
||||
self.pointword = "komma"
|
||||
self.exclude_title = ["och", "komma", "minus"]
|
||||
|
||||
self.mid_numwords = [(1000, "tusen"), (100, "hundra"),
|
||||
(90, "nittio"), (80, "åttio"), (70, "sjuttio"),
|
||||
(60, "sextio"), (50, "femtio"), (40, "förtio"),
|
||||
(30, "trettio")]
|
||||
self.low_numwords = ["tjugo", "nitton", "arton", "sjutton",
|
||||
"sexton", "femton", "fjorton", "tretton",
|
||||
"tolv", "elva", "tio", "nio", "åtta",
|
||||
"sju", "sex", "fem", "fyra", "tre", "två",
|
||||
"ett", "noll"]
|
||||
self.ords = {"noll": "nollte",
|
||||
"ett": "första",
|
||||
"två": "andra",
|
||||
"tre": "tredje",
|
||||
"fyra": "fjärde",
|
||||
"fem": "femte",
|
||||
"sex": "sjätte",
|
||||
"sju": "sjunde",
|
||||
"åtta": "åttonde",
|
||||
"nio": "nionde",
|
||||
"tio": "tionde",
|
||||
"elva": "elfte",
|
||||
"tolv": "tolfte",
|
||||
"tjugo": "tjugonde"}
|
||||
|
||||
def merge(self, lpair, rpair):
|
||||
ltext, lnum = lpair
|
||||
rtext, rnum = rpair
|
||||
if lnum == 1 and rnum < 100:
|
||||
return (rtext, rnum)
|
||||
elif 100 > lnum > rnum:
|
||||
return ("%s%s" % (ltext, rtext), lnum + rnum)
|
||||
elif lnum >= 100 > rnum:
|
||||
return ("%s%s" % (ltext, rtext), lnum + rnum)
|
||||
elif rnum >= 1000000 and lnum == 1:
|
||||
return ("%s %s" % ('en', rtext[:-2]), lnum + rnum)
|
||||
elif rnum >= 1000000 and lnum > 1:
|
||||
return ("%s %s" % (ltext, rtext), lnum + rnum)
|
||||
elif rnum > lnum:
|
||||
return ("%s%s" % (ltext, rtext), lnum * rnum)
|
||||
return ("%s %s" % (ltext, rtext), lnum + rnum)
|
||||
|
||||
def to_ordinal(self, value):
|
||||
self.verify_ordinal(value)
|
||||
outwords = self.to_cardinal(value).split(" ")
|
||||
lastword = outwords[-1]
|
||||
ending_length = 0
|
||||
try:
|
||||
lastword_ending = self.ords[lastword[-4:]]
|
||||
ending_length = 4
|
||||
except KeyError:
|
||||
try:
|
||||
lastword_ending = self.ords[lastword[-3:]]
|
||||
ending_length = 3
|
||||
except KeyError:
|
||||
lastword_ending = "de"
|
||||
if lastword_ending == 'de':
|
||||
lastword_first_part = self.title(lastword)[:]
|
||||
else:
|
||||
lastword_first_part = self.title(lastword)[:-ending_length]
|
||||
lastword_correct = lastword_first_part + lastword_ending
|
||||
outwords[-1] = lastword_correct
|
||||
return " ".join(outwords)
|
||||
|
||||
def to_ordinal_num(self, value):
|
||||
raise NotImplementedError(
|
||||
"'ordinal_num' is not implemented for swedish language")
|
||||
|
||||
def to_year(self, val, longval=True):
|
||||
raise NotImplementedError(
|
||||
"'year' is not implemented for swedish language")
|
||||
|
||||
def to_currency(self, val, longval=True):
|
||||
raise NotImplementedError(
|
||||
"'currency' is not implemented for swedish language")
|
||||
2826
tests/test_es.py
2826
tests/test_es.py
File diff suppressed because it is too large
Load Diff
70
tests/test_sv.py
Normal file
70
tests/test_sv.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# 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 unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words import num2words
|
||||
|
||||
|
||||
class Num2WordsSVTest(TestCase):
|
||||
def test_ordinal(self):
|
||||
self.assertEqual(num2words(14, to="ordinal", lang="sv"), "fjortonde")
|
||||
self.assertEqual(num2words(1435, to="ordinal", lang="sv"),
|
||||
"etttusen fyrahundratrettiofemte")
|
||||
self.assertEqual(num2words(32, to="ordinal", lang="sv"),
|
||||
"trettioandra")
|
||||
self.assertEqual(num2words(1, to="ordinal", lang="sv"), "första")
|
||||
self.assertEqual(num2words(5, to="ordinal", lang="sv"), "femte")
|
||||
self.assertEqual(num2words(10, to="ordinal", lang="sv"), "tionde")
|
||||
|
||||
def test_cardinal(self):
|
||||
self.assertEqual(num2words(0, to="cardinal", lang="sv"), "noll")
|
||||
self.assertEqual(num2words(1, to="cardinal", lang="sv"), "ett")
|
||||
self.assertEqual(num2words(3, to="cardinal", lang="sv"), "tre")
|
||||
self.assertEqual(num2words(5, to="cardinal", lang="sv"), "fem")
|
||||
self.assertEqual(num2words(18, to="cardinal", lang="sv"), "arton")
|
||||
self.assertEqual(num2words(45, to="cardinal", lang="sv"), "förtiofem")
|
||||
self.assertEqual(num2words(1345, to="cardinal", lang="sv"),
|
||||
"etttusen trehundraförtiofem")
|
||||
self.assertEqual(num2words(4435, to="cardinal", lang="sv"),
|
||||
"fyratusen fyrahundratrettiofem")
|
||||
self.assertEqual(num2words(1004135, to="cardinal", lang="sv"),
|
||||
"en miljon fyratusen etthundratrettiofem")
|
||||
self.assertEqual(num2words(4335000, to="cardinal", lang="sv"),
|
||||
"fyra miljoner trehundratrettiofemtusen")
|
||||
self.assertEqual(num2words(14004535, to="cardinal", lang="sv"),
|
||||
"fjorton miljoner fyratusen femhundratrettiofem")
|
||||
self.assertEqual(num2words(1.5, to="cardinal", lang="sv"),
|
||||
"ett komma fem")
|
||||
|
||||
def test_not_implemented_options(self):
|
||||
with self.assertRaises(NotImplementedError) as context:
|
||||
num2words(1235, to="year", lang="sv")
|
||||
self.assertTrue("'year' is not implemented for swedish language"
|
||||
in str(context.exception))
|
||||
|
||||
with self.assertRaises(NotImplementedError) as context:
|
||||
num2words(1235, to="currency", lang="sv")
|
||||
self.assertTrue("'currency' is not implemented for swedish language"
|
||||
in str(context.exception))
|
||||
|
||||
with self.assertRaises(NotImplementedError) as context:
|
||||
num2words(1235, to="ordinal_num", lang="sv")
|
||||
self.assertTrue("'ordinal_num' is not implemented for swedish language"
|
||||
in str(context.exception))
|
||||
Reference in New Issue
Block a user