# Themes and localization

> Align editor appearance, dark mode, and language resources with your application.

- Human documentation: [https://docs.univer.ai/overview/features/shared/themes-and-locales](https://docs.univer.ai/overview/features/shared/themes-and-locales)

- Agent Markdown: [https://docs.univer.ai/overview/features/shared/themes-and-locales.md](https://docs.univer.ai/overview/features/shared/themes-and-locales.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.6.1`

- Source: [features/shared/themes-and-locales.mdx](https://github.com/dream-num/documentation/blob/dev/content/docs/features/shared/themes-and-locales.mdx)

---

Themes and internationalization are shared runtime services. All six products use the same theme service, locale resources, and regional configuration, and custom plugins can observe the same state. Brand appearance and user preferences can change while the application is running, without affecting the data and styles stored with the content.

The SDK includes **[19 built-in interface language and region options](#supported-locales)** and **7 theme palettes**. All six products share the appearance, locale, and region configuration, and custom themes and application translations use the same services.

## One state model for UI and rendering

`ThemeService` stores the complete palette and the dark-mode state separately, and publishes changes through `currentTheme$` and `darkMode$`. The UI expands the palette into `--univer-*` CSS variables and responds to the `univer-dark` class. Renderers subscribe to the same service and mark the affected components for repaint. The Canvas color service resolves tokens, maps colors for dark display, and caches the results.

The configuration and examples in this chapter apply to `@univerjs/*` and `@univerjs-pro/*` **1.2.0**. Keep the SDK dependency versions aligned in your application.

| Setting | Options and scope | Runtime API |
| --- | --- | --- |
| `theme` | 7 built-in palettes, or a complete custom `Theme`. | `setTheme()` |
| `darkMode` | `true` / `false`, default `false`; independent of the palette. | `toggleDarkMode()` |
| `locale` | 19 built-in `LocaleType` values; load the matching resources first. | `setLocale()` |
| `locales` | Product, feature, and application resources combined by locale identifier. | `loadLocales()` |
| `region` | The same `LocaleType` values; follows the UI locale until it is set explicitly. | `setRegion()` |
| `direction` | `ltr` / `rtl`, default `ltr`; applies to menus and similar UI only. Canvas content does not support RTL yet. | `setDirection()` |

```mermaid
flowchart LR
A["Application / Facade"] --> B["ThemeService<br/>Palette + dark mode"]
B --> C["UI<br/>CSS variables and dark class"]
B --> D["Renderer<br/>Repaint and color mapping"]
C --> E["Six products and custom extensions"]
D --> E
```

## Build a brand theme from a complete palette

`@univerjs/themes` provides `primary`, `gray`, the functional color scales, `loop-color`, and `highlight.background`. Copy a built-in theme, replace the branches that require changes, and keep the structure complete. `setTheme()` replaces an entire theme; it does not deep-fill a partial object. The example below provides a continuous violet brand scale.

The 7 built-in palettes are `blueTheme`, `darkBlueTheme`, `greenTheme`, `orangeTheme`, `purpleTheme`, `redTheme`, and `yellowTheme`.

`defaultTheme` is an alias of `blueTheme`. The palette and the dark-mode state are selected separately. The configurable branches are as follows:

| Theme branch | Configurable options |
| --- | --- |
| `primary` | **10 brand steps**: `50`, then `100` through `900`. |
| `gray` | **12 neutral steps**: `0`, `50`, `100` through `900`, and `1000`. |
| `blue` · `red` · `orange` · `yellow` · `green` · `jiqing` · `indigo` · `purple` · `pink` | **9 functional scales**, with 10 steps each. |
| `loop-color` | **12** rotating color positions that reference palette tokens. |
| `highlight.background` | **16** background highlight positions, each with `color` and `alpha`. |

```typescript title="brand-theme.ts"
import type { Theme } from '@univerjs/themes';
import { defaultTheme } from '@univerjs/themes';

export const brandTheme: Theme = {
  ...defaultTheme,
  primary: {
    ...defaultTheme.primary,
    50: '#F5F3FF', 100: '#EDE9FE', 200: '#DDD6FE', 300: '#C4B5FD',
    400: '#A78BFA', 500: '#8B5CF6', 600: '#7C3AED', 700: '#6D28D9',
    800: '#5B21B6', 900: '#4C1D95',
  },
};
```

Pass the theme to the product integration you selected. This example uses the Sheet core preset (`UniverSheetsCorePreset`) and registers translation keys owned by the application; other products use their own plugin composition. The preset accepts the following options:

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `container` | `string \| HTMLElement` | `'app'` | Mount element or its DOM ID. |

```typescript title="setup.ts"
import { LocaleType, mergeLocales } from '@univerjs/core';
import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core';
import SheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US';
import { createUniver } from '@univerjs/presets';
import { brandTheme } from './brand-theme';
import '@univerjs/preset-sheets-core/lib/index.css';

export const { univer, univerAPI } = createUniver({
  theme: brandTheme,
  darkMode: false,
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: mergeLocales(SheetsCoreEnUS, {
      'sales-report': { generate: 'Generate report', ready: 'Ready for {0}' },
    }),
  },
  presets: [UniverSheetsCorePreset({ container: 'app' })],
});
```

- [Open the theme builder](/tools/theme-customizer)
  The theme builder supports editing palettes, loop colors, and highlights; switching between light and dark mode; previewing against real Sheet and Doc hosts; and copying Theme JSON or integration code. Sheet and Doc are the two preview hosts currently available, and the complete application theme also works with the other products.

## Change appearance at runtime and follow preferences

`setTheme()` changes the palette, and `toggleDarkMode()` changes the dark-mode state. `getCurrentTheme()` and `isDarkMode()` read the current values. Switching to `darkBlueTheme` alone does not enable the dark-mode flag. Changing the appearance does not require destroying and recreating the editor.

The function below follows the system preference and returns a cleanup function. If the application provides a manual appearance setting, call `toggleDarkMode()` from the handler for that setting instead.

```typescript title="appearance.ts"
import type { FUniver } from '@univerjs/core/facade';
import { brandTheme } from './brand-theme';

export function followSystemAppearance(univerAPI: FUniver): () => void {
  univerAPI.setTheme(brandTheme);
  const preference = window.matchMedia('(prefers-color-scheme: dark)');
  const update = () => univerAPI.toggleDarkMode(preference.matches);
  update();
  preference.addEventListener('change', update);
  return () => preference.removeEventListener('change', update);
}
```

Call the function after the editor has been set up, and run the returned cleanup function when the component unmounts or stops following the system. In React and similar integrations, retain the existing instance and update it through Facade.

## Make custom plugins follow theme and language

Custom DOM uses the injected CSS variables and provides its own styles for the dark class. The variables contain palette values, so the component must still apply the dark-mode state itself.

```css title="report-panel.css"
.report-panel {
  color: var(--univer-gray-900);
  background: var(--univer-gray-0);
  border: 1px solid var(--univer-gray-200);
}

.univer-dark .report-panel {
  color: var(--univer-gray-100);
  background: var(--univer-gray-800);
  border-color: var(--univer-gray-700);
}
```

Canvas extensions read live tokens through `ThemeService` and obtain the colors used for drawing from `ICanvasColorService`. The example below combines theme, dark-mode, and locale changes into a single observable state. It translates labels and resolves colors when the state changes, so no lookup or allocation is repeated on every drawing frame.

```typescript title="report-appearance.ts"
import { Disposable, Inject, LocaleService, ThemeService, toDisposable } from '@univerjs/core';
import { ICanvasColorService } from '@univerjs/engine-render';
import { combineLatest, ReplaySubject } from 'rxjs';

export interface IReportAppearance {
  label: string;
  accent: string;
}

export class ReportAppearance extends Disposable {
  readonly state$ = new ReplaySubject<IReportAppearance>(1);

  constructor(
    @Inject(ThemeService) theme: ThemeService,
    @Inject(LocaleService) locale: LocaleService,
    @ICanvasColorService colors: ICanvasColorService,
  ) {
    super();
    this.disposeWithMe(toDisposable(() => this.state$.complete()));
    this.disposeWithMe(combineLatest([
      theme.currentTheme$, theme.darkMode$, locale.currentLocale$,
    ]).subscribe(() => {
      this.state$.next({
        label: locale.t('sales-report.generate'),
        accent: colors.getRenderColor(theme.getColorFromTheme('primary.600')),
      });
    }));
  }
}
```

Register `ReportAppearance` through DI and resolve it in the plugin. The view or drawing controller subscribes to `state$` and refreshes. The consumer owns the subscription, and the service owner calls `dispose()`. Node.js also provides theme and locale services, but it does not inject browser CSS.

## Dark mode

Sheet, Doc, Slide, Relational Table, Canvases, and PDF all use the shared theme and dark mode. The screenshots below were taken from the local standard demos, whose UI and content are in English. Dark display does not write the mapped colors back into the Snapshot. Application appearance and PDF page processing are separate concerns; the result of local PDF verification is described below.

| Product | Shared theme | Dark mode | Interface i18n |
| --- | --- | --- | --- |
| Sheet | ✓ | ✓ | ✓ |
| Doc | ✓ | ✓ | ✓ |
| Slide | ✓ | ✓ | ✓ |
| Relational Table | ✓ | ✓ | ✓ |
| Canvases | ✓ | ✓ | ✓ |
| PDF | ✓ | UI supported; content display issue | ✓ |

#### Sheet

![Sheet order table and toolbar in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/sheet-dark.jpg)

#### Doc

![Doc editor with English content in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/doc-dark.jpg)

#### Slide

![Slide presentation with an English title in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/slide-dark.jpg)

#### Relational Table

![Relational Table records in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/base-dark.jpg)

#### Canvases

![Canvases in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/board-dark.jpg)

#### PDF

![PDF editor UI in dark mode](https://raw.githubusercontent.com/dream-num/documentation/dev/public/assets/features/themes/pdf-dark.jpg)

> [!WARNING]
> The current local standard demo has a text-visibility issue with PDF content in dark mode; light mode displays correctly. This screenshot shows the editor UI in dark mode. Dark-mode support for PDF content still requires correction and verification.

Language coverage depends on the resource bundles provided by the selected products and the installed features. An application palette does not register products, load locales, or import stylesheets.

## 19 built-in language and region options

`LocaleType` provides the following 19 options, including the Simplified, Traditional, and Hong Kong Traditional Chinese variants. The main UI packages of all six products include these resources; coverage in extensions depends on the package selected. Bundle tags are used in import paths, and the matching enum values are used in initialization and Facade configuration.

> [!WARNING]
> **RTL scope:** Arabic (`ar-SA`) and other locale bundles translate interface text such as menus and messages. `direction: 'rtl'` currently adapts menus and similar UI only. **RTL layout and editing in the Canvas content area have not been implemented.**

| Language (native name) | Bundle tag | Configuration value |
| --- | --- | --- |
| English | `en-US` | `LocaleType.EN_US` |
| 简体中文 | `zh-CN` | `LocaleType.ZH_CN` |
| 繁體中文 | `zh-TW` | `LocaleType.ZH_TW` |
| 繁體中文（香港） | `zh-HK` | `LocaleType.ZH_HK` |
| 日本語 | `ja-JP` | `LocaleType.JA_JP` |
| 한국어 | `ko-KR` | `LocaleType.KO_KR` |
| Tiếng Việt | `vi-VN` | `LocaleType.VI_VN` |
| Bahasa Indonesia | `id-ID` | `LocaleType.ID_ID` |
| Français | `fr-FR` | `LocaleType.FR_FR` |
| Deutsch | `de-DE` | `LocaleType.DE_DE` |
| Español | `es-ES` | `LocaleType.ES_ES` |
| Català | `ca-ES` | `LocaleType.CA_ES` |
| Italiano | `it-IT` | `LocaleType.IT_IT` |
| Português (Brasil) | `pt-BR` | `LocaleType.PT_BR` |
| Polski | `pl-PL` | `LocaleType.PL_PL` |
| Slovenčina | `sk-SK` | `LocaleType.SK_SK` |
| Русский | `ru-RU` | `LocaleType.RU_RU` |
| فارسی | `fa-IR` | `LocaleType.FA_IR` |
| العربية | `ar-SA` | `LocaleType.AR_SA` |

**Internationalization across products:** In the current 1.2.0 source, **92 modules** in the Web SDK and Pro editors provide **1,751 locale entry files** for shared UI, product editors, and features such as formulas, number formats, and comments. Each module maintains and publishes its own resources, and the application combines the features it enables with the locales it targets.

The count covers the locale entry `.ts` files under `packages/*/src/locale` in both source trees, excluding tests and generated subdirectories. It does not mean that every module covers all 19 options. Some modules include additional languages; [`LocaleType`](https://docs.univer.ai/reference/enums/locale-type.md) defines the common built-in set.

## Compose locale resources by plugin, then load and select

`LocaleService` organizes resources by locale and resolves labels through namespaces and key paths. `mergeLocales()` combines product presets, feature plugins, and application translations. `loadLocales()` merges resources at runtime, and `setLocale()` selects the language. Selecting a locale does not download its bundle.

```mermaid
flowchart LR
A["Product / feature / application bundles"] --> B["mergeLocales / loadLocales"] --> C["LocaleService<br/>Namespace lookup"] --> D["Menus, messages, and plugin labels"]
```

The following example adds Chinese resources to the Sheet instance introduced earlier, switches the UI to Chinese, and explicitly retains German regional conventions. `LocaleType.ZH_CN` has the value `zhCN`; `zh-CN` is the form used in bundle filenames and documentation routes.

```typescript title="locales.ts"
import type { FUniver } from '@univerjs/core/facade';
import { LocaleType, mergeLocales } from '@univerjs/core';
import SheetsCoreZhCN from '@univerjs/preset-sheets-core/locales/zh-CN';

export function switchInterface(univerAPI: FUniver): void {
  univerAPI.loadLocales(LocaleType.ZH_CN, mergeLocales(SheetsCoreZhCN, {
    'sales-report': { generate: '生成报告', ready: '已为 {0} 就绪' },
  }));
  univerAPI.setLocale(LocaleType.ZH_CN);
  univerAPI.setRegion(LocaleType.DE_DE);
  univerAPI.setDirection('ltr');
}
```

Keys such as `sales-report.generate` belong to the plugin that owns them. Write complete translated sentences and use `{0}`, `{1}` placeholders for dynamic values, as in `LocaleService.t('sales-report.ready', 'Alex')`. Do not cache translations at module initialization. After resources have been initialized, a missing key currently falls back to the key itself. Switching the interface language does not translate content or rename existing Units.

## Distinguish language, region, and content formatting

| Layer | Actual effect |
| --- | --- |
| Interface `locale` | Menus, messages, plugin labels, and some language-dependent behavior such as document segmentation. |
| `region` | Currency actions that use this setting, comment date/time display, and statistics formatting; no currency conversion or timestamp changes. |
| Content number formats | Saved Sheet number/date formats follow cell formats and the content locale that applies to them; changing the region does not rewrite them all. |
| `direction` | Independent UI direction; changing the language or region does not switch it automatically. |

When no region is specified, the corresponding default applies. Once the region is set explicitly, it can be selected independently of the interface language. `region` is not a timezone setting. RTL currently adapts menus and similar UI only, and right-to-left layout and editing in the Canvas content area have not been implemented.

## Content themes and application themes have separate boundaries

The application theme controls the workbench and the rendering defaults. It does not rewrite persisted cell fills, text, shapes, PDF annotations, or explicit Chart colors. Range and table themes, Slide color schemes, and Canvases content themes are managed through the corresponding public product capabilities.

Pro Charts use a separate `IEchartTheme` registry shared by Sheet, Doc, Slide, and Canvases Charts. An application `Theme` is not a Chart theme. In a host with the appropriate Chart plugins installed, import the Chart Facade and register a complete definition:

```typescript title="chart-theme.ts"
import type { IEchartTheme } from '@univerjs-pro/engine-chart';
import type { FUniver } from '@univerjs/core/facade';
import { UniverTheme1 } from '@univerjs-pro/engine-chart';
import '@univerjs-pro/engine-chart/facade';

export function registerBrandChartTheme(univerAPI: FUniver): void {
  const chartTheme: IEchartTheme = {
    ...UniverTheme1,
    themeName: 'sales-brand',
    theme: {
      ...UniverTheme1.theme,
      color: ['#7C3AED', '#0EA5E9', '#10B981', '#F59E0B'],
    },
  };
  univerAPI.registerTheme('sales-brand', chartTheme);
}
```

Select the registered name through the Chart builder's `setTheme('sales-brand')`. A Chart palette that is set explicitly may override the series colors.

Appearance must be consistent within one browser document, because the current UI variables and the `univer-dark` class are written to the document root. Multiple editors should share one appearance or use separate documents such as iframes; separate containers alone do not isolate CSS themes.

Further reading: [Themes and dark mode](https://docs.univer.ai/guides/fundamentals/ui/themes.md) · [Detailed i18n configuration](https://docs.univer.ai/guides/sheets/getting-started/i18n.md) · [Plugins and Facade](https://docs.univer.ai/overview/features/shared/customization.md) · [Charts](https://docs.univer.ai/overview/features/charts.md)

[Back to feature overview](https://docs.univer.ai/overview/features.md)
