Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(124): microsoft translator region #127

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
20 changes: 9 additions & 11 deletions src/lib/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,21 +422,18 @@ export interface ITranslateFlowOptions {
translateIntents: boolean;
translateNodes: boolean;
apiKey: string;
apiRegion?: string;
forceYes: boolean;
locale: string;
}

/**
*
* @param flowName The name of the flow
* @param fromLanguage The locale in the flow that should be translated
* @param targetLanguage The target langauge to translate to
* @param translator Whether to use google, microsoft or deepl translate
* @param apiKey The google, microsoft or deepl translate API Key
* @param timeout The timeout for execution
* @param options
*/
export const translateFlow = async (flowName: string, options: ITranslateFlowOptions): Promise<void> => {
const { toLanguage, translator, apiKey } = options;
const { toLanguage, translator, apiKey, apiRegion } = options;

const flowsDir = CONFIG.agentDir + "/flows";
const flowDir = flowsDir + "/" + flowName;
Expand Down Expand Up @@ -465,7 +462,7 @@ export const translateFlow = async (flowName: string, options: ITranslateFlowOpt
for (let intent of flowIntents) {
try {
if (intent.localeReference === targetLocale._id) {
await translateIntent(intent, flowConfig._id, targetLocale, toLanguage, translator, apiKey);
await translateIntent(intent, flowConfig._id, targetLocale, toLanguage, translator, apiKey, apiRegion);
}
} catch (err) {
// if a localization throws an error, we skip
Expand All @@ -485,7 +482,7 @@ export const translateFlow = async (flowName: string, options: ITranslateFlowOpt
try {
if (localeReference === targetLocale._id) {
if (['say', 'question', 'optionalQuestion'].indexOf(type) > -1) {
const flowNode = await translateFlowNode(node, toLanguage, translator, apiKey);
const flowNode = await translateFlowNode(node, toLanguage, translator, apiKey, apiRegion);
// update node in Cognigy.AI
await CognigyClient.updateChartNode({
nodeId: flowNode._id,
Expand Down Expand Up @@ -788,8 +785,9 @@ export const localizeFlow = async (flowName: string, availableProgress: number,
* @param toLanguage Language to translate to
* @param translator Translator to use
* @param apiKey apikey for the translator
* @param apiRegion API Region used by Microsoft Translator
*/
export const translateIntent = async (intent: any, flowId, targetLocale, toLanguage, translator, apiKey): Promise<void> => {
export const translateIntent = async (intent: any, flowId, targetLocale, toLanguage, translator, apiKey, apiRegion): Promise<void> => {
const intentData = await CognigyClient.readIntent({
intentId: intent._id,
flowId,
Expand All @@ -799,7 +797,7 @@ export const translateIntent = async (intent: any, flowId, targetLocale, toLangu
// translate default reply
if (intentData.data) {
try {
intentData.data = await translateSayNode(intentData.data, toLanguage, translator, apiKey);
intentData.data = await translateSayNode(intentData.data, toLanguage, translator, apiKey, apiRegion);
await CognigyClient.updateIntent({
intentId: intent._id,
flowId,
Expand Down Expand Up @@ -833,7 +831,7 @@ export const translateIntent = async (intent: any, flowId, targetLocale, toLangu
try {
for (let sentence of intentSentences) {
// translate the current example sentence of the current intent
sentence = await translateIntentExampleSentence(sentence, toLanguage, translator, apiKey)
sentence = await translateIntentExampleSentence(sentence, toLanguage, translator, apiKey, apiRegion);

try {
// update example sentence in Cognigy.AI
Expand Down
3 changes: 2 additions & 1 deletion src/program/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ program
.option('-ti, --translateIntents', 'adds localization to Flow Intents')
.option('-tn, --translateNodes', 'adds localization to Flow Nodes')
.option('-k, --apiKey <apiKey>', 'the translator api key')
.option('-r, --apiRegion <apiRegion>', 'the translator api region; needed by microsoft regional translator')
.option('-y, --forceYes', 'skips warnings and overwrites all content')
.action(async (resourceType, resourceName, cmdObj) => { await translate({ resourceType, resourceName, options: cmdObj }); });

Expand All @@ -150,4 +151,4 @@ program
await run({ resourceType, playbookFile, options: cmdObj });
});

program.addCommand(makeKnowledgeAIProgram());
program.addCommand(makeKnowledgeAIProgram());
Loading