Implementation:Hiyouga LLaMA Factory WebUI Locales
| Knowledge Sources | |
|---|---|
| Domains | Web UI, Internationalization |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
Multilingual localization module containing all UI labels, tooltips, and alert messages for the LLaMA-Factory WebUI across five languages (English, Russian, Chinese, Korean, Japanese).
Description
locales.py defines two large dictionary constants that provide complete internationalization (i18n) support for the WebUI:
- LOCALES: A nested dictionary mapping each UI element name to per-language Gradio component properties. Each entry has the structure:
- Top-level key: element identifier (e.g., "model_name", "learning_rate", "training_stage")
- Second-level key: language code ("en", "ru", "zh", "ko", "ja")
- Third-level keys: Gradio component properties ("label", "info", "value") containing the localized strings
- Example: LOCALES["model_name"]["en"]["label"] returns "Model name"
- The dictionary covers every UI element across all tabs: model selection, training configuration, evaluation, chat interface, export settings, and more.
- ALERTS: A simpler nested dictionary mapping alert/status message keys to per-language message strings. Keys include:
- Error messages: "err_conflict", "err_no_model", "err_no_path", "err_no_dataset", "err_demo", "err_no_output_dir", "err_json_schema", "err_no_reward_model", "err_failed", "err_config_not_found"
- Warning messages: "warn_no_cuda", "warn_output_dir_exists"
- Info messages: "info_aborting", "info_aborted", "info_finished", "info_config_saved", "info_config_loaded", "info_loading", "info_unloading", "info_loaded", "info_unloaded", "info_thinking", "info_thought", "info_exporting", "info_exported", "info_swanlab_link"
The module supports dynamic language switching, where the WebUI reads the current language selection and retrieves the corresponding localized strings at runtime.
Usage
This module is imported by all WebUI components that need to display localized text. The Runner class uses ALERTS for error and status messages, while the UI construction functions use LOCALES for element labels and tooltips. Language switching triggers a re-read of these dictionaries with the new language code.
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/webui/locales.py
- Lines: 1-3183
Signature
LOCALES: dict[str, dict[str, dict[str, str]]] = {
"title": {"en": {"value": "..."}, "ru": {...}, "zh": {...}, "ko": {...}, "ja": {...}},
"model_name": {"en": {"label": "Model name", "info": "..."}, ...},
# ... hundreds of UI element entries
}
ALERTS: dict[str, dict[str, str]] = {
"err_conflict": {"en": "...", "ru": "...", "zh": "...", "ko": "...", "ja": "..."},
"info_finished": {"en": "Finished.", "ru": "...", "zh": "...", "ko": "...", "ja": "..."},
# ... error, warning, and info message entries
}
Import
from llamafactory.webui.locales import LOCALES, ALERTS
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | -- | -- | This module exports constants only; no function inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| LOCALES | dict[str, dict[str, dict[str, str]]] | Nested dictionary: element_name -> language_code -> property_name -> localized_string. Properties include "label", "info", and "value" for Gradio components |
| ALERTS | dict[str, dict[str, str]] | Nested dictionary: alert_key -> language_code -> localized_message_string. Used for error messages, warnings, and status notifications |
Usage Examples
from llamafactory.webui.locales import LOCALES, ALERTS
# Get the English label for the model_name element
label = LOCALES["model_name"]["en"]["label"] # "Model name"
info = LOCALES["model_name"]["en"]["info"] # "Input the initial name to search for the model."
# Get a localized error message
error_msg = ALERTS["err_no_model"]["zh"] # Chinese error message for missing model
# Get the output box default value for a language
default_value = LOCALES["output_box"]["en"]["value"]
# Dynamic language switching
lang = "ja" # Japanese
title = LOCALES["title"][lang]["value"]
finished_msg = ALERTS["info_finished"][lang]
Related Pages
- Hiyouga_LLaMA_Factory_WebUI_Train_Component - Training tab that uses LOCALES for all element labels
- Hiyouga_LLaMA_Factory_WebUI_Runner - Runner that uses ALERTS for status and error messages