Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/lg/src/commands/lg/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class TranslateCommand extends Command {
srclang: flags.string({description: 'Source lang code. Auto detect if missing.'}),
translate_comments: flags.boolean({description: 'Machine translate all comments found in .lg file'}),
translate_link_text: flags.boolean({description: 'Machine translate link description in .lg file'}),
region: flags.string({description: 'The sub region.', required: true}),
help: flags.help({char: 'h', description: 'lg:translate help'}),
}

Expand Down Expand Up @@ -68,7 +69,7 @@ export default class TranslateCommand extends Command {
for (const toLang of toLangs) {
const tgt_lang = toLang.trim()
if (tgt_lang !== '') {
const translateOption = new TranslateOption(flags.translatekey, toLang, src_lang)
const translateOption = new TranslateOption(flags.translatekey, toLang, src_lang, flags.region)
const result = await this.translateLGFileToSpecificLang(filePath, translateOption, translateParts)
const outputFilePath = this.getOutputFile(filePath, tgt_lang, flags.out)
if (!outputFilePath) {
Expand Down
9 changes: 8 additions & 1 deletion packages/lg/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class Helper {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': translateOption.subscriptionKey,
'Ocp-Apim-Subscription-Region': translateOption.region,
'X-ClientTraceId': Helper.get_guid(),
},
}
Expand Down Expand Up @@ -181,10 +182,16 @@ export class TranslateOption {
*/
public src_lang: string

constructor(subscriptionKey: string, to_lang: string, src_lang: string) {
/**
* the ubscription region.
*/
public region: string

constructor(subscriptionKey: string, to_lang: string, src_lang: string, region: string) {
this.subscriptionKey = subscriptionKey
this.to_lang = to_lang
this.src_lang = src_lang
this.region = region
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/lg/test/commands/lg/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const generatedFolderPath = './../../fixtures/generated'
const verifiedFolderPath = './../../fixtures/verified'
const generatedFolder = path.join(__dirname, generatedFolderPath)
const translatekey = '11111111111111111111111111111111'
const subsregion = 'japaneast'

describe('lg:translate to fr', async () => {
const response = require('./../../fixtures/testcase/translate-fr-1.json')
Expand Down Expand Up @@ -48,6 +49,8 @@ describe('lg:translate to fr', async () => {
.command(['lg:translate',
'--translatekey',
translatekey,
'--region',
subsregion,
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--tgtlang',
Expand Down Expand Up @@ -90,6 +93,8 @@ describe('lg:translate to zh-cn', async () => {
.command(['lg:translate',
'--translatekey',
translatekey,
'--region',
subsregion,
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--tgtlang',
Expand Down Expand Up @@ -131,6 +136,8 @@ describe('lg:translate to zh-cn with comments', async () => {
.command(['lg:translate',
'--translatekey',
translatekey,
'--region',
subsregion,
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--tgtlang',
Expand Down Expand Up @@ -173,6 +180,8 @@ describe('lg:translate to zh-cn with translate_link_text', async () => {
.command(['lg:translate',
'--translatekey',
translatekey,
'--region',
subsregion,
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--tgtlang',
Expand Down