0
# Script Transliteration
1
2
Convert text from one script to another within the same language, preserving pronunciation and meaning. Supports conversions like Latin to Cyrillic, Arabic to Latin, Devanagari to Latin, and many other script pairs for supported languages.
3
4
## Capabilities
5
6
### Transliterate Text
7
8
Converts characters or letters of input text from one script to corresponding characters in a target script while maintaining linguistic meaning.
9
10
```python { .api }
11
def transliterate(
12
body: Union[List[str], List[InputTextItem], IO[bytes]],
13
*,
14
language: str,
15
from_script: str,
16
to_script: str,
17
client_trace_id: Optional[str] = None,
18
**kwargs: Any
19
) -> List[TransliteratedText]
20
```
21
22
**Parameters:**
23
- `body`: Text to transliterate (strings, InputTextItem objects, or binary data)
24
- `language`: Language code for the text (e.g., "zh-Hans", "ar", "hi")
25
- `from_script`: Source script identifier (e.g., "Hans", "Arab", "Deva")
26
- `to_script`: Target script identifier (e.g., "Latn", "Cyrl")
27
- `client_trace_id`: Client-generated GUID for request tracking
28
29
**Returns:** List of transliteration results with script information
30
31
### Usage Examples
32
33
```python
34
from azure.ai.translation.text import TextTranslationClient
35
from azure.core.credentials import AzureKeyCredential
36
37
client = TextTranslationClient(
38
credential=AzureKeyCredential("your-api-key"),
39
region="your-region"
40
)
41
42
# Chinese to Latin transliteration
43
chinese_response = client.transliterate(
44
body=["这是个测试。"],
45
language="zh-Hans",
46
from_script="Hans",
47
to_script="Latn"
48
)
49
50
for result in chinese_response:
51
print(f"Original script: {result.script}")
52
print(f"Transliterated: {result.text}")
53
# Output: "zhè shì gè cè shì。"
54
55
# Arabic to Latin transliteration
56
arabic_response = client.transliterate(
57
body=["مرحبا بالعالم"],
58
language="ar",
59
from_script="Arab",
60
to_script="Latn"
61
)
62
63
# Hindi to Latin transliteration
64
hindi_response = client.transliterate(
65
body=["नमस्ते दुनिया"],
66
language="hi",
67
from_script="Deva",
68
to_script="Latn"
69
)
70
71
# Russian Cyrillic to Latin transliteration
72
russian_response = client.transliterate(
73
body=["Привет мир"],
74
language="ru",
75
from_script="Cyrl",
76
to_script="Latn"
77
)
78
79
# Multiple texts in single request
80
multiple_response = client.transliterate(
81
body=["第一个测试", "第二个例子"],
82
language="zh-Hans",
83
from_script="Hans",
84
to_script="Latn"
85
)
86
87
for i, result in enumerate(multiple_response):
88
print(f"Text {i+1}: {result.text}")
89
```
90
91
## Input Types
92
93
### Text Input Models
94
95
```python { .api }
96
class InputTextItem:
97
text: str # Text content to transliterate
98
```
99
100
## Response Types
101
102
### Transliteration Results
103
104
```python { .api }
105
class TransliteratedText:
106
script: str # Target script identifier used in output
107
text: str # Transliterated text in target script
108
```
109
110
## Script Discovery
111
112
Use the language support endpoint to discover available script conversions:
113
114
```python
115
# Get transliteration languages and their supported scripts
116
response = client.get_supported_languages(scope="transliteration")
117
118
if response.transliteration:
119
for lang_code, lang_info in response.transliteration.items():
120
print(f"\nLanguage: {lang_code} ({lang_info.name})")
121
122
for script in lang_info.scripts:
123
print(f" From script: {script.code} ({script.name})")
124
print(f" Available conversions:")
125
126
for target_script in script.to_scripts:
127
print(f" -> {target_script.code} ({target_script.name})")
128
```
129
130
## Common Script Codes
131
132
### Source Scripts
133
- `Hans`: Simplified Chinese characters
134
- `Hant`: Traditional Chinese characters
135
- `Arab`: Arabic script
136
- `Deva`: Devanagari (Hindi, Sanskrit)
137
- `Cyrl`: Cyrillic (Russian, Bulgarian, etc.)
138
- `Gujr`: Gujarati script
139
- `Guru`: Gurmukhi (Punjabi)
140
- `Hebr`: Hebrew script
141
- `Jpan`: Japanese (Hiragana/Katakana/Kanji)
142
- `Kore`: Korean (Hangul/Hanja)
143
- `Thai`: Thai script
144
145
### Target Scripts
146
- `Latn`: Latin alphabet
147
- `Cyrl`: Cyrillic script
148
- `Arab`: Arabic script
149
- `Hans`: Simplified Chinese
150
- `Hant`: Traditional Chinese
151
152
## Error Handling
153
154
```python
155
from azure.core.exceptions import HttpResponseError
156
157
try:
158
response = client.transliterate(
159
body=["Invalid text for script"],
160
language="zh-Hans",
161
from_script="InvalidScript", # Invalid script code
162
to_script="Latn"
163
)
164
except HttpResponseError as error:
165
if error.error:
166
print(f"Error Code: {error.error.code}")
167
print(f"Message: {error.error.message}")
168
```