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.

feat(i18n): add i18n support to umd

白熱452effb78928
diff --git a/examples/src/docs/main.ts b/examples/src/docs/main.ts
index 8d4ff1a400..34ecdaaefa 100644
--- a/examples/src/docs/main.ts
+++ b/examples/src/docs/main.ts
@@ -15,7 +15,7 @@
*/
/* eslint-disable node/prefer-global/process */
-import { LocaleType, Univer } from '@univerjs/core';
+import { LocaleType, Univer, UniverInstanceType } from '@univerjs/core';
import { defaultTheme } from '@univerjs/design';
import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
@@ -68,7 +68,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {
univer.registerPlugin(UniverImagePlugin);
-univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
+univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_CN);
// use for console test
declare global {
diff --git a/packages/umd/scripts/index.mjs b/packages/umd/scripts/index.mjs
index 880cc2ce98..b5f7bdf138 100644
--- a/packages/umd/scripts/index.mjs
+++ b/packages/umd/scripts/index.mjs
@@ -31,6 +31,22 @@ const __dirname = path.dirname(__filename);
const nodeModulesPath = path.resolve(__dirname, '../node_modules');
+function generateUMDTemplate(code) {
+ return `(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ define([], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ module.exports = factory();
+ } else {
+ root.UniverUMD = root.UniverUMD || {};
+ Object.assign(root.UniverUMD, factory());
+ }
+}(typeof self !== 'undefined' ? self : this, function () {
+ var exports = ${code};
+ return exports;
+}));`;
+}
+
async function generateLocale() {
const libs = [
'@univerjs/design',
@@ -69,8 +85,11 @@ async function generateLocale() {
const data = fs.readFileSync(file, 'utf-8');
output = lodash.merge(JSON.parse(data), output);
}
+ const result = generateUMDTemplate(`{
+ "${lang}": ${JSON.stringify(output)}
+ }`);
- fs.writeFileSync(path.resolve(outputDir, `${lang}.json`), JSON.stringify(output, null, 2), 'utf-8');
+ fs.writeFileSync(path.resolve(outputDir, `${lang}.js`), result, 'utf-8');
}
};