Official Content

Sets the language to display the texts and messages in your application.      

Syntax

SetLanguage(LanguageObjectName)

Where:

LanguageObjectName
            
Name of the Language object defined in your Knowledge Base to be used for the translation.

Scope

Objects: ProcedureTransactionWeb PanelPanelData Provider
Generators: .NET, .NET Framework, JavaApple, Android, Angular

Description

The SetLanguage function is used when the Translation type property is set to 'Run-time'. 

You have to use this function in your code to indicate the language to be used.

It returns 0 if the Language can be changed. Otherwise, it returns a non-zero value. If the specified Language cannot be loaded, then no language change is performed and the current Language remains as if the method had not been executed.

Once the SetLanguage function has been executed successfully, the Language setting remains active for the rest of the session. In Web applications, this means that the GeneXus code automatically saves the value of the current language in the current session.

Notes:

  • For Web applications: To refresh all the texts and language-dependant elements of the web page, a Refresh command should be added after the SetLanguage function. This Refresh command will make a GET of the web page (a different behavior than if the Refresh command is not used after the SetLanguage function). Read SAC #24129. Remember that making a GET of the web page implies that values entered in editable fields will be lost.

    Browsers running GeneXus applications using Design Systems require support for the 'dir' attribute (HTML attribute: dir,  CSS Logical Properties). Read SAC #52783.
  • For Mobile applications: This function is available from GeneXus X Evolution 3 Upgrade 9 onwards. It's recommended to use the GoHome Method of the Actions external object after changing the language to "refresh" the previously loaded Panel objects. For it to work, the Environment's Translation type property must be set to 'Run-time'. Otherwise, a non-zero value will be returned when the function is used. In Android, messages like: "set Language to : LanguageId" / "set Language failed. Language LanguageId not found in catalog." appear when debugging (monitor.bat).
     
  • For GeneXus X Evolution 2, .NET: SetLanguage(&MyLanguage) does not always work. However, SetLanguage(!'Spanish') or SetLanguage(!'English) does. Therefore, type the Language Name instead of using variables if you have problems with the sample code below.

Samples

Event &MyLanguage.Click
   If SetLanguage(&MyLanguage)<>0
      msg("It was not possible to set the language " + &MyLanguage)
   EndIf
EndEvent

Event &MyLanguage.Click
   &NumericVariable = SetLanguage(!"Spanish")
EndEvent

See Also

GetLanguage function
GeneXus Application Localization

  

Last update: March 2025 | © GeneXus. All rights reserved. GeneXus Powered by Globant