aqEnvironment.SetLocaleInfo Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The SetLocaleInfo method allows you to change parameters of system and user locales, for example, regional and language options specified in the Control Panel. To obtain the current values of locale parameters, use the GetLocaleInfo method.

The SetLocaleInfo method is a wrapper over the Windows API function of the same name. For more information on how to use this method, see the description of the SetLocaleInfo function in the MSDN library.

Declaration

aqEnvironment.SetLocaleInfo(Locale, Type, Data)

Locale [in]    Required    Integer    
Type [in]    Required    Integer    
Data [in]    Required    String    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Locale

Identifier of the locale whose parameter you want to change. This parameter supports the LOCALE_NNN locale identifier constants defined in the Win32API object. For example, LOCALE_USER_DEFAULT stands for the user’s default locale.

For a list of the supported locale identifier constants, see the description of the Locale parameter in the article about the GetLocaleInfo function in the MSDN library.

Type

The identifier of the locale’s parameter that you want to change. This parameter can be one of the LOCALE_NNN locale information constants defined in the Win32API object. For example, LOCALE_SDECIMAL stands for the decimal separator in numbers.

For a full list of the supported constants, see the section “Constants Used in the LCType Parameter of GetLocaleInfo, GetLocaleInfoEx, and SetLocaleInfo” in the Locale Information Constants article of the MSDN library.

Data

A string that holds the parameter value. For valid parameter values, see the description of the appropriate locale information constant in MSDN.

Result Value

True, if the specified locale parameter has been changed successfully; otherwise False.

Example

The following example demonstrates how you can change the number display settings that are specified in the Regional and Language Options in the Control Panel:

JavaScript, JScript

function SetLocaleInfoSample()
{
  var number = 0.7;

  // Remember default number settings
  var ds = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL);
  var lz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO);

  // Log a number using default settings
  Log.Message( FloatToStr(number) );

  // Log a number using a different decimal separator
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ",");
  Log.Message( FloatToStr(number) );

  // Log a number without the leading zero
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, "0");
  Log.Message( FloatToStr(number) );

  // Restore original settings
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ds);
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, lz);
}

/*
The routine produces the following output for US English locale:

 0.7
 0,7
 ,7
*/

Python

def SetLocaleInfoSample():
  number = 0.7
  # Remember default number settings 
  ds = aqEnvironment.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL)
  lz = aqEnvironment.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO)
  # Log a number using default settings 
  Log.Message(FloatToStr(number))
  # Log a number using a different decimal separator 
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ",")
  Log.Message(FloatToStr(number))
  # Log a number without the leading zero  
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, "0")
  Log.Message(FloatToStr(number))
  # Restore original settings 
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ds)
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, lz)

# The routine produces the following output for US English locale: 
# 0.7 
# 0,7 
# ,7

VBScript

Sub SetLocaleInfoSample
  Dim number, ds, lz

  number = 0.7

  ' Remember default number settings
  ds = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL)
  lz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO)

  ' Log a number using default settings
  Log.Message FloatToStr(number)

  ' Log a number using a different decimal separator
  SetLocaleInfo LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ","
  Log.Message FloatToStr(number)

  ' Log a number without the leading zero
  SetLocaleInfo LOCALE_USER_DEFAULT, LOCALE_ILZERO, "0"
  Log.Message FloatToStr(number)

  ' Restore original settings
  SetLocaleInfo LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ds
  SetLocaleInfo LOCALE_USER_DEFAULT, LOCALE_ILZERO, lz
End Sub

' The routine produces the following output for US English locale:

' 0.7
' 0,7
' ,7

DelphiScript

procedure SetLocaleInfoSample;
var number, ds, lz;
begin
  number := 0.7;

  // Remember default number settings
  ds := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL);
  lz := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO);

  // Log a number using default settings
  Log.Message( FloatToStr(number) );

  // Log a number using a different decimal separator
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ',');
  Log.Message( FloatToStr(number) );

  // Log a number without the leading zero
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, '0');
  Log.Message( FloatToStr(number) );

  // Restore original settings
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ds);
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, lz);
end;

{
The function produces the following output for US English locale:

 0.7
 0,7
 ,7
}

C++Script, C#Script

function SetLocaleInfoSample()
{
  var number = 0.7;

  // Remember default number settings
  var ds = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL);
  var lz = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO);

  // Log a number using default settings
  Log["Message"]( FloatToStr(number) );

  // Log a number using a different decimal separator
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ",");
  Log["Message"]( FloatToStr(number) );

  // Log a number without the leading zero
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, "0");
  Log["Message"]( FloatToStr(number) );

  // Restore original settings
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, ds);
  SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILZERO, lz);
}

/*
The routine produces the following output for US English locale:

 0.7
 0,7
 ,7
*/

The following example demonstrates how to change the default short date format for the current user:

JavaScript, JScript

function ChangeShortDate()
{
  // Get current short date format
  var strOldShortDate = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE);

  if (! SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, "yyyy/MM/dd"))
    Log.Error("Could not change short date format.");

  // Restore original short date format
  if (! SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strOldShortDate))
    Log.Error("Could not restore original short date format.");
}

Python

def ChangeShortDate():
  # Get current short date format 
  strOldShortDate = aqEnvironment.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE)
  if not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, "yyyy/MM/dd"):
    Log.Error("Could not change short date format.")
  # Restore original short date format 
  if not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strOldShortDate):
    Log.Error("Could not restore original short date format.")

VBScript

Sub ChangeShortDate
  ' Get current short date format
  Dim strOldShortDate
  strOldShortDate = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE)

  If Not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, "yyyy/MM/dd") Then
    Log.Error "Could not change short date format."
  End If

  ' Restore original short date format
  If Not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strOldShortDate) Then
    Log.Error "Could not restore original short date format."
  End If
End Sub

DelphiScript

procedure ChangeShortDate;
var strOldShortDate;
begin
  // Get current short date format
  strOldShortDate := GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE);

  if not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, 'yyyy/MM/dd') then
    Log.Error('Could not change short date format.');

  // Restore original short date format
  if not SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strOldShortDate) then
    Log.Error('Could not restore original short date format.');
end;

C++Script, C#Script

function ChangeShortDate()
{
  // Get current short date format
  var strOldShortDate = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE);

  if (! SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, "yyyy/MM/dd"))
    Log["Error"]("Could not change short date format.");

  // Restore original short date format
  if (! SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strOldShortDate))
    Log["Error"]("Could not restore original short date format.");
}

See Also

GetLocaleInfo Method

Highlight search results