MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
Functions
jq Library dialog alert confirm prompt snackbar getTheme setTheme getColorFromImage setColorScheme removeColorScheme loadLocale setLocale getLocale throttle observeResize breakpoint
Libraries

loadLocale

The loadLocale function loads locale modules. For more details, see Localization.

Usage

Import the function:

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

Here are a few common ways 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 loader function takes a locale code and returns a Promise that resolves to the matching 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