Skip to content

Commit cea7a9f

Browse files
jasperdewclaude
andcommitted
feat: add context, instructions, and glossary to translate method
New optional parameters for the translate method: - context: describes what the text is about (max 500 chars) - instructions: tells the model how to translate (max 500 chars) - glossary: list of term dicts to force specific translations All fields are optional. Omitting them preserves full Google Translate v2 compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 636c596 commit cea7a9f

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__pycache__/
2+
*.egg-info/
3+
dist/
4+
build/
5+
.eggs/
6+
*.pyc

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "langbly"
7-
version = "0.1.0"
7+
version = "0.2.0"
88
description = "Official Python SDK for the Langbly translation API"
99
readme = "README.md"
1010
license = "MIT"

src/langbly/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def translate(
101101
target: str,
102102
source: Optional[str] = None,
103103
format: Optional[str] = None,
104+
context: Optional[str] = None,
105+
instructions: Optional[str] = None,
106+
glossary: Optional[List[dict]] = None,
104107
) -> Union[Translation, List[Translation]]:
105108
"""Translate text to the target language.
106109
@@ -109,6 +112,11 @@ def translate(
109112
target: Target language code (e.g., "nl", "de", "fr").
110113
source: Source language code. Auto-detected if omitted.
111114
format: "text" or "html". Default: "text".
115+
context: Describes what the text is about (max 500 chars).
116+
Example: "e-commerce checkout page", "medical report".
117+
instructions: Tells the model how to translate (max 500 chars).
118+
Example: "Use informal Dutch", "Do not translate product names".
119+
glossary: List of {"source": "...", "target": "..."} term pairs (max 200).
112120
113121
Returns:
114122
A Translation object, or a list if input was a list.
@@ -125,6 +133,12 @@ def translate(
125133
body["source"] = source
126134
if format:
127135
body["format"] = format
136+
if context:
137+
body["context"] = context
138+
if instructions:
139+
body["instructions"] = instructions
140+
if glossary:
141+
body["glossary"] = glossary
128142

129143
data = self._post("/language/translate/v2", body)
130144

0 commit comments

Comments
 (0)