Repository: joke2k/faker

Issue:
wrong language in faker.word() method


### Steps to reproduce

1. from faker import Faker 
1. fake = Faker('de_DE')
1. fake.word()

### Expected behavior

Generated word should be in German language

### Actual behavior

Generated word is in Latin. The same situation is with Spanish word() method.



Discussion:
The issue is that the there is no German (or Spanish) localization for the `word` method.

We usually fall back to `en_US` when a localization is missing (https://github.com/joke2k/faker#localization).

The `lorem` provider is a special case in that it falls back to "latin-ish". This is because the original point of the provider was to provide a 'lorem ipsum' kind of text, which one would expect to be in "latin-ish".

I see how this could be confusing from the user perspective. It should at very last fall back to `en_US` as stated in the docs. But switching the fallback locale for `lorem` would be a breaking change.

Resolving patch:
diff --git a/faker/providers/lorem/de_AT/__init__.py b/faker/providers/lorem/de_AT/__init__.py
new file mode 100644
--- /dev/null
+++ b/faker/providers/lorem/de_AT/__init__.py
@@ -0,0 +1,9 @@
+from ..de_DE import Provider as GermanProvider
+
+
+class Provider(GermanProvider):
+    """Implement lorem provider for ``de_DE`` locale.
+    Using the same as in ```de_DE```.
+    """
+
+    pass
diff --git a/faker/providers/lorem/de_DE/__init__.py b/faker/providers/lorem/de_DE/__init__.py
new file mode 100644
--- /dev/null
+++ b/faker/providers/lorem/de_DE/__init__.py
@@ -0,0 +1,523 @@
+from .. import Provider as LoremProvider
+
+
+class Provider(LoremProvider):
+    """Implement lorem provider for ``de_DE`` locale.
+
+    Word list is based on the source below, and some words have been removed
+    because of some duplications.
+
+    Sources:
+
+    - https://www.gut1.de/grundwortschatz/grundwortschatz-500/
+    """
+
+    word_list = (
+        "ab",
+        "Abend",
+        "aber",
+        "acht",
+        "Affe",
+        "alle",
+        "allein",
+        "als",
+        "also",
+        "alt",
+        "am",
+        "an",
+        "andere",
+        "anfangen",
+        "Angst",
+        "antworten",
+        "Apfel",
+        "Arbeit",
+        "arbeiten",
+        "Arzt",
+        "auch",
+        "auf",
+        "Auge",
+        "aus",
+        "Auto",
+        "baden",
+        "bald",
+        "Ball",
+        "bauen",
+        "Bauer",
+        "Baum",
+        "bei",
+        "beide",
+        "beim",
+        "Bein",
+        "Beispiel",
+        "beißen",
+        "bekommen",
+        "Berg",
+        "besser",
+        "Bett",
+        "Bild",
+        "bin",
+        "bis",
+        "blau",
+        "bleiben",
+        "Blume",
+        "Boden",
+        "brauchen",
+        "braun",
+        "Brief",
+        "bringen",
+        "Brot",
+        "Bruder",
+        "Buch",
+        "böse",
+        "da",
+        "dabei",
+        "dafür",
+        "damit",
+        "danach",
+        "dann",
+        "daran",
+        "darauf",
+        "darin",
+        "das",
+        "dauern",
+        "davon",
+        "dazu",
+        "dein",
+        "dem",
+        "den",
+        "denken",
+        "denn",
+        "der",
+        "deshalb",
+        "dich",
+        "dick",
+        "die",
+        "Ding",
+        "dir",
+        "doch",
+        "Dorf",
+        "dort",
+        "draußen",
+        "drehen",
+        "drei",
+        "dumm",
+        "dunkel",
+        "durch",
+        "dürfen",
+        "eigentlich",
+        "ein",
+        "einfach",
+        "einige",
+        "einigen",
+        "einmal",
+        "Eis",
+        "Eltern",
+        "Ende",
+        "endlich",
+        "er",
+        "Erde",
+        "erklären",
+        "erschrecken",
+        "erst",
+        "erzählen",
+        "es",
+        "essen",
+        "Essen",
+        "etwas",
+        "fahren",
+        "Fahrrad",
+        "fallen",
+        "Familie",
+        "fangen",
+        "fast",
+        "fehlen",
+        "Fenster",
+        "Ferien",
+        "fertig",
+        "fest",
+        "Feuer",
+        "fiel",
+        "finden",
+        "Finger",
+        "Fisch",
+        "Flasche",
+        "fliegen",
+        "Frage",
+        "fragen",
+        "Frau",
+        "frei",
+        "fressen",
+        "Freude",
+        "freuen",
+        "Freund",
+        "fröhlich",
+        "früh",
+        "früher",
+        "Fuß",
+        "Fußball",
+        "fährt",
+        "führen",
+        "fünf",
+        "für",
+        "gab",
+        "ganz",
+        "gar",
+        "Garten",
+        "geben",
+        "Geburtstag",
+        "gefährlich",
+        "gegen",
+        "gehen",
+        "gehören",
+        "gelb",
+        "Geld",
+        "genau",
+        "gerade",
+        "gern",
+        "Geschenk",
+        "Geschichte",
+        "Gesicht",
+        "gestern",
+        "gesund",
+        "gewinnen",
+        "gibt",
+        "ging",
+        "Glas",
+        "glauben",
+        "gleich",
+        "Glück",
+        "glücklich",
+        "Gott",
+        "groß",
+        "grün",
+        "gut",
+        "Haare",
+        "haben",
+        "halbe",
+        "halten",
+        "Hand",
+        "hart",
+        "Hase",
+        "hat",
+        "Haus",
+        "heiß",
+        "heißen",
+        "helfen",
+        "her",
+        "heraus",
+        "Herr",
+        "Herz",
+        "heute",
+        "hier",
+        "Hilfe",
+        "Himmel",
+        "hin",
+        "hinein",
+        "hinter",
+        "hoch",
+        "holen",
+        "Hund",
+        "Hunger",
+        "hängen",
+        "hören",
+        "ich",
+        "ihm",
+        "ihn",
+        "ihr",
+        "im",
+        "immer",
+        "in",
+        "ins",
+        "ist",
+        "ja",
+        "Jahr",
+        "jeder",
+        "jetzt",
+        "jung",
+        "Junge",
+        "kalt",
+        "kam",
+        "kann",
+        "Katze",
+        "kaufen",
+        "kein",
+        "kennen",
+        "Kind",
+        "Klasse",
+        "klein",
+        "klettern",
+        "kochen",
+        "kommen",
+        "Kopf",
+        "krank",
+        "kurz",
+        "können",
+        "Küche",
+        "lachen",
+        "Land",
+        "lange",
+        "langsam",
+        "las",
+        "lassen",
+        "laufen",
+        "laut",
+        "leben",
+        "Leben",
+        "legen",
+        "Lehrer",
+        "Lehrerin",
+        "leicht",
+        "leise",
+        "lernen",
+        "lesen",
+        "letzte",
+        "Leute",
+        "Licht",
+        "lieb",
+        "liegen",
+        "ließ",
+        "Loch",
+        "los",
+        "Luft",
+        "lustig",
+        "machen",
+        "mal",
+        "Mama",
+        "man",
+        "Mann",
+        "Maus",
+        "Meer",
+        "mehr",
+        "mein",
+        "Mensch",
+        "merken",
+        "mich",
+        "Milch",
+        "Minute",
+        "Minutenmir",
+        "mit",
+        "Monat",
+        "Monate",
+        "Musik",
+        "Mutter",
+        "Mädchen",
+        "mögen",
+        "möglich",
+        "müde",
+        "müssen",
+        "nach",
+        "Nacht",
+        "nah",
+        "Name",
+        "Nase",
+        "nass",
+        "natürlich",
+        "neben",
+        "nehmen",
+        "nein",
+        "nennen",
+        "neu",
+        "neun",
+        "nicht",
+        "nichts",
+        "nie",
+        "nimmt",
+        "noch",
+        "nun",
+        "nur",
+        "nächste",
+        "nämlich",
+        "ob",
+        "oben",
+        "oder",
+        "offen",
+        "oft",
+        "ohne",
+        "Oma",
+        "Onkel",
+        "Opa",
+        "packen",
+        "Papa",
+        "Pferd",
+        "Platz",
+        "plötzlich",
+        "Polizei",
+        "Rad",
+        "rechnen",
+        "reich",
+        "reiten",
+        "rennen",
+        "richtig",
+        "rot",
+        "rufen",
+        "ruhig",
+        "rund",
+        "Sache",
+        "sagen",
+        "schaffen",
+        "schauen",
+        "scheinen",
+        "schenken",
+        "schicken",
+        "Schiff",
+        "schlafen",
+        "schlagen",
+        "schlecht",
+        "schlimm",
+        "Schluss",
+        "Schnee",
+        "schnell",
+        "schon",
+        "schreiben",
+        "schreien",
+        "Schuh",
+        "Schule",
+        "schwarz",
+        "schwer",
+        "Schwester",
+        "schwimmen",
+        "schön",
+        "Schüler",
+        "sechs",
+        "See",
+        "sehen",
+        "sehr",
+        "sein",
+        "seit",
+        "Seite",
+        "selbst",
+        "setzen",
+        "sich",
+        "sicher",
+        "sie",
+        "sieben",
+        "sieht",
+        "sind",
+        "singen",
+        "sitzen",
+        "so",
+        "sofort",
+        "Sohn",
+        "sollen",
+        "Sommer",
+        "Sonne",
+        "Sonntag",
+        "sonst",
+        "Spaß",
+        "Spiel",
+        "spielen",
+        "sprechen",
+        "springen",
+        "spät",
+        "später",
+        "Stadt",
+        "stark",
+        "stehen",
+        "steigen",
+        "Stein",
+        "Stelle",
+        "stellen",
+        "Straße",
+        "Stunde",
+        "Stück",
+        "suchen",
+        "Tag",
+        "Tante",
+        "Teller",
+        "tief",
+        "Tier",
+        "Tisch",
+        "tot",
+        "tragen",
+        "traurig",
+        "treffen",
+        "trinken",
+        "tun",
+        "turnen",
+        "Tür",
+        "Uhr",
+        "um",
+        "und",
+        "uns",
+        "unser",
+        "unten",
+        "unter",
+        "Vater",
+        "vergessen",
+        "verkaufen",
+        "verlieren",
+        "verstecken",
+        "verstehen",
+        "versuchen",
+        "viel",
+        "vielleicht",
+        "vier",
+        "Vogel",
+        "voll",
+        "vom",
+        "von",
+        "vor",
+        "vorbei",
+        "Wagen",
+        "wahr",
+        "Wald",
+        "war",
+        "warm",
+        "warten",
+        "warum",
+        "was",
+        "waschen",
+        "Wasser",
+        "weg",
+        "Weg",
+        "Weihnachten",
+        "weil",
+        "weinen",
+        "weit",
+        "weiter",
+        "weiß",
+        "Welt",
+        "wenig",
+        "wenn",
+        "wer",
+        "werden",
+        "werfen",
+        "Wetter",
+        "wichtig",
+        "wie",
+        "wieder",
+        "Wiese",
+        "will",
+        "Winter",
+        "wir",
+        "wird",
+        "wirklich",
+        "wissen",
+        "Wissen",
+        "wo",
+        "Woche",
+        "wohl",
+        "wohnen",
+        "Wohnung",
+        "wollen",
+        "Wort",
+        "wünschen",
+        "Zahl",
+        "zehn",
+        "zeigen",
+        "Zeit",
+        "Zeitung",
+        "ziehen",
+        "Zimmer",
+        "zu",
+        "Zug",
+        "zum",
+        "zur",
+        "zurück",
+        "zusammen",
+        "zwei",
+        "zwischen",
+        "öffnen",
+        "über",
+        "überall",
+    )


Test patch:
diff --git a/tests/providers/test_lorem.py b/tests/providers/test_lorem.py
--- a/tests/providers/test_lorem.py
+++ b/tests/providers/test_lorem.py
@@ -4,6 +4,8 @@
 
 from faker.providers.lorem.az_AZ import Provider as AzAzLoremProvider
 from faker.providers.lorem.cs_CZ import Provider as CsCzLoremProvider
+from faker.providers.lorem.de_AT import Provider as DeAtLoremProvider
+from faker.providers.lorem.de_DE import Provider as DeDeLoremProvider
 
 
 class TestLoremProvider:
@@ -313,3 +315,141 @@ def test_words(self, faker, num_samples):
         for _ in range(num_samples):
             words = faker.words(num_words)
             assert all(isinstance(word, str) and word in AzAzLoremProvider.word_list for word in words)
+
+
+class TestDeDe:
+    """Test ```de_DE``` lorem provider"""
+
+    word_list = [word.lower() for word in DeDeLoremProvider.word_list]
+
+    def test_paragraph(self, faker, num_samples):
+        num_sentences = 10
+        for _ in range(num_samples):
+            paragraph = faker.paragraph(nb_sentences=num_sentences)
+            assert isinstance(paragraph, str)
+            words = paragraph.replace(".", "").split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_paragraphs(self, faker, num_samples):
+        num_paragraphs = 5
+        for _ in range(num_samples):
+            paragraphs = faker.paragraphs(nb=num_paragraphs)
+            for paragraph in paragraphs:
+                assert isinstance(paragraph, str)
+                words = paragraph.replace(".", "").split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_sentence(self, faker, num_samples):
+        num_words = 10
+        for _ in range(num_samples):
+            sentence = faker.sentence(nb_words=num_words)
+            assert isinstance(sentence, str)
+            words = sentence.replace(".", "").split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_sentences(self, faker, num_samples):
+        num_sentences = 5
+        for _ in range(num_samples):
+            sentences = faker.sentences(nb=num_sentences)
+            for sentence in sentences:
+                assert isinstance(sentence, str)
+                words = sentence.replace(".", "").split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_text(self, faker, num_samples):
+        num_chars = 25
+        for _ in range(num_samples):
+            text = faker.text(max_nb_chars=num_chars)
+            assert isinstance(text, str)
+            words = re.sub(r"[.\n]+", " ", text).split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_texts(self, faker, num_samples):
+        num_texts = 5
+        num_chars = 25
+        for _ in range(num_samples):
+            texts = faker.texts(max_nb_chars=num_chars, nb_texts=num_texts)
+            for text in texts:
+                assert isinstance(text, str)
+                words = re.sub(r"[.\n]+", " ", text).split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_word(self, faker, num_samples):
+        for _ in range(num_samples):
+            word = faker.word()
+            assert isinstance(word, str) and word in DeDeLoremProvider.word_list
+
+    def test_words(self, faker, num_samples):
+        num_words = 5
+        for _ in range(num_samples):
+            words = faker.words(num_words)
+            assert all(isinstance(word, str) and word in DeDeLoremProvider.word_list for word in words)
+
+
+class TestDeAt:
+    """Test ```de_AT``` lorem provider"""
+
+    word_list = [word.lower() for word in DeAtLoremProvider.word_list]
+
+    def test_paragraph(self, faker, num_samples):
+        num_sentences = 10
+        for _ in range(num_samples):
+            paragraph = faker.paragraph(nb_sentences=num_sentences)
+            assert isinstance(paragraph, str)
+            words = paragraph.replace(".", "").split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_paragraphs(self, faker, num_samples):
+        num_paragraphs = 5
+        for _ in range(num_samples):
+            paragraphs = faker.paragraphs(nb=num_paragraphs)
+            for paragraph in paragraphs:
+                assert isinstance(paragraph, str)
+                words = paragraph.replace(".", "").split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_sentence(self, faker, num_samples):
+        num_words = 10
+        for _ in range(num_samples):
+            sentence = faker.sentence(nb_words=num_words)
+            assert isinstance(sentence, str)
+            words = sentence.replace(".", "").split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_sentences(self, faker, num_samples):
+        num_sentences = 5
+        for _ in range(num_samples):
+            sentences = faker.sentences(nb=num_sentences)
+            for sentence in sentences:
+                assert isinstance(sentence, str)
+                words = sentence.replace(".", "").split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_text(self, faker, num_samples):
+        num_chars = 25
+        for _ in range(num_samples):
+            text = faker.text(max_nb_chars=num_chars)
+            assert isinstance(text, str)
+            words = re.sub(r"[.\n]+", " ", text).split()
+            assert all(word.lower() in self.word_list for word in words)
+
+    def test_texts(self, faker, num_samples):
+        num_texts = 5
+        num_chars = 25
+        for _ in range(num_samples):
+            texts = faker.texts(max_nb_chars=num_chars, nb_texts=num_texts)
+            for text in texts:
+                assert isinstance(text, str)
+                words = re.sub(r"[.\n]+", " ", text).split()
+                assert all(word.lower() in self.word_list for word in words)
+
+    def test_word(self, faker, num_samples):
+        for _ in range(num_samples):
+            word = faker.word()
+            assert isinstance(word, str) and word in DeAtLoremProvider.word_list
+
+    def test_words(self, faker, num_samples):
+        num_words = 5
+        for _ in range(num_samples):
+            words = faker.words(num_words)
+            assert all(isinstance(word, str) and word in DeAtLoremProvider.word_list for word in words)