Internationalization
Using Preset Locales
From version 0.1.13, Univer no longer includes any locales, all locales are provided by plugins. If you find it too cumbersome to manually import the locales required by the plugin, we also provide a build tool plugin that automatically imports the locales required by the plugin. Please refer to Using Univer Plugins for more information.
If you need to manually add locales, you can refer to the following example, import the corresponding locale as needed and assemble it into an object to pass it to the Univer
instance:
import { LocaleType, Tools } from '@univerjs/core';
import DesignEnUS from '@univerjs/design/locale/en-US';
import UIEnUS from '@univerjs/ui/locale/en-US';
import DocsUIEnUS from '@univerjs/docs-ui/locale/en-US';
import SheetsEnUS from '@univerjs/sheets/locale/en-US';
import SheetsUIEnUS from '@univerjs/sheets-ui/locale/en-US';
import SheetsFormulaEnUS from '@univerjs/sheets-formula/locale/en-US';
const univer = new Univer({
theme: defaultTheme,
locale: LocaleType.EN_US,
locales: {
[LocaleType.EN_US]: Tools.deepMerge(
SheetsEnUS,
DocsUIEnUS,
SheetsUIEnUS,
SheetsFormulaEnUS,
UIEnUS,
DesignEnUS,
),
},
});
Univer currently includes the following preset locales:
zh-CN
: Simplified Chineseen-US
: Englishru-RU
: Russian
You need to pay attention to the fact that since Webpack 4 does not support the exports
field of package.json, you may need to modify the path to import the locale.
- import DesignZhCN from '@univerjs/design/locale/zh-CN';
+ import DesignZhCN from '@univerjs/design/lib/locale/zh-CN.json'
If you are using TypeScript, you also need to confirm whether the resolveJsonModule
option is configured in tsconfig.json.
{
"compilerOptions": {
+ "resolveJsonModule": true
}
}
Using Custom Locales
Univer also supports custom locales, you can assemble the locale object according to your needs and pass it to the Univer
instance. The preset locales for reference are generally stored in the <rootDir>/packages/<PLUGIN_NAME>/locale
directory.
const univer = new Univer({
theme: defaultTheme,
locale: 'es-ES',
locales: {
'es-ES': {
shortcut: {
undo: 'Deshacer',
redo: 'Rehacer',
}
},
},
});
Contributing Locales
Univer OSS is an open source project full of inclusiveness, and we welcome developers from all over the world to add or improve locales for Univer. If you are interested in contributing locales to Univer, please refer to the Contribution Guide.