From 46a9e004bf02cdaf01799756777b25e9c2eb9aa5 Mon Sep 17 00:00:00 2001 From: Suhun Han Date: Fri, 13 Dec 2024 23:32:16 +0900 Subject: [PATCH] chore(docs): update for v4.0.0 --- README.rst | 64 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/README.rst b/README.rst index f953110..ac83fb1 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,6 @@ Googletrans |GitHub license| |travis status| |Documentation Status| |PyPI version| |Coverage Status| |Code Climate| -ANNOUNCEMENT: `v4.0 is planned `_. - Googletrans is a **free** and **unlimited** python library that implemented Google Translate API. This uses the `Google Translate Ajax API `__ to make calls to such methods as @@ -78,14 +76,21 @@ source language. .. code:: python + >>> import asyncio >>> from googletrans import Translator - >>> translator = Translator() - >>> translator.translate('안녕하세요.') - # - >>> translator.translate('안녕하세요.', dest='ja') - # - >>> translator.translate('veritas lux mea', src='la') - # + >>> + >>> async def translate_text(): + ... async with Translator() as translator: + ... result = await translator.translate('안녕하세요.') + ... print(result) # + ... + ... result = await translator.translate('안녕하세요.', dest='ja') + ... print(result) # + ... + ... result = await translator.translate('veritas lux mea', src='la') + ... print(result) # + ... + >>> asyncio.run(translate_text()) Customize service URL ~~~~~~~~~~~~~~~~~~~~~ @@ -125,12 +130,16 @@ for arrays as well. .. code:: python - >>> translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') - >>> for translation in translations: - ... print(translation.origin, ' -> ', translation.text) - # The quick brown fox -> 빠른 갈색 여우 - # jumps over -> 이상 점프 - # the lazy dog -> 게으른 개 + >>> async def translate_bulk(): + ... async with Translator() as translator: + ... translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko') + ... for translation in translations: + ... print(translation.origin, ' -> ', translation.text) + ... # The quick brown fox -> 빠른 갈색 여우 + ... # jumps over -> 이상 점프 + ... # the lazy dog -> 게으른 개 + ... + >>> asyncio.run(translate_bulk()) Language detection ~~~~~~~~~~~~~~~~~~ @@ -140,16 +149,21 @@ a given sentence. .. code:: python - >>> from googletrans import Translator - >>> translator = Translator() - >>> translator.detect('이 문장은 한글로 쓰여졌습니다.') - # - >>> translator.detect('この文章は日本語で書かれました。') - # - >>> translator.detect('This sentence is written in English.') - # - >>> translator.detect('Tiu frazo estas skribita en Esperanto.') - # + >>> async def detect_languages(): + ... async with Translator() as translator: + ... result = await translator.detect('이 문장은 한글로 쓰여졌습니다.') + ... print(result) # + ... + ... result = await translator.detect('この文章は日本語で書かれました。') + ... print(result) # + ... + ... result = await translator.detect('This sentence is written in English.') + ... print(result) # + ... + ... result = await translator.detect('Tiu frazo estas skribita en Esperanto.') + ... print(result) # + ... + >>> asyncio.run(detect_languages()) GoogleTrans as a command line application -----------------------------------------