-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from LauraMBraun/main
Added Deutsch
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from dataclasses import dataclass | ||
from saa.core.language import Luga | ||
|
||
@dataclass(init=False, eq=False, repr=False, frozen=False) | ||
class Deutsch(Luga): | ||
time = { | ||
"to": "{minute} {time_indicator} vor {hour} Uhr", | ||
"past": "{minute} {time_indicator} nach {hour} Uhr", | ||
0: "{hour} Uhr", | ||
15: "Viertel nach {hour}", | ||
45: "Viertel vor {hour}", | ||
30: "Halb {hour}", | ||
} | ||
number_connector = "und" | ||
connect_format = "{0}{1}{2}" | ||
numbers = { | ||
0: "null", | ||
1: "ein", # ein und zwanzig / eine Minute / ein Uhr | ||
2: "zwei", | ||
3: "drei", | ||
4: "vier", | ||
5: "fünf", | ||
6: "sechs", | ||
7: "sieben", | ||
8: "acht", | ||
9: "neun", | ||
10: "zehn", | ||
11: "elf", | ||
12: "zwölf", | ||
13: "dreizehn", | ||
14: "vierzehn", | ||
15: "fünfzehn", | ||
16: "sechzehn", | ||
17: "siebzehn", | ||
18: "achtzehn", | ||
19: "neunzehn", | ||
20: "zwanzig", | ||
30: "dreißig", | ||
40: "vierzig", | ||
50: "fünfzig", | ||
} | ||
|
||
@staticmethod | ||
def time_logic(hour, minute) -> tuple[int, int, str, str]: | ||
if minute in [0, 15, 30, 45]: | ||
if minute == 45 or minute == 30: | ||
hour += 1 | ||
return (hour, minute, '', '') | ||
|
||
is_to = "to" if minute > 30 else "past" | ||
time_indicator = "Minuten" if minute not in [1,59] else "Minute" | ||
|
||
if is_to == "to": | ||
hour += 1 | ||
minute = 60 - minute | ||
|
||
if minute <= 20 or minute == 30 or minute == 40 or minute == 50: | ||
if minute == 1: | ||
minute = Deutsch.numbers[minute][1] if is_to == 'to' else Deutsch.numbers[minute][0] | ||
else: | ||
minute = Deutsch.numbers[minute] | ||
else: | ||
tens = minute // 10 * 10 | ||
ones = minute % 10 | ||
minute = Deutsch.connect_format.format(Deutsch.numbers[ones], Deutsch.number_connector, Deutsch.numbers[tens]) | ||
|
||
hour = Deutsch.numbers[hour] | ||
|
||
return hour, minute, is_to, time_indicator | ||
|
||
|
||
@staticmethod | ||
def post_logic(hour, minute, is_to, time_indicator) -> str: | ||
if is_to: | ||
return Deutsch.time[is_to].format(minute=minute, time_indicator=time_indicator, hour=hour) | ||
else: | ||
return Deutsch.time[minute].format(hour=hour) | ||
|
||
class Language(Deutsch): | ||
pass | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from datetime import time | ||
import pytest | ||
from saa.core.watch import Watch | ||
from saa.core.plugins import supported_languages | ||
|
||
German = supported_languages.get("de") | ||
|
||
test_cases = [ | ||
(time(hour=13, minute=45), German, "viertel vor zwei"), | ||
(time(hour=13, minute=15), German, "viertel nach eins"), | ||
(time(hour=13, minute=30), German, "halb zwei"), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("test_input, language, test_output", test_cases) | ||
def test_clocks(test_input, language, test_output): | ||
clock = Watch(language=language) | ||
assert test_output == clock(test_input) | ||
|
||
|
||
test_plural_cases = [ | ||
(time(hour=13, minute=1), German, "eine Minute nach eins"), | ||
(time(hour=6, minute=17), German, "siebzehn Minuten nach sechs"), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("test_input, language, test_output", test_plural_cases) | ||
def test_cases(test_input, language, test_output): | ||
clock = Watch(language=language) | ||
assert test_output == clock(test_input) |