Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit b1d4cc1

Browse files
author
Shuai Wang
authored
Add region support in lg translate (#995)
1 parent df24cb2 commit b1d4cc1

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

packages/lg/src/commands/lg/translate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default class TranslateCommand extends Command {
4040
srclang: flags.string({description: 'Source lang code. Auto detect if missing.'}),
4141
translate_comments: flags.boolean({description: 'Machine translate all comments found in .lg file'}),
4242
translate_link_text: flags.boolean({description: 'Machine translate link description in .lg file'}),
43+
region: flags.string({description: 'The sub region.', required: true}),
4344
help: flags.help({char: 'h', description: 'lg:translate help'}),
4445
}
4546

@@ -68,7 +69,7 @@ export default class TranslateCommand extends Command {
6869
for (const toLang of toLangs) {
6970
const tgt_lang = toLang.trim()
7071
if (tgt_lang !== '') {
71-
const translateOption = new TranslateOption(flags.translatekey, toLang, src_lang)
72+
const translateOption = new TranslateOption(flags.translatekey, toLang, src_lang, flags.region)
7273
const result = await this.translateLGFileToSpecificLang(filePath, translateOption, translateParts)
7374
const outputFilePath = this.getOutputFile(filePath, tgt_lang, flags.out)
7475
if (!outputFilePath) {

packages/lg/src/utils/helper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export class Helper {
123123
headers: {
124124
'Content-Type': 'application/json',
125125
'Ocp-Apim-Subscription-Key': translateOption.subscriptionKey,
126+
'Ocp-Apim-Subscription-Region': translateOption.region,
126127
'X-ClientTraceId': Helper.get_guid(),
127128
},
128129
}
@@ -181,10 +182,16 @@ export class TranslateOption {
181182
*/
182183
public src_lang: string
183184

184-
constructor(subscriptionKey: string, to_lang: string, src_lang: string) {
185+
/**
186+
* the ubscription region.
187+
*/
188+
public region: string
189+
190+
constructor(subscriptionKey: string, to_lang: string, src_lang: string, region: string) {
185191
this.subscriptionKey = subscriptionKey
186192
this.to_lang = to_lang
187193
this.src_lang = src_lang
194+
this.region = region
188195
}
189196
}
190197

packages/lg/test/commands/lg/translate.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const generatedFolderPath = './../../fixtures/generated'
1717
const verifiedFolderPath = './../../fixtures/verified'
1818
const generatedFolder = path.join(__dirname, generatedFolderPath)
1919
const translatekey = '11111111111111111111111111111111'
20+
const subsregion = 'japaneast'
2021

2122
describe('lg:translate to fr', async () => {
2223
const response = require('./../../fixtures/testcase/translate-fr-1.json')
@@ -48,6 +49,8 @@ describe('lg:translate to fr', async () => {
4849
.command(['lg:translate',
4950
'--translatekey',
5051
translatekey,
52+
'--region',
53+
subsregion,
5154
'--in',
5255
path.join(__dirname, testcaseFolderPath, inputFileName),
5356
'--tgtlang',
@@ -90,6 +93,8 @@ describe('lg:translate to zh-cn', async () => {
9093
.command(['lg:translate',
9194
'--translatekey',
9295
translatekey,
96+
'--region',
97+
subsregion,
9398
'--in',
9499
path.join(__dirname, testcaseFolderPath, inputFileName),
95100
'--tgtlang',
@@ -131,6 +136,8 @@ describe('lg:translate to zh-cn with comments', async () => {
131136
.command(['lg:translate',
132137
'--translatekey',
133138
translatekey,
139+
'--region',
140+
subsregion,
134141
'--in',
135142
path.join(__dirname, testcaseFolderPath, inputFileName),
136143
'--tgtlang',
@@ -173,6 +180,8 @@ describe('lg:translate to zh-cn with translate_link_text', async () => {
173180
.command(['lg:translate',
174181
'--translatekey',
175182
translatekey,
183+
'--region',
184+
subsregion,
176185
'--in',
177186
path.join(__dirname, testcaseFolderPath, inputFileName),
178187
'--tgtlang',

0 commit comments

Comments
 (0)