Comments (6)
Hi @mkinney, thanks for the question.
We don't have this information in the languages list. You could instead use the translator itself to translate the native language name:
Edited to add: warning, this approach to determine native names does not always yield correct results, see below.
for language in translator.get_source_languages():
# Handle source language codes that are not accepted as target languages
target_lang = "EN-US" if language.code == "EN" else ("PT-PT" if language.code == "PT" else language.code)
native_name = translator.translate_text(language.name, source_lang="EN", target_lang=target_lang)
print(f"{language.code} ({language.name}) - {native_name}") # Example: "ZH (Chinese) - **"
Edited to add: After reviewing this code above, it might not work correctly in some cases. DeepL translates best when the input text includes context; translating singular words may lead to mistakes. The example above for Chinese "**" has a closer meaning to "China" (the country). This approach might have similar problems for other languages due to the lack of context.
from deepl-python.
That's great!
Do you want a PR to update the README example with that updated code snippet?
from deepl-python.
I edited the message above after reviewing: the approach above is wrong in some cases e.g. Chinese. As the approach is flawed I would not add it to the README.
Coming back to your original question, it seems we don't have an easy way to get native language names. Some languages and/or UI frameworks (e.g. .NET) include a locale framework that defines native language names, but unfortunately after a cursory search I could not find something suitable in Python.
from deepl-python.
Ok. I would be content with the list of languages in native language somewhere.
For context, this is what I’m using as a language picker in a list.
from deepl-python.
Hi again, I do not have an update regarding our API, however this StackOverflow post might provide a good solution using the ICU Python package: https://stackoverflow.com/questions/10405915/how-to-get-the-language-name-in-native-language.
from deepl-python.
Hi @mkinney, the team discussed this topic: we won't add the native language names. Various platforms offer alternatives you can use to get the native names, for example ICU Python package above.
from deepl-python.
Related Issues (20)
- [Bug] DeepL Write adds sentences describing chosen style
- DeepL documentation states ZH is supported as target for translate_docs but on execution it errors HOT 2
- translate_document_from_filepath fails to recognise XML files HOT 1
- Error: Bad request, message: Document is empty HOT 4
- [Feature Request] Make auto-retry toggleable HOT 3
- can't use my auth key, and can't sign up to the API plan for free trial HOT 4
- preserve_formatting missing in translate_document() function HOT 5
- translator.create_glossary() forces to remove regional variant HOT 3
- Translation with glossary and target "EN-GB" looses some words HOT 2
- Encoding problem when translating to french. HOT 2
- New feature : customize timeout duration HOT 2
- Glossaries HOT 1
- deepl.Formality.MORE results in untranslated text HOT 1
- Mismatch in the placement of ignore tags and lack of translation HOT 1
- The deepl.Formality is ignored
- Abnormal strings in translation results: ãã£ã£ãç§ã¡ã¡åã HOT 5
- `translate_document()` should `seek(0, 0)` the output file after being done
- Disambiguate homonyms in glossaries / provide alternative translations? HOT 3
- When translating long English fields into Chinese, the last paragraph was lost
- Glossary flexible search
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepl-python.