fix: skip lingo.dev i18n automation when API key is not set (#28704)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin AI
parent
9b3bbb9f72
commit
c106740d17
@@ -10,6 +10,7 @@ concurrency:
|
||||
jobs:
|
||||
i18n:
|
||||
name: Run i18n
|
||||
if: ${{ secrets.CI_LINGO_DOT_DEV_API_KEY != '' }}
|
||||
runs-on: blacksmith-2vcpu-ubuntu-2404
|
||||
permissions:
|
||||
actions: write
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { LINGO_DOT_DEV_API_KEY } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { LocaleCode } from "@lingo.dev/_spec";
|
||||
import { LingoDotDevEngine } from "lingo.dev/sdk";
|
||||
|
||||
import { LINGO_DOT_DEV_API_KEY } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
|
||||
export class LingoDotDevService {
|
||||
private static engine = new LingoDotDevEngine({
|
||||
apiKey: LINGO_DOT_DEV_API_KEY,
|
||||
});
|
||||
private static engine = LINGO_DOT_DEV_API_KEY
|
||||
? new LingoDotDevEngine({
|
||||
apiKey: LINGO_DOT_DEV_API_KEY,
|
||||
})
|
||||
: null;
|
||||
|
||||
/**
|
||||
* Localizes text from one language to another
|
||||
@@ -25,8 +26,13 @@ export class LingoDotDevService {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!LingoDotDevService.engine) {
|
||||
logger.warn("LingoDotDevService.localizeText() skipped: LINGO_DOT_DEV_API_KEY is not set");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.engine.localizeText(text, {
|
||||
const result = await LingoDotDevService.engine.localizeText(text, {
|
||||
sourceLocale,
|
||||
targetLocale,
|
||||
});
|
||||
@@ -50,8 +56,13 @@ export class LingoDotDevService {
|
||||
sourceLocale: string,
|
||||
targetLocales: string[]
|
||||
): Promise<string[]> {
|
||||
if (!LingoDotDevService.engine) {
|
||||
logger.warn("LingoDotDevService.batchLocalizeText() skipped: LINGO_DOT_DEV_API_KEY is not set");
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.engine.batchLocalizeText(text, {
|
||||
const result = await LingoDotDevService.engine.batchLocalizeText(text, {
|
||||
// TODO: LocaleCode is hacky, use our locale mapping instead.
|
||||
sourceLocale: sourceLocale as LocaleCode,
|
||||
targetLocales: targetLocales as LocaleCode[],
|
||||
@@ -76,8 +87,13 @@ export class LingoDotDevService {
|
||||
return texts;
|
||||
}
|
||||
|
||||
if (!LingoDotDevService.engine) {
|
||||
logger.warn("LingoDotDevService.localizeTexts() skipped: LINGO_DOT_DEV_API_KEY is not set");
|
||||
return texts;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.engine.localizeChat(
|
||||
const result = await LingoDotDevService.engine.localizeChat(
|
||||
texts.map((text) => ({ name: "NO_NAME", text: text.trim() })),
|
||||
{
|
||||
sourceLocale,
|
||||
|
||||
Reference in New Issue
Block a user