MDUIDocsEnglish简体中文LightDarkSystem
Preset Colors
Custom Color
Extract Color from Wallpaper
Select a Wallpaper
Getting Started
Styles
Frameworks
Components
Functions
JavaScript Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

loadLocale

The loadLocale function is used to load locale modules. For more details, refer to Localization.

Usage

Import the function:

import { loadLocale } from 'mdui/functions/loadLocale.js';

Here are a few common patterns to load locale modules. For detailed explanations, see Localization.

Dynamic import (Lazy-load):

loadLocale((locale) => import(`../node_modules/mdui/locales/${locale}.js`));

Dynamic import (Pre-load):

const localizedTemplates = new Map([
  ['zh-cn', import(`../node_modules/mdui/locales/zh-cn.js`)],
  ['zh-tw', import(`../node_modules/mdui/locales/zh-tw.js`)]
]);

loadLocale(async (locale) => localizedTemplates.get(locale));

Static imports:

import * as locale_zh_cn from 'mdui/locales/zh-cn.js';
import * as locale_zh_tw from 'mdui/locales/zh-tw.js';

const localizedTemplates = new Map([
  ['zh-cn', locale_zh_cn],
  ['zh-tw', locale_zh_tw]
]);

loadLocale(async (locale) => localizedTemplates.get(locale));

API

loadLocale((LocaleTargetCode) => Promise<LocaleModule>): void;

This function accepts a function that defines how to load the locale modules. The locale modules loading function takes a locale code as an argument and returns a Promise that resolves to the corresponding locale module.

Refer to Supported Languages for a list of locale codes. en-us is the built-in locale module and does not need to be loaded.

On this page