Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify I18n Language

From Leeroopedia
Knowledge Sources
Domains Frontend, Internationalization
Last Updated 2026-02-12 07:00 GMT

Overview

Central locale type definitions, supported language registry, locale mapping utilities, and static i18n notice content for the Dify frontend.

Description

This module serves as the primary locale configuration hub for the Dify web application. It re-exports the raw language data from languages.ts and builds several derived artifacts on top of it:

  • Locale -- A union type representing all supported locale codes (e.g., 'en-US', 'zh-Hans', 'ja-JP'), including legacy underscore-delimited variants for backward compatibility.
  • LanguagesSupported -- A filtered array of locale codes for languages that have supported: true in the language data.
  • localeMap -- A record that maps Dify locale codes (both hyphenated and underscore variants) to simplified short codes used by external systems (e.g., 'zh-Hans' to 'zh-cn').
  • getLanguage -- Converts hyphenated locale strings to underscore-delimited form for backward compatibility with older APIs.
  • getDocLanguage -- Resolves a locale to a DocLanguage code for linking to the correct documentation version.
  • getPricingPageLanguage -- Returns a language suffix for the Dify pricing page URL.
  • NOTICE_I18N -- A static object containing pre-translated system notice strings (title and description) for all supported locales.
  • I18nText -- A utility type representing a record keyed by all supported locale codes, useful for multilingual text fields in the application.

Usage

Use this module whenever you need to determine which locales the application supports, convert between locale formats, render locale-specific documentation or pricing links, or display static multilingual notice content. It is imported throughout the frontend codebase wherever locale awareness is required.

Code Reference

Source Location

Signature

export type Item = {
  value: number | string
  name: string
  example: string
}

export type I18nText = Record<typeof LanguagesSupported[number], string>

export type Locale = 'ja_JP' | 'zh_Hans' | 'en_US' | (typeof languages[number])['value']

export const LanguagesSupported: Locale[]

export const languages: typeof data.languages

export const localeMap: Record<Locale, string>

export const getLanguage: (locale: Locale) => Locale

export const getDocLanguage: (locale: string) => DocLanguage

export const getPricingPageLanguage: (locale: string) => string

export const NOTICE_I18N: {
  title: Record<string, string>
  desc: Record<string, string>
  href: string
}

Import

import {
  LanguagesSupported,
  localeMap,
  getLanguage,
  getDocLanguage,
  getPricingPageLanguage,
  NOTICE_I18N,
} from '@/i18n-config/language'
import type { Locale, I18nText, Item } from '@/i18n-config/language'

I/O Contract

Inputs

Name Type Required Description
locale (getLanguage) Locale Yes A locale code such as 'zh-Hans' or 'ja-JP' to convert to underscore format.
locale (getDocLanguage) string Yes A locale code to resolve to a documentation language ('zh', 'ja', or 'en').
locale (getPricingPageLanguage) string Yes A locale code to resolve to a pricing page language suffix.

Outputs

Name Type Description
LanguagesSupported Locale[] Array of all locale codes marked as supported.
localeMap Record<Locale, string> Mapping from Dify locale codes to simplified short codes.
getLanguage result Locale The locale code with hyphens replaced by underscores; defaults to the first supported locale if no match.
getDocLanguage result DocLanguage A short language code for documentation links; defaults to 'en'.
getPricingPageLanguage result string A language suffix for pricing page URLs; empty string if no override exists.

Usage Examples

Get Supported Locales

import { LanguagesSupported } from '@/i18n-config/language'

// Returns all locale codes with supported: true
console.log(LanguagesSupported)
// ['en-US', 'zh-Hans', 'zh-Hant', 'pt-BR', 'es-ES', 'fr-FR', ...]

Resolve Documentation Language

import { getDocLanguage } from '@/i18n-config/language'

const docLang = getDocLanguage('zh-Hans') // 'zh'
const docLangDefault = getDocLanguage('ko-KR') // 'en'

Map Locale to Short Code

import { localeMap } from '@/i18n-config/language'

const shortCode = localeMap['zh-Hans'] // 'zh-cn'
const shortCodeJa = localeMap['ja-JP'] // 'ja'

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment