getLanguage
Category: Application Control
Namespace: web.app.getLanguage
Description
Get the current language of the application. Returns the language that was actually loaded at startup — either the user's selection (if the app is configured for multilingual mode) or the project's default language.
In multilingual mode (Builder setting: "All Languages = True"), the user is prompted to choose a language on first launch, and their choice is remembered. This method returns that saved choice.
In single language mode, it returns the project's configured target language.
Syntax
const language = await web.app.getLanguage();
Parameters
None
Returns
Promise<string> - The language name as a string (e.g., "English", "Spanish", "French", "German")
Example
Simple example
const lang = await web.app.getLanguage();
console.log('App language:', lang);
Practical example — set page language attribute
const lang = await web.app.getLanguage();
const langMap = {
'English': 'en',
'Spanish': 'es',
'French': 'fr',
'German': 'de',
'Portuguese': 'pt',
'Italian': 'it',
'Japanese': 'ja',
'Chinese': 'zh',
'Korean': 'ko',
'Russian': 'ru'
};
document.documentElement.lang = langMap[lang] || 'en';
Advanced example — load translation strings
async function initLocalization() {
const lang = await web.app.getLanguage();
const translations = {
'English': {
greeting: 'Welcome',
save: 'Save',
cancel: 'Cancel',
confirm: 'Are you sure?'
},
'Spanish': {
greeting: 'Bienvenido',
save: 'Guardar',
cancel: 'Cancelar',
confirm: '¿Estás seguro?'
},
'French': {
greeting: 'Bienvenue',
save: 'Enregistrer',
cancel: 'Annuler',
confirm: 'Êtes-vous sûr?'
}
};
// Fall back to English if language not in our translations
const t = translations[lang] || translations['English'];
// Apply translations to UI
document.getElementById('greeting').textContent = t.greeting;
document.getElementById('btn-save').textContent = t.save;
document.getElementById('btn-cancel').textContent = t.cancel;
}
document.addEventListener('DOMContentLoaded', initLocalization);
Use Cases
- Set the
langattribute on<html>for accessibility and SEO - Load the correct translation strings for the UI
- Format dates, numbers, and currency based on locale
- Display language-specific content or instructions
- Choose the right help documentation to show
- Adjust text direction (LTR/RTL) based on language
- Log the user's language for analytics
Error Handling
Falls back to "English" if the language cannot be determined.
const lang = await web.app.getLanguage();
// Always returns a string — never null or undefined
console.log('Language:', lang);
Performance Tips
- Call at startup to initialize your UI language
- The user can change the language at runtime via the tray menu — if your app needs to react to that, call
getLanguage()again after a page reload or at key moments
let appLanguage = 'English';
document.addEventListener('DOMContentLoaded', async () => {
appLanguage = await web.app.getLanguage();
applyTranslations(appLanguage);
});
Related Methods
web.app.getCmdArgs()- Get command line argumentsweb.app.licensed()- Check if licensedweb.app.packageName()- Get license package name
Notes
- In multilingual apps, the user's language choice is stored in the Windows registry and persists across sessions
- The user can change their language at runtime via the tray menu Language item (if multilingual mode is enabled) —
getLanguage()returns the language at the time of the call - Language names match the resource names configured in the Builder (e.g., "English", "Spanish", not ISO codes like "en", "es")
- If you need ISO language codes, create a mapping from the language name (see practical example above)