AI-native design editor. Open-source Figma alternative.
fix(i18n): ignore placeholders in script checks
Danila Poyarkov6d96edcc521d
diff --git a/tools/i18n/mixed-script-baseline.txt b/tools/i18n/mixed-script-baseline.txtindex 26e82b576..b7155a32a 100644--- a/tools/i18n/mixed-script-baseline.txt+++ b/tools/i18n/mixed-script-baseline.txt@@ -21,11 +21,8 @@ ja:ai.getProviderAPIKeyja:ai.modelIDja:ai.modelIDPlaceholderja:ai.modelRoleDesignDescription-ja:ai.permissionRequestja:ai.providerja:ai.reasoningEffortPlaceholder-ja:ai.removeImageAttachment-ja:ai.viewAttachmentja:automation.addServerConnectionja:automation.authenticationDescriptionja:automation.bearerAuthentication@@ -45,15 +42,11 @@ ja:automation.rootDirectoryja:automation.rootDirectoryDescriptionja:automation.searchToolsja:automation.serverURL-ja:automation.toolsEnabledja:automation.toolsRestartNoticeja:code.copyJSXReference-ja:collaboration.clickToFollowPeer-ja:collaboration.followingPeerStopja:collaboration.pasteRoomLinkOrIdja:commands.paletteDescriptionja:credentials.getAPIKey-ja:credentials.storageja:diagnostics.acpFailedja:diagnostics.chatCompletedja:diagnostics.chatFailed@@ -64,25 +57,18 @@ ja:diagnostics.modelStepCompletedja:diagnostics.usageDescriptionja:diagnostics.usageHistoryDescriptionja:editor.showUI-ja:editor.toolOptionsja:files.browserFileAPINotSupportedja:files.clipboardImageFetchFailedja:files.clipboardImagesFetchFailedja:files.clipboardImagesUnavailableWebja:files.clipboardImageUnavailableWeb-ja:files.closeTabja:files.importFailedja:files.importHTMLCSSja:files.importHTMLCSSDescription-ja:files.noMatchingFilesja:files.orEdgeForFullSupportja:files.useChrome-ja:fonts.affectedLayerCountja:fonts.downloadFallbackPacksDescriptionja:fonts.downloadMissingWebFonts-ja:fonts.issuesFound-ja:fonts.providerDisabled-ja:fonts.providerEnabledja:fonts.webFontProvidersRequireDesktopAppja:media.getPexelsAPIKeyja:media.getUnsplashAccessKey@@ -101,23 +87,15 @@ ja:menu.exportSelectionAsPNGja:menu.exportSelectionAsPPTXja:menu.exportSelectionAsSVGja:menu.toggleUI-ja:pages.pageName-ja:panels.assetVariantSummaryja:panels.colorHintHsbja:panels.colorHintHslja:panels.colorHintOkhcl-ja:panels.colorPreviewClipped-ja:panels.createColorVariable-ja:panels.createNumberVariable-ja:panels.layersCountja:panels.localFontsAccessHint-ja:panels.missingStyleja:panels.sizingFillFrja:panels.sizingFixedPxja:panels.xAxisja:panels.yAxisja:recovery.dialogDescription-ja:rename.layersja:rendering.reloadRequiredja:rendering.settingsDescriptionja:rendering.urlOverride@@ -129,7 +107,6 @@ ja:storage.copyCorsja:storage.providerS3ja:updates.availableja:updates.availableTitle-ja:updates.checkFailedja:updates.downloadingja:updates.installedja:updates.unavailable@@ -158,11 +135,8 @@ zh-cn:ai.maxOutputTokenszh-cn:ai.modelIDzh-cn:ai.modelIDPlaceholderzh-cn:ai.modelRoleDesignDescription-zh-cn:ai.permissionRequestzh-cn:ai.providerzh-cn:ai.reasoningEffortPlaceholder-zh-cn:ai.removeImageAttachment-zh-cn:ai.viewAttachmentzh-cn:automation.addServerConnectionzh-cn:automation.authenticationDescriptionzh-cn:automation.bearerAuthentication@@ -182,15 +156,11 @@ zh-cn:automation.rootDirectoryzh-cn:automation.rootDirectoryDescriptionzh-cn:automation.searchToolszh-cn:automation.serverURL-zh-cn:automation.toolsEnabledzh-cn:automation.toolsRestartNoticezh-cn:code.copyJSXReference-zh-cn:collaboration.clickToFollowPeer-zh-cn:collaboration.followingPeerStopzh-cn:collaboration.pasteRoomLinkOrIdzh-cn:commands.paletteDescriptionzh-cn:credentials.getAPIKey-zh-cn:credentials.storagezh-cn:diagnostics.acpFailedzh-cn:diagnostics.chatCompletedzh-cn:diagnostics.chatFailed@@ -200,24 +170,15 @@ zh-cn:diagnostics.mcpFailedzh-cn:diagnostics.modelStepCompletedzh-cn:diagnostics.usageDescriptionzh-cn:diagnostics.usageHistoryDescription-zh-cn:editor.showUI-zh-cn:editor.toolOptionszh-cn:files.browserFileAPINotSupportedzh-cn:files.clipboardImageFetchFailedzh-cn:files.clipboardImagesFetchFailed-zh-cn:files.clipboardImagesUnavailableWeb-zh-cn:files.closeTabzh-cn:files.importFailedzh-cn:files.importHTMLCSSzh-cn:files.importHTMLCSSDescription-zh-cn:files.noMatchingFileszh-cn:files.orEdgeForFullSupportzh-cn:files.useChrome-zh-cn:fonts.affectedLayerCountzh-cn:fonts.downloadFallbackPacksDescription-zh-cn:fonts.issuesFound-zh-cn:fonts.providerDisabled-zh-cn:fonts.providerEnabledzh-cn:media.getPexelsAPIKeyzh-cn:media.getUnsplashAccessKeyzh-cn:media.pexelsAlternativeOptional@@ -234,23 +195,15 @@ zh-cn:menu.exportSelectionAsFigzh-cn:menu.exportSelectionAsPNGzh-cn:menu.exportSelectionAsPPTXzh-cn:menu.exportSelectionAsSVG-zh-cn:pages.pageName-zh-cn:panels.assetVariantSummaryzh-cn:panels.colorHintHsbzh-cn:panels.colorHintHslzh-cn:panels.colorHintOkhcl-zh-cn:panels.colorPreviewClipped-zh-cn:panels.createColorVariable-zh-cn:panels.createNumberVariable-zh-cn:panels.layersCountzh-cn:panels.localFontsAccessHint-zh-cn:panels.missingStylezh-cn:panels.sizingFillFrzh-cn:panels.sizingFixedPxzh-cn:panels.xAxiszh-cn:panels.yAxiszh-cn:recovery.dialogDescription-zh-cn:rename.layerszh-cn:rendering.reloadRequiredzh-cn:rendering.settingsDescriptionzh-cn:rendering.urlOverride@@ -262,7 +215,6 @@ zh-cn:storage.copyCorszh-cn:storage.providerS3zh-cn:updates.availablezh-cn:updates.availableTitle-zh-cn:updates.checkFailedzh-cn:updates.downloadingzh-cn:updates.installedzh-cn:updates.unavailablediff --git a/tools/i18n/package.json b/tools/i18n/package.jsonindex 0dd2ae1b5..1811c77ad 100644--- a/tools/i18n/package.json+++ b/tools/i18n/package.json@@ -1,5 +1,8 @@{"name": "@open-pencil/i18n-tools","private": true,- "type": "module"+ "type": "module",+ "scripts": {+ "test": "bun test"+ }}diff --git a/tools/i18n/src/check-locales.ts b/tools/i18n/src/check-locales.tsindex 2d33eead9..ee3995a6f 100644--- a/tools/i18n/src/check-locales.ts+++ b/tools/i18n/src/check-locales.ts@@ -10,6 +10,8 @@ import {type TranslatedLocale} from '@open-pencil/vue'+import { hasMixedLatinAndCjk, placeholders } from './quality'+const LOCALES_DIR = 'packages/vue/src/i18n/locales'const LOCALE_FILE_NAMES: Record<string, string> = {variableTypes: 'variable-types'@@ -17,7 +19,6 @@ const LOCALE_FILE_NAMES: Record<string, string> = {const REQUIRED_INDEX_FILE = 'index.ts'const TRANSLATION_BASELINE_PATH = 'tools/i18n/translation-baseline.txt'const MIXED_SCRIPT_BASELINE_PATH = 'tools/i18n/mixed-script-baseline.txt'-const PLACEHOLDER_PATTERN = /\{([A-Za-z][A-Za-z0-9_]*)\}/gfunction sourceMessage(value: unknown): string | null {if (typeof value === 'string') return value@@ -28,21 +29,10 @@ function sourceMessage(value: unknown): string | null {return null}-function placeholders(value: string): string[] {- return [...value.matchAll(PLACEHOLDER_PATTERN)].map((match) => match[1]).sort()-}-function normalized(value: string): string {return value.normalize('NFKC').replaceAll(/\s+/g, ' ').trim()}-function hasMixedLatinAndCjk(value: string): boolean {- return (- /\p{Script=Latin}/u.test(value) &&- /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(value)- )-}-function localeFileName(namespace: string) {return LOCALE_FILE_NAMES[namespace] ?? namespace}diff --git a/tools/i18n/src/quality.ts b/tools/i18n/src/quality.tsnew file mode 100644index 000000000..be86db0ee--- /dev/null+++ b/tools/i18n/src/quality.ts@@ -0,0 +1,17 @@+const PLACEHOLDER_PATTERN = /\{([A-Za-z][A-Za-z0-9_]*)\}/g++export function placeholders(value: string): string[] {+ return [...value.matchAll(PLACEHOLDER_PATTERN)].map((match) => match[1]).sort()+}++export function visibleTranslationText(value: string): string {+ return value.replaceAll(PLACEHOLDER_PATTERN, '')+}++export function hasMixedLatinAndCjk(value: string): boolean {+ const visibleText = visibleTranslationText(value)+ return (+ /\p{Script=Latin}/u.test(visibleText) &&+ /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(visibleText)+ )+}diff --git a/tools/i18n/tests/quality.test.ts b/tools/i18n/tests/quality.test.tsnew file mode 100644index 000000000..0453421ba--- /dev/null+++ b/tools/i18n/tests/quality.test.ts@@ -0,0 +1,25 @@+import { describe, expect, test } from 'bun:test'++import { hasMixedLatinAndCjk, placeholders, visibleTranslationText } from '../src/quality'++describe('translation quality checks', () => {+ test('extracts and removes interpolation placeholders', () => {+ expect(placeholders('移除图片 {name},尺寸 {width} × {height}')).toEqual([+ 'height',+ 'name',+ 'width'+ ])+ expect(visibleTranslationText('画像 {name} を削除')).toBe('画像 を削除')+ })++ test('does not treat placeholder identifiers as translated Latin text', () => {+ expect(hasMixedLatinAndCjk('画像 {name} を削除')).toBe(false)+ expect(hasMixedLatinAndCjk('查看附件 {name}')).toBe(false)+ })++ test('still detects visible Latin text mixed with CJK text', () => {+ expect(hasMixedLatinAndCjk('画像 OpenPencil を表示')).toBe(true)+ expect(hasMixedLatinAndCjk('APIキーを更新')).toBe(true)+ expect(hasMixedLatinAndCjk('画像を表示')).toBe(false)+ })+})