kakaotrans

[Unofficial] Kakaotrans: Kakao translate API for python


Keywords
ajax-api, kakao, translation
License
MIT
Install
pip install kakaotrans==0.1.2

Documentation

Kakaotrans

Unofficial python API for Kakao translate service.

Installation

$ pip install kakaotrans

Usage

Basic Usage

>>> from kakaotrans import Translator
>>> translator = Translator()
>>> translator.translate("Try your best rather than be the best.")
# '์ตœ๊ณ ๊ฐ€ ๋˜๊ธฐ๋ณด๋‹ค๋Š” ์ตœ์„ ์„ ๋‹คํ•˜๋ผ.'
>>> translator.translate("์ตœ๊ณ ๊ฐ€ ๋˜๊ธฐ๋ณด๋‹ค๋Š” ์ตœ์„ ์„ ๋‹คํ•˜๋ผ.", src='kr', tgt='de')
# 'Tun Sie Ihr Bestes, anstatt das Beste zu sein.'

Separate the query into multiple sentences

Translation query might include multiple sentences. If you set separate_lines=True, translator will automatically separate the query and return the list of multiple sentences.

from kakaotrans import Translator

translator = Translator()

translator.translate("""์ง€๋‚œํ•ด 3์›” ์˜คํ”ˆํ•œ ์นด์นด์˜คํ†ก ์ฃผ๋ฌธํ•˜๊ธฐ๋Š” ํ˜„์žฌ๊นŒ์ง€ ์•ฝ 250๋งŒ๋ช…์˜ ํšŒ์›์„ ํ™•๋ณดํ–ˆ๋‹ค.
            ์ „ ๊ตญ๋ฏผ์—๊ฒŒ ์นœ์ˆ™ํ•œ ์นด์นด์˜คํ†ก UI๋ฅผ ํ™œ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋„์˜ ์•ฑ์„ ์„ค์น˜ํ•  ํ•„์š” ์—†์ด ์นด์นด์˜คํ†ก ๋‚ด์—์„œ ๋ชจ๋“  ๊ณผ์ •์ด ์ด๋ค„์ง€๋Š” ๊ฒƒ์ด ํŠน์ง•์ด๋‹ค.""",
            src='kr', tgt='en', separate_lines=True)
# ['The ordering of KakaoTalk, which opened in March last year, has secured about 2.5 million members to date.', 'Because it uses KakaoTalk UI, which is familiar to the whole nation, it is characterized by all the processes in KakaoTalk without having to install a separate app.']

Save translated result as file

>>> from kakaotrans import Translator
>>> translator = Translator()
>>> translator.translate("Try your best rather than be the best.", save_as_file=True, file_name='result.txt')

Reference