1- import type { LocaleCode } from "@lingo.dev/_spec" ;
2- import { LingoDotDevEngine } from "lingo.dev/sdk" ;
3-
41import { LINGO_DOT_DEV_API_KEY } from "@calcom/lib/constants" ;
52import logger from "@calcom/lib/logger" ;
3+ import type { LocaleCode } from "@lingo.dev/_spec" ;
4+ import { LingoDotDevEngine } from "lingo.dev/sdk" ;
65
76export class LingoDotDevService {
8- private static engine = new LingoDotDevEngine ( {
9- apiKey : LINGO_DOT_DEV_API_KEY ,
10- } ) ;
7+ private static engine = LINGO_DOT_DEV_API_KEY
8+ ? new LingoDotDevEngine ( {
9+ apiKey : LINGO_DOT_DEV_API_KEY ,
10+ } )
11+ : null ;
1112
1213 /**
1314 * Localizes text from one language to another
@@ -25,8 +26,13 @@ export class LingoDotDevService {
2526 return null ;
2627 }
2728
29+ if ( ! LingoDotDevService . engine ) {
30+ logger . warn ( "LingoDotDevService.localizeText() skipped: LINGO_DOT_DEV_API_KEY is not set" ) ;
31+ return null ;
32+ }
33+
2834 try {
29- const result = await this . engine . localizeText ( text , {
35+ const result = await LingoDotDevService . engine . localizeText ( text , {
3036 sourceLocale,
3137 targetLocale,
3238 } ) ;
@@ -50,8 +56,13 @@ export class LingoDotDevService {
5056 sourceLocale : string ,
5157 targetLocales : string [ ]
5258 ) : Promise < string [ ] > {
59+ if ( ! LingoDotDevService . engine ) {
60+ logger . warn ( "LingoDotDevService.batchLocalizeText() skipped: LINGO_DOT_DEV_API_KEY is not set" ) ;
61+ return [ ] ;
62+ }
63+
5364 try {
54- const result = await this . engine . batchLocalizeText ( text , {
65+ const result = await LingoDotDevService . engine . batchLocalizeText ( text , {
5566 // TODO: LocaleCode is hacky, use our locale mapping instead.
5667 sourceLocale : sourceLocale as LocaleCode ,
5768 targetLocales : targetLocales as LocaleCode [ ] ,
@@ -76,8 +87,13 @@ export class LingoDotDevService {
7687 return texts ;
7788 }
7889
90+ if ( ! LingoDotDevService . engine ) {
91+ logger . warn ( "LingoDotDevService.localizeTexts() skipped: LINGO_DOT_DEV_API_KEY is not set" ) ;
92+ return texts ;
93+ }
94+
7995 try {
80- const result = await this . engine . localizeChat (
96+ const result = await LingoDotDevService . engine . localizeChat (
8197 texts . map ( ( text ) => ( { name : "NO_NAME" , text : text . trim ( ) } ) ) ,
8298 {
8399 sourceLocale,
0 commit comments