Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

build: use regex for locale file name validation

白熱8debc7fa278a
diff --git a/common/shared/locale/index.ts b/common/shared/locale/index.ts
index ce7ddc8999..fb91f25a0b 100644
--- a/common/shared/locale/index.ts
+++ b/common/shared/locale/index.ts
@@ -2,6 +2,8 @@ import { existsSync, readdirSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
+const LOCALE_FILE_NAME_PATTERN = /^[a-z]{2}-[A-Z]{2}\.ts$/;
+
export interface IDiscoverUniverUiLocalesOptions {
rootDir?: string;
uiPackageDir?: string;
@@ -53,7 +55,7 @@ export function discoverUniverUiLocales(options: IDiscoverUniverUiLocalesOptions
}
return readdirSync(localeDir, { withFileTypes: true })
- .filter((entry) => entry.isFile() && entry.name.endsWith('.ts'))
+ .filter((entry) => entry.isFile() && LOCALE_FILE_NAME_PATTERN.test(entry.name))
.map((entry) => path.basename(entry.name, '.ts'))
.sort((left, right) => left.localeCompare(right));
}