Skip to content

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.txt
index 26e82b576..b7155a32a 100644
--- a/tools/i18n/mixed-script-baseline.txt
+++ b/tools/i18n/mixed-script-baseline.txt
@@ -21,11 +21,8 @@ ja:ai.getProviderAPIKey
ja:ai.modelID
ja:ai.modelIDPlaceholder
ja:ai.modelRoleDesignDescription
-ja:ai.permissionRequest
ja:ai.provider
ja:ai.reasoningEffortPlaceholder
-ja:ai.removeImageAttachment
-ja:ai.viewAttachment
ja:automation.addServerConnection
ja:automation.authenticationDescription
ja:automation.bearerAuthentication
@@ -45,15 +42,11 @@ ja:automation.rootDirectory
ja:automation.rootDirectoryDescription
ja:automation.searchTools
ja:automation.serverURL
-ja:automation.toolsEnabled
ja:automation.toolsRestartNotice
ja:code.copyJSXReference
-ja:collaboration.clickToFollowPeer
-ja:collaboration.followingPeerStop
ja:collaboration.pasteRoomLinkOrId
ja:commands.paletteDescription
ja:credentials.getAPIKey
-ja:credentials.storage
ja:diagnostics.acpFailed
ja:diagnostics.chatCompleted
ja:diagnostics.chatFailed
@@ -64,25 +57,18 @@ ja:diagnostics.modelStepCompleted
ja:diagnostics.usageDescription
ja:diagnostics.usageHistoryDescription
ja:editor.showUI
-ja:editor.toolOptions
ja:files.browserFileAPINotSupported
ja:files.clipboardImageFetchFailed
ja:files.clipboardImagesFetchFailed
ja:files.clipboardImagesUnavailableWeb
ja:files.clipboardImageUnavailableWeb
-ja:files.closeTab
ja:files.importFailed
ja:files.importHTMLCSS
ja:files.importHTMLCSSDescription
-ja:files.noMatchingFiles
ja:files.orEdgeForFullSupport
ja:files.useChrome
-ja:fonts.affectedLayerCount
ja:fonts.downloadFallbackPacksDescription
ja:fonts.downloadMissingWebFonts
-ja:fonts.issuesFound
-ja:fonts.providerDisabled
-ja:fonts.providerEnabled
ja:fonts.webFontProvidersRequireDesktopApp
ja:media.getPexelsAPIKey
ja:media.getUnsplashAccessKey
@@ -101,23 +87,15 @@ ja:menu.exportSelectionAsPNG
ja:menu.exportSelectionAsPPTX
ja:menu.exportSelectionAsSVG
ja:menu.toggleUI
-ja:pages.pageName
-ja:panels.assetVariantSummary
ja:panels.colorHintHsb
ja:panels.colorHintHsl
ja:panels.colorHintOkhcl
-ja:panels.colorPreviewClipped
-ja:panels.createColorVariable
-ja:panels.createNumberVariable
-ja:panels.layersCount
ja:panels.localFontsAccessHint
-ja:panels.missingStyle
ja:panels.sizingFillFr
ja:panels.sizingFixedPx
ja:panels.xAxis
ja:panels.yAxis
ja:recovery.dialogDescription
-ja:rename.layers
ja:rendering.reloadRequired
ja:rendering.settingsDescription
ja:rendering.urlOverride
@@ -129,7 +107,6 @@ ja:storage.copyCors
ja:storage.providerS3
ja:updates.available
ja:updates.availableTitle
-ja:updates.checkFailed
ja:updates.downloading
ja:updates.installed
ja:updates.unavailable
@@ -158,11 +135,8 @@ zh-cn:ai.maxOutputTokens
zh-cn:ai.modelID
zh-cn:ai.modelIDPlaceholder
zh-cn:ai.modelRoleDesignDescription
-zh-cn:ai.permissionRequest
zh-cn:ai.provider
zh-cn:ai.reasoningEffortPlaceholder
-zh-cn:ai.removeImageAttachment
-zh-cn:ai.viewAttachment
zh-cn:automation.addServerConnection
zh-cn:automation.authenticationDescription
zh-cn:automation.bearerAuthentication
@@ -182,15 +156,11 @@ zh-cn:automation.rootDirectory
zh-cn:automation.rootDirectoryDescription
zh-cn:automation.searchTools
zh-cn:automation.serverURL
-zh-cn:automation.toolsEnabled
zh-cn:automation.toolsRestartNotice
zh-cn:code.copyJSXReference
-zh-cn:collaboration.clickToFollowPeer
-zh-cn:collaboration.followingPeerStop
zh-cn:collaboration.pasteRoomLinkOrId
zh-cn:commands.paletteDescription
zh-cn:credentials.getAPIKey
-zh-cn:credentials.storage
zh-cn:diagnostics.acpFailed
zh-cn:diagnostics.chatCompleted
zh-cn:diagnostics.chatFailed
@@ -200,24 +170,15 @@ zh-cn:diagnostics.mcpFailed
zh-cn:diagnostics.modelStepCompleted
zh-cn:diagnostics.usageDescription
zh-cn:diagnostics.usageHistoryDescription
-zh-cn:editor.showUI
-zh-cn:editor.toolOptions
zh-cn:files.browserFileAPINotSupported
zh-cn:files.clipboardImageFetchFailed
zh-cn:files.clipboardImagesFetchFailed
-zh-cn:files.clipboardImagesUnavailableWeb
-zh-cn:files.closeTab
zh-cn:files.importFailed
zh-cn:files.importHTMLCSS
zh-cn:files.importHTMLCSSDescription
-zh-cn:files.noMatchingFiles
zh-cn:files.orEdgeForFullSupport
zh-cn:files.useChrome
-zh-cn:fonts.affectedLayerCount
zh-cn:fonts.downloadFallbackPacksDescription
-zh-cn:fonts.issuesFound
-zh-cn:fonts.providerDisabled
-zh-cn:fonts.providerEnabled
zh-cn:media.getPexelsAPIKey
zh-cn:media.getUnsplashAccessKey
zh-cn:media.pexelsAlternativeOptional
@@ -234,23 +195,15 @@ zh-cn:menu.exportSelectionAsFig
zh-cn:menu.exportSelectionAsPNG
zh-cn:menu.exportSelectionAsPPTX
zh-cn:menu.exportSelectionAsSVG
-zh-cn:pages.pageName
-zh-cn:panels.assetVariantSummary
zh-cn:panels.colorHintHsb
zh-cn:panels.colorHintHsl
zh-cn:panels.colorHintOkhcl
-zh-cn:panels.colorPreviewClipped
-zh-cn:panels.createColorVariable
-zh-cn:panels.createNumberVariable
-zh-cn:panels.layersCount
zh-cn:panels.localFontsAccessHint
-zh-cn:panels.missingStyle
zh-cn:panels.sizingFillFr
zh-cn:panels.sizingFixedPx
zh-cn:panels.xAxis
zh-cn:panels.yAxis
zh-cn:recovery.dialogDescription
-zh-cn:rename.layers
zh-cn:rendering.reloadRequired
zh-cn:rendering.settingsDescription
zh-cn:rendering.urlOverride
@@ -262,7 +215,6 @@ zh-cn:storage.copyCors
zh-cn:storage.providerS3
zh-cn:updates.available
zh-cn:updates.availableTitle
-zh-cn:updates.checkFailed
zh-cn:updates.downloading
zh-cn:updates.installed
zh-cn:updates.unavailable
diff --git a/tools/i18n/package.json b/tools/i18n/package.json
index 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.ts
index 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_]*)\}/g
function 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.ts
new file mode 100644
index 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.ts
new file mode 100644
index 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)
+ })
+})