diff --git a/.changeset/tame-snails-fold.md b/.changeset/tame-snails-fold.md new file mode 100644 index 000000000..7c634f2d3 --- /dev/null +++ b/.changeset/tame-snails-fold.md @@ -0,0 +1,10 @@ +--- +"@logto/language-kit": patch +"@logto/translate": patch +--- + +make method `isLanguageTag` case-insensitive + +The language tags should be case insensitive. In `phrases` and `phrases-experience` packages, the language tags are all in lowercase. However, in the language kit, the language tags are in mixed cases, such as `pt-BR` and `zh-CN`. + +Therefore, some of the i18n phrases were not translated by the translate CLI tool. The fix is to update the language kit to ignore cases in `isLanguageTag` function, so that the previously mismatched language tags can be detected and translated. diff --git a/packages/toolkit/language-kit/src/utility.ts b/packages/toolkit/language-kit/src/utility.ts index 01cfe914b..2cea43b7a 100644 --- a/packages/toolkit/language-kit/src/utility.ts +++ b/packages/toolkit/language-kit/src/utility.ts @@ -4,7 +4,10 @@ import { languages } from './const.js'; import type { LanguageTag } from './type.js'; export const isLanguageTag = (value: unknown): value is LanguageTag => - typeof value === 'string' && value in languages; + typeof value === 'string' && + Object.keys(languages) + .map((key) => key.toLowerCase()) + .includes(value.toLowerCase()); export const languageTagGuard: z.ZodType = z .any() diff --git a/packages/translate/src/prompts.ts b/packages/translate/src/prompts.ts index d7537142f..5b928b8aa 100644 --- a/packages/translate/src/prompts.ts +++ b/packages/translate/src/prompts.ts @@ -1,4 +1,4 @@ -import { languages, type LanguageTag } from '@logto/language-kit'; +import { type LanguageTag } from '@logto/language-kit'; import { conditionalString } from '@silverhand/essentials'; type GetTranslationPromptProperties = { @@ -22,9 +22,7 @@ export const getTranslationPromptMessages = ({ }: GetTranslationPromptProperties) => [ { role: 'assistant', - content: `You are a assistant translator and will receive a TypeScript object. Traverse and find object values with "${untranslatedMark}" annotation on the top, then translate these values to target locale "${ - languages[targetLanguage] - }". Remove the "${untranslatedMark}" annotations from output. Escape the single quotes (if any) in translated results by prepending a backslash. Keep the interpolation double curly brackets and their inner values intact. Make sure there is a space between the CJK and non-CJK characters. Prefer using "你" instead of "您" in Chinese. Do not include sample code snippet below in the final output. ${conditionalString( + content: `You are a assistant translator and will receive a TypeScript object. Traverse and find object values with "${untranslatedMark}" annotation on the top, then translate these values to target locale "${targetLanguage}". Remove the "${untranslatedMark}" annotations from output. Escape the single quotes (if any) in translated results by prepending a backslash. Keep the interpolation double curly brackets and their inner values intact. Make sure there is a space between the CJK and non-CJK characters. Prefer using "你" instead of "您" in Chinese. Do not include sample code snippet below in the final output. ${conditionalString( extraPrompt )}