or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdv2-legacy-api.mdv3-adaptive-mt.mdv3-automl-translation.mdv3-data-structures.mdv3-glossary-management.mdv3-request-response-types.mdv3-translation-services.md

v3-glossary-management.mddocs/

0

# V3 Glossary Management

1

2

Translation glossaries provide consistent terminology translation for domain-specific content. Glossaries contain term mappings that ensure specific words or phrases are translated consistently according to user preferences, particularly useful for technical documentation, brand names, and specialized terminology.

3

4

## Core Import

5

6

```python

7

from google.cloud import translate_v3

8

```

9

10

## Capabilities

11

12

### Glossary Lifecycle Management

13

14

Create, update, and manage translation glossaries with custom terminology mappings.

15

16

```python { .api }

17

def create_glossary(

18

self,

19

request=None,

20

*,

21

parent=None,

22

glossary=None,

23

retry=None,

24

timeout=None,

25

metadata=()

26

):

27

"""

28

Creates a glossary and returns the long-running operation.

29

30

Args:

31

request (CreateGlossaryRequest): The request object

32

parent (str): Project/location resource name

33

glossary (Glossary): Glossary configuration

34

retry: Retry configuration

35

timeout (float): Request timeout in seconds

36

metadata: Additional metadata

37

38

Returns:

39

Operation: Long-running operation for glossary creation

40

"""

41

42

def update_glossary(

43

self,

44

request=None,

45

*,

46

glossary=None,

47

update_mask=None,

48

retry=None,

49

timeout=None,

50

metadata=()

51

):

52

"""

53

Updates a glossary and returns the long-running operation.

54

55

Args:

56

request (UpdateGlossaryRequest): The request object

57

glossary (Glossary): Updated glossary configuration

58

update_mask (FieldMask): Fields to update

59

retry: Retry configuration

60

timeout (float): Request timeout in seconds

61

metadata: Additional metadata

62

63

Returns:

64

Operation: Long-running operation for glossary update

65

"""

66

67

def list_glossaries(

68

self,

69

request=None,

70

*,

71

parent=None,

72

page_size=None,

73

page_token=None,

74

filter=None,

75

retry=None,

76

timeout=None,

77

metadata=()

78

):

79

"""

80

Lists glossaries in a project.

81

82

Args:

83

request (ListGlossariesRequest): The request object

84

parent (str): Project/location resource name

85

page_size (int): Maximum number of glossaries to return

86

page_token (str): Token for pagination

87

filter (str): Filter expression for glossaries

88

retry: Retry configuration

89

timeout (float): Request timeout in seconds

90

metadata: Additional metadata

91

92

Returns:

93

ListGlossariesResponse: Paginated list of glossaries

94

"""

95

96

def get_glossary(

97

self,

98

request=None,

99

*,

100

name=None,

101

retry=None,

102

timeout=None,

103

metadata=()

104

):

105

"""

106

Gets a glossary.

107

108

Args:

109

request (GetGlossaryRequest): The request object

110

name (str): Glossary resource name

111

retry: Retry configuration

112

timeout (float): Request timeout in seconds

113

metadata: Additional metadata

114

115

Returns:

116

Glossary: Glossary resource

117

"""

118

119

def delete_glossary(

120

self,

121

request=None,

122

*,

123

name=None,

124

retry=None,

125

timeout=None,

126

metadata=()

127

):

128

"""

129

Deletes a glossary, or cancels glossary construction if in progress.

130

131

Args:

132

request (DeleteGlossaryRequest): The request object

133

name (str): Glossary resource name

134

retry: Retry configuration

135

timeout (float): Request timeout in seconds

136

metadata: Additional metadata

137

138

Returns:

139

Operation: Long-running operation for glossary deletion

140

"""

141

```

142

143

### Glossary Entry Management

144

145

Manage individual glossary entries for fine-grained terminology control.

146

147

```python { .api }

148

def create_glossary_entry(

149

self,

150

request=None,

151

*,

152

parent=None,

153

glossary_entry=None,

154

retry=None,

155

timeout=None,

156

metadata=()

157

):

158

"""

159

Creates a glossary entry.

160

161

Args:

162

request (CreateGlossaryEntryRequest): The request object

163

parent (str): Glossary resource name

164

glossary_entry (GlossaryEntry): Entry configuration

165

retry: Retry configuration

166

timeout (float): Request timeout in seconds

167

metadata: Additional metadata

168

169

Returns:

170

GlossaryEntry: Created glossary entry

171

"""

172

173

def update_glossary_entry(

174

self,

175

request=None,

176

*,

177

glossary_entry=None,

178

retry=None,

179

timeout=None,

180

metadata=()

181

):

182

"""

183

Updates a glossary entry.

184

185

Args:

186

request (UpdateGlossaryEntryRequest): The request object

187

glossary_entry (GlossaryEntry): Updated entry configuration

188

retry: Retry configuration

189

timeout (float): Request timeout in seconds

190

metadata: Additional metadata

191

192

Returns:

193

GlossaryEntry: Updated glossary entry

194

"""

195

196

def list_glossary_entries(

197

self,

198

request=None,

199

*,

200

parent=None,

201

page_size=None,

202

page_token=None,

203

retry=None,

204

timeout=None,

205

metadata=()

206

):

207

"""

208

List the entries for the glossary.

209

210

Args:

211

request (ListGlossaryEntriesRequest): The request object

212

parent (str): Glossary resource name

213

page_size (int): Maximum number of entries to return

214

page_token (str): Token for pagination

215

retry: Retry configuration

216

timeout (float): Request timeout in seconds

217

metadata: Additional metadata

218

219

Returns:

220

ListGlossaryEntriesResponse: Paginated list of glossary entries

221

"""

222

223

def get_glossary_entry(

224

self,

225

request=None,

226

*,

227

name=None,

228

retry=None,

229

timeout=None,

230

metadata=()

231

):

232

"""

233

Gets a single glossary entry by the given id.

234

235

Args:

236

request (GetGlossaryEntryRequest): The request object

237

name (str): Glossary entry resource name

238

retry: Retry configuration

239

timeout (float): Request timeout in seconds

240

metadata: Additional metadata

241

242

Returns:

243

GlossaryEntry: Glossary entry resource

244

"""

245

246

def delete_glossary_entry(

247

self,

248

request=None,

249

*,

250

name=None,

251

retry=None,

252

timeout=None,

253

metadata=()

254

):

255

"""

256

Deletes a single entry from the glossary.

257

258

Args:

259

request (DeleteGlossaryEntryRequest): The request object

260

name (str): Glossary entry resource name

261

retry: Retry configuration

262

timeout (float): Request timeout in seconds

263

metadata: Additional metadata

264

265

Returns:

266

None

267

"""

268

```

269

270

## Usage Examples

271

272

### Creating a Glossary from Cloud Storage

273

274

```python

275

from google.cloud import translate_v3

276

277

client = translate_v3.TranslationServiceClient()

278

279

parent = "projects/my-project/locations/us-central1"

280

281

glossary = {

282

"name": f"{parent}/glossaries/my-glossary",

283

"language_pair": {

284

"source_language_code": "en",

285

"target_language_code": "es",

286

},

287

"input_config": {

288

"gcs_source": {

289

"input_uri": "gs://my-bucket/glossary.csv"

290

},

291

"mime_type": "text/csv"

292

}

293

}

294

295

operation = client.create_glossary(

296

request={

297

"parent": parent,

298

"glossary": glossary,

299

}

300

)

301

302

print(f"Operation name: {operation.name}")

303

304

# Wait for operation to complete

305

result = operation.result(timeout=300)

306

print(f"Created glossary: {result.name}")

307

print(f"Entry count: {result.entry_count}")

308

```

309

310

### Creating a Glossary with Equivalent Terms

311

312

```python

313

from google.cloud import translate_v3

314

315

client = translate_v3.TranslationServiceClient()

316

317

parent = "projects/my-project/locations/us-central1"

318

319

glossary = {

320

"name": f"{parent}/glossaries/multi-language-glossary",

321

"language_codes_set": {

322

"language_codes": ["en", "es", "fr"]

323

},

324

"input_config": {

325

"gcs_source": {

326

"input_uri": "gs://my-bucket/multilingual-glossary.tsv"

327

},

328

"mime_type": "text/tab-separated-values"

329

}

330

}

331

332

operation = client.create_glossary(

333

request={

334

"parent": parent,

335

"glossary": glossary,

336

}

337

)

338

339

result = operation.result(timeout=300)

340

print(f"Created multilingual glossary: {result.name}")

341

```

342

343

### Using Glossary in Translation

344

345

```python

346

from google.cloud import translate_v3

347

348

client = translate_v3.TranslationServiceClient()

349

350

parent = "projects/my-project/locations/us-central1"

351

glossary_name = f"{parent}/glossaries/my-glossary"

352

353

glossary_config = {

354

"glossary": glossary_name

355

}

356

357

response = client.translate_text(

358

request={

359

"parent": parent,

360

"contents": ["Hello world", "Machine learning"],

361

"mime_type": "text/plain",

362

"source_language_code": "en",

363

"target_language_code": "es",

364

"glossary_config": glossary_config,

365

}

366

)

367

368

for translation in response.translations:

369

print(f"Translated with glossary: {translation.translated_text}")

370

```

371

372

### Managing Glossary Entries

373

374

```python

375

from google.cloud import translate_v3

376

377

client = translate_v3.TranslationServiceClient()

378

379

glossary_name = "projects/my-project/locations/us-central1/glossaries/my-glossary"

380

381

# Create a new glossary entry

382

glossary_entry = {

383

"terms_set": {

384

"terms": {

385

"en": "machine learning",

386

"es": "aprendizaje automático"

387

}

388

}

389

}

390

391

entry = client.create_glossary_entry(

392

request={

393

"parent": glossary_name,

394

"glossary_entry": glossary_entry,

395

}

396

)

397

398

print(f"Created entry: {entry.name}")

399

400

# List all entries

401

entries_response = client.list_glossary_entries(

402

request={

403

"parent": glossary_name,

404

"page_size": 10,

405

}

406

)

407

408

for entry in entries_response.glossary_entries:

409

print(f"Entry: {entry.name}")

410

if hasattr(entry, 'terms_set'):

411

for term in entry.terms_set.terms:

412

print(f" {term}: {entry.terms_set.terms[term]}")

413

414

# Update an entry

415

entry.terms_set.terms["fr"] = "apprentissage automatique"

416

417

updated_entry = client.update_glossary_entry(

418

request={

419

"glossary_entry": entry,

420

}

421

)

422

423

print(f"Updated entry with French term: {updated_entry.terms_set.terms['fr']}")

424

```

425

426

### Listing and Managing Glossaries

427

428

```python

429

from google.cloud import translate_v3

430

431

client = translate_v3.TranslationServiceClient()

432

433

parent = "projects/my-project/locations/us-central1"

434

435

# List all glossaries

436

response = client.list_glossaries(

437

request={

438

"parent": parent,

439

"page_size": 10,

440

}

441

)

442

443

for glossary in response.glossaries:

444

print(f"Glossary: {glossary.name}")

445

print(f"Display name: {glossary.display_name}")

446

print(f"Entry count: {glossary.entry_count}")

447

448

if hasattr(glossary, 'language_pair'):

449

print(f"Language pair: {glossary.language_pair.source_language_code} -> {glossary.language_pair.target_language_code}")

450

elif hasattr(glossary, 'language_codes_set'):

451

print(f"Language codes: {', '.join(glossary.language_codes_set.language_codes)}")

452

453

print(f"Submit time: {glossary.submit_time}")

454

print("---")

455

456

# Get specific glossary

457

glossary_name = f"{parent}/glossaries/my-glossary"

458

glossary = client.get_glossary(

459

request={"name": glossary_name}

460

)

461

462

print(f"Retrieved glossary: {glossary.display_name}")

463

print(f"Input URI: {glossary.input_config.gcs_source.input_uri}")

464

```

465

466

### Updating a Glossary

467

468

```python

469

from google.cloud import translate_v3

470

from google.protobuf import field_mask_pb2

471

472

client = translate_v3.TranslationServiceClient()

473

474

glossary_name = "projects/my-project/locations/us-central1/glossaries/my-glossary"

475

476

# Get existing glossary

477

glossary = client.get_glossary(

478

request={"name": glossary_name}

479

)

480

481

# Update display name

482

glossary.display_name = "Updated Glossary Name"

483

484

# Create update mask

485

update_mask = field_mask_pb2.FieldMask()

486

update_mask.paths.append("display_name")

487

488

# Update glossary

489

operation = client.update_glossary(

490

request={

491

"glossary": glossary,

492

"update_mask": update_mask,

493

}

494

)

495

496

result = operation.result(timeout=300)

497

print(f"Updated glossary: {result.display_name}")

498

```

499

500

### Deleting a Glossary

501

502

```python

503

from google.cloud import translate_v3

504

505

client = translate_v3.TranslationServiceClient()

506

507

glossary_name = "projects/my-project/locations/us-central1/glossaries/my-glossary"

508

509

operation = client.delete_glossary(

510

request={"name": glossary_name}

511

)

512

513

result = operation.result(timeout=300)

514

print(f"Deleted glossary: {result.name}")

515

print(f"Submit time: {result.submit_time}")

516

print(f"End time: {result.end_time}")

517

```