GuidesUniver SheetsGet StartedInternationalization

Internationalization

Presets Installation

Each Preset provides a corresponding locale, import the locale corresponding to the Preset you are using:

import { createUniver, defaultTheme, LocaleType, Tools } from '@univerjs/presets';
import { UniverSheetsAdvancedPreset } from '@univerjs/presets/preset-sheets-advanced';
import UniverPresetSheetsAdvancedEnUS from '@univerjs/presets/preset-sheets-advanced/locales/en-US';
import { UniverSheetsCorePreset } from '@univerjs/presets/preset-sheets-core';
import UniverPresetSheetsCoreEnUS from '@univerjs/presets/preset-sheets-core/locales/en-US';
 
const { univerAPI } = createUniver({
  locale: LocaleType.EN_US,
  locales: {
    enUS: Tools.deepMerge(
      {},
      UniverPresetSheetsCoreEnUS,
      UniverPresetSheetsAdvancedEnUS,
    ),
  },
  theme: defaultTheme,
  presets: [
    UniverSheetsCorePreset(),
    UniverSheetsAdvancedPreset(),
  ],
});

Advance Installation

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 SheetsFormulaUIEnUS from '@univerjs/sheets-formula-ui/locale/en-US';
 
const univer = new Univer({
  theme: defaultTheme,
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: Tools.deepMerge(
      SheetsEnUS,
      DocsUIEnUS,
      SheetsUIEnUS,
      SheetsFormulaUIEnUS,
      UIEnUS,
      DesignEnUS,
    ),
  },
});

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 DesignEnUS from '@univerjs/design/locale/en-US';
+ import DesignEnUS from '@univerjs/design/lib/locale/en-US.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 Translations

Now, Univer includes the following preset locales:

  • zh-CN: Simplified Chinese
  • en-US: English
  • zh-TW: Traditional Chinese
  • ru-RU: Russian
  • vi-VN: Vietnamese
  • fa_IR: Persian

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.