mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-24 06:36:37 +00:00
1.3 KiB
1.3 KiB
WebAppLocalizer
Quick reference for AI-assisted development of the WebAppLocalizer class.
Import
<script src="/lollms_assets/js/web.app.localizer"></script>
Initialization
const localizer = new WebAppLocalizer(translations, localStoragePrefix, languageSelector);
Key Methods
setLanguage(lang)
getCurrentLanguage()
getAvailableLanguages()
translate(key)
apply()
Translations Object Structure
{
[langCode]: {
name: "Language Name",
translations: {
[key]: "Translation"
},
// optional
promptTranslations: {
[prompt name]: "Translation"
}
}
}
HTML Usage
If your translation is plain text, then use:
<element data-translate="key"></element>
If your translation contains html, then add data-translate-html entry:
<element data-translate="key" data-translate-html></element>
Apply translations: localizer.apply();
Get the translation of a prompt with options:
localizer.formatPrompt([prompt name], {
variable name: variable value to substitude in the translation string
})
In the translation string use the syntax {variable name}. This will allow using variable string parts when translating.