Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lang tet ordinal #11

Merged
merged 6 commits into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 76 additions & 32 deletions num2words/lang_TET.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def setup(self):
},
{
0: "",
1: "daatusidak",
2: "daatusruak",
3: "daatustoluk",
4: "daatushaat",
5: "daatuslimak",
6: "daatusneen",
7: "daatushituk",
8: "daatusualuk",
9: "daatussiak",
1: "daatus idak",
2: "daatus ruak",
3: "daatus toluk",
4: "daatus haat",
5: "daatus limak",
6: "daatus neen",
7: "daatus hituk",
8: "daatus ualuk",
9: "daatus siak",
},
]
self.thousand_separators = {
Expand Down Expand Up @@ -160,32 +160,76 @@ def to_ordinal(self, value):
# Before changing this function remember this is used by pt-BR
# so act accordingly
self.verify_ordinal(value)
try:
assert int(value) == value
except (ValueError, TypeError, AssertionError):
return self.to_cardinal_float(value)

out = ""
if value < 0:
value = abs(value)
out = "%s " % self.negword.strip()

if value >= self.MAXVAL:
raise OverflowError(self.errmsg_toobig % (value, self.MAXVAL))

val = self.splitnum(value)
outs = val
while len(val) != 1:
outs = []
left, right = val[:2]
if isinstance(left, tuple) and isinstance(right, tuple):
outs.append(self.merge(left, right))
if val[2:]:
outs.append(val[2:])
else:
for elem in val:
if isinstance(elem, list):
if len(elem) == 1:
outs.append(elem[0])
else:
outs.append(self.clean(elem))
else:
outs.append(elem)
val = outs

words, num = outs[0]

if num in [90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 5, 3, 2]:
words = 'da'+words+'k'
if num in [6,4]:
words = 'da'+words
if num == 1:
words = 'dahuluk'
if num in [900, 800, 700, 500, 300, 200, 100]:
words = 'dah'+words+'k'
if num in [600, 400]:
words = 'dah'+words

words_split = words.split()
if len(words_split) >= 3 and num < 100:
first_word = 'da'+words_split[0]
second_word = " ".join(words_split[1:])
if 'haat' in second_word or 'neen' in second_word:
words = first_word+" "+second_word
else:
words = first_word+" "+second_word+'k'

result = []
value = str(value)
thousand_separator = ''

for idx, char in enumerate(value[::-1]):
if idx and idx % 3 == 0:
thousand_separator = self.thousand_separators[idx]

if char != '0' and thousand_separator:
# avoiding "segundo milionésimo milésimo" for 6000000,
# for instance
result.append(thousand_separator)
thousand_separator = ''

result.append(self.ords[idx % 3][int(char)])

result = ' '.join(result[::-1])
result = result.strip()
result = re.sub('\\s+', ' ', result)
word_first = 'dah'+words_split[0]
if word_first == 'dahatus' and len(words_split) >=3:
word_second = " ".join(words_split[2:])
if 'haat' in word_second or 'neen' in word_second:
words = word_first+" "+word_second
else:
words = word_first+" "+word_second+'k'

if result.startswith('primeiru') and value != '1':
# avoiding "primeiro milésimo", "primeiro milionésimo" and so on
result = result[9:]
if len(str(num)) > 3:
if 'haat' in words or 'neen' in words:
words = 'da'+words
else:
words = 'da'+words+'k'

return result
return self.title(out + words)

def to_ordinal_num(self, value):
# Before changing this function remember this is used by pt-BR
Expand Down