Search code examples
pythonpython-3.xwikipediawikipedia-apipyttsx3

How to change language output with wikipedia package in python?


If i ask about iphone, the output is: "The iPhone is a line of smartphones designed and marketed by Apple Inc. that use Apple's iOS mobile operating system." But i want to change it into german.

elif 'wikipedia' in query:
            speak('Suche auf wikipedia...')
            query = query.replace("wikipedia", "")
            result = wikipedia.summary(query, sentences = 2)
            print(result)
            speak(result)

Solution

  • After importing wikipedia you can set the language as follows:

    wikipedia.set_lang('de')
    

    Example:

    import wikipedia
    
    wikipedia.set_lang('de')
    
    result = wikipedia.summary('Stack Overflow', sentences = 1)
    
    print(result)
    

    And the output will be:

    Pufferüberläufe (englisch buffer overflow) oder – im Besonderen – auch Stapelüberläufe (englisch ‚stack overflows‘) genannt, gehören zu den häufigsten Sicherheitslücken in aktueller Software, die sich u.