Translate korean text
Project description
KR Translator
Translate Korean text using LLM APIs (Google Gemini, OpenAI, Claude).
Installation
You can install the package using pip:
pip install kr-translation
Usage
Getting GOOGLE_API_KEY
-
Go to https://aistudio.google.com/apikey, follow instruction over there.
-
Save the API KEY somewhere safe.
Basic Translation
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key")
output = translator.translate("안녕하세요, 오빠!")
print(output)
Translate from a file
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key")
output = translator.translate_file("/path/to/file.txt")
print(output)
Save Translation to a file
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key")
korean_text = open("/path/to/file.txt").read()
translator.save_translation(korean_text, "output_file.txt")
Passing character information to improve translation
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key")
character_info = """
Seo Dalmi, a girl.
Nam Dosan, a boy.
Han Jipyeong, a boy, team leader at SH venture capital.
"""
output = translator.translate(
"korean text here",
characters=character_info,
)
Passing additional information to improve translation
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key")
additional_info = """
The story revolves around startups and venture capital, therefore there are company names
that might have direct english translation, in which DO NOT translate them into english but keep
the Korean name.
"""
output = translator.translate(
"korean text here",
additional_info=additional_info,
)
Using translation memory
Enable memory to maintain consistency across multiple translation sessions. The translator keeps a .memory file in the current directory that tracks character names, terminology, and plot context.
from kr_translator import TextTranslator
translator = TextTranslator(api_key="your_google_api_key", use_memory=True)
# First translation creates .memory file with a summary
output1 = translator.translate("chapter 1 korean text")
# Second translation reads .memory for context, then updates it
output2 = translator.translate("chapter 2 korean text")
Each call makes a second LLM request to update the summary (~500 words), so character names, relationships, and terminology stay consistent across chapters.
Using a specific Gemini model
By default, we use gemini-2.5-flash. You can specify a different model:
from kr_translator import TextTranslator
translator = TextTranslator(
api_key="your_google_api_key",
model="gemini-2.5-pro",
)
output = translator.translate("korean text here")
Using OpenAI model
from kr_translator import TextTranslator
translator = TextTranslator(
api_key="your_openai_api_key",
model_type="open_ai",
model="gpt-4o-mini",
)
output = translator.translate("korean text here")
Using Claude model
from kr_translator import TextTranslator
translator = TextTranslator(
api_key="your_anthropic_api_key",
model_type="anthropic",
)
output = translator.translate("korean text here")
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kr_translator-0.2.1.tar.gz.
File metadata
- Download URL: kr_translator-0.2.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-35-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15bd2e9ded48f040c0389cb7fef125bcc72a4ea967039ebe9275fc9accc46d14
|
|
| MD5 |
f91d59365682687982b01f074032f1c7
|
|
| BLAKE2b-256 |
1930d852f339b248f81711de99bce717486a50d9a79bdcb1b18eac584a3f680e
|
File details
Details for the file kr_translator-0.2.1-py3-none-any.whl.
File metadata
- Download URL: kr_translator-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-35-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fdd496282978ba97d9323700943a976bffb62da031664b36003bf3a0494acb3
|
|
| MD5 |
d62469f3b596c7816b6fa603d46f64b0
|
|
| BLAKE2b-256 |
a31856adda2aa02c69d44ef3839720ef9311d962a7a1c96d23c71dd69433baae
|