[Overview][Classes][Procedures and functions][Index] | Reference for unit 'LCLTranslator' (#lcl)

# SetDefaultLang

Sets the default language used for string translations.

## Declaration

Source position: lcltranslator.pas line 83

`function SetDefaultLang(`
`Lang: string;`
`Dir: string = '';`
`LocaleFileName: string = '';`
`ForceUpdate: Boolean = True`
`):string;`

## Arguments

`Lang` |  | Language ID requested for translated strings, or '' to use the system default.
`Dir` |  | Directory with the localization files, or '' to use the predefined directories.
`LocaleFileName` |  | Base name for the localization file, or '' to use the base name for the executable file.
`ForceUpdate` |  | Indicates if the UI should be updated immediately.

## Function result

Language code used for the translation, or an empty string when a language code is not available or an error occurs.

## Description

SetDefaultLang is a procedure used to the set the default language used for string translations.

Lang contains the Language identifier used to translate strings. Lang contains a value as defined in ISO 639, at:

ISO 639 - Codes for the Representation of Names of Languages

The default value for the parameter is an empty string (''), and indicates that the default language identifier for the system should be used. This value can be passed as a command line argument (like '--lang ru' or '--lang=es'). The value also can be overridden using the LANG environment variable. The fallback value is the language identifier for the platform. For Windows, this is the language code and country code from GetLocaleInfo in a format like 'en_US' or 'zh_CN'. For other platforms, the value from either the LC_ALL or LC_MESSAGE environment variables is used as the fallback.

Dir contains the name of the directory where .po or .mo localization files are stored, like 'mylng'. The default value is an empty string (''), and indicates that the predefined directories like 'languages' or 'locale' are used to find the localization files for the translation.

LocaleFileName contains the base name for the localization file used to translate string values, like 'lazaruside' or 'debuggerstrconst'. The default value for the argument is an empty string ('') and causes the base name for the application executable to be used, like 'project1' for 'project1.exe'.

When combined with the language identifier and the '.po' or '.mo' file extension, it forms the complete file name with the localized string values. For example: 'lazaruside.ru.po', 'debuggerstrconst.zh_CN.po', or 'project1.es.po'. The value in the Dir argument is prepended to form the complete path to the localization file.

ForceUpdate indicates if an immediate update to the user interface is performed when translations are loaded. Set ForceUpdate to False when SetDefaultLang is called from the initialization section in a unit. The default value is True.

SetDefaultLang ensures that the language ID / locale codes are valid, and .po or .mo files exist with the specified values before they are applied. SetDefaultLang calls the FindLocaleFileName function to get the file name used for translation resources. .po files are applied when they exist. Otherwise, .mo file are used to get the translated string values. LCL resource string constants are also translated using TranslateLCLResourceStrings when a localization file is found with the specified values.

When ForceUpdate contains True, string properties used in Forms, Data Modules, Controls, Components and Persistent objects are translated. This action is performed for members with RTTI (Run Time Type Information) which include a setter (write access) procedure. TUpdateTranslator is used to perform the update to user interface elements.

## See also

TranslateLCLResourceStrings |  | Translates resource strings in LCLStrConsts.pas using localization files for the specified language.
TPOTranslator |  | Performs string translations using a .po (Portable Object) file.
TDefaultTranslator |  | Performs string translations using a .mo file (Machine Object).
TUpdateTranslator |  | Performs string translations for persistent objects.