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.

fix(umd): fix issue with datepicker localization not working in UMD bundle (#2719)

白熱962e05778e67
diff --git a/packages/umd/scripts/index.mjs b/packages/umd/scripts/index.mjs
index dfdf84bbe0..7ddc9d935c 100644
--- a/packages/umd/scripts/index.mjs
+++ b/packages/umd/scripts/index.mjs
@@ -74,7 +74,17 @@ async function generateLocale() {
'@univerjs/uniscript',
];
- const languages = ['en-US', 'ru-RU', 'zh-CN'];
+ // const languages = ['en-US', 'ru-RU', 'zh-CN'];
+ const languages = [{
+ key: 'en-US',
+ dayjsKey: 'en',
+ }, {
+ key: 'ru-RU',
+ dayjsKey: 'ru',
+ }, {
+ key: 'zh-CN',
+ dayjsKey: 'zh-cn',
+ }];
const outputDir = path.resolve(__dirname, '../lib/locale');
if (!fs.existsSync(outputDir)) {
@@ -84,7 +94,7 @@ async function generateLocale() {
for (const lang of languages) {
let output = {};
for (const lib of libs) {
- const file = path.resolve(nodeModulesPath, lib, `lib/locale/${lang}.json`);
+ const file = path.resolve(nodeModulesPath, lib, `lib/locale/${lang.key}.json`);
if (!fs.existsSync(file)) {
throw new Error(`File not found: ${file}`);
}
@@ -92,11 +102,18 @@ async function generateLocale() {
const data = fs.readFileSync(file, 'utf-8');
output = lodash.merge(JSON.parse(data), output);
}
- const result = generateUMDTemplate(`{
- "${lang}": ${JSON.stringify(output)}
+
+ let result = generateUMDTemplate(`{
+ "${lang.key}": ${JSON.stringify(output)}
}`);
- fs.writeFileSync(path.resolve(outputDir, `${lang}.js`), result, 'utf-8');
+ // append dayjs locale
+ const dayjsFile = path.resolve(nodeModulesPath, 'dayjs/locale', `${lang.dayjsKey}.js`);
+ if (fs.existsSync(dayjsFile)) {
+ result += fs.readFileSync(dayjsFile, 'utf-8');
+ }
+
+ fs.writeFileSync(path.resolve(outputDir, `${lang.key}.js`), result, 'utf-8');
}
};