set locale

Prev Next

Function Names

set locale

Description

During the installation process, you have been asked to specify a language and a country in order to set the locale settings applicable for B4P. The locale settings rule data formats such as numbers, dates and times, and also chooses the right language for weekdays and months. This function is available to change the locale setting to a different locale.

You can either specify a country, a language or a locale keyword (like en_US). Specifying a country is fine if only one major language is spoken (e.g. English for Great Britain), and specifying a language is fine if the language is spoken in one country or a few (e.g. German). For German, Germany is assumed. For Spanish, Spain is assumed. In order to specify the locale properly (e.g. Canadian French fr_CA, Spanish in Mexico es_MX), using locale codes is recommended.

Call as: function

Restrictions

Indirect parameter passing is disabled.

Parameter count

1

Parameters

No.TypeDescription
1
input
string Locale

All values (Locale, Language, Country) are supported. First match is assumed if specifying language or country.

Locale Language Country Remarks
none none none
en_US English USA M-D-Y date format
en_GB English Great Britain
en_UK English United Kingdom Same as Great Britain
en_CA English Canada
en_FR English France
en_IN English India Indian numbering system
hi_IN Hindi India Indian numbering system
de_DE German Germany
en_DE English Germany
de_CH German Switzerland Apostroph used as thousand separator
en_CH English Switzerland
de_AT German Austria Some month names are different than DE, CH
en_AT English Austria
fr_CA French Canada
fr_FR French France
fr_CH French Switzerland
fr_BE French Belgium
it_IT Italian Italy
it_CH Italian Switzerland Apostroph used as thousand separator
de_IT German Italy
es_ES Spanish Spain
es_US Spanish USA M-D-Y date format
sv_SE Swedish Sweden
en_SE English Sweden

Opt. 2
input
string Locale table file name

In case you have maintained your own locale file (e.g. to support additional countries or specifi configurations), then specify the CSV file name with your locale data. The CSV file must contain the same column header names as the original "List of Locales.csv").

Examples

    orig locale[] = local settings[locale];
    echo("Keep the original locale in order to restore orig. settings later on: ", orig locale[] );

    date[] = date( "2020-01-14" );
    num[] = 12345678.90;

    for all parameters( { en_IN, es_US, de_AT, it_IT, Switzerland }, loc[], i[] )
    {
        echo(loc[],":");
        set locale( loc[] );
        echo( str( date[], "  Tttt, DD.Mmmm.YYYY", local ) );
        echo( str( num[],  "  #,###.##", local ) );
        if (i[]==0) list system variables( "local settings" ); //  Do this for 1 example
    }

    set locale( orig locale[] );

Output

Keep the original locale in order to restore orig. settings later on: de_CH
en_IN:
  Tuesday, 14.January.2020
  1,23,45,678.9

Variable List Level = 0  Regional Level = 0    System variables
-------------------------------------------------------------------------------
local settings          [Void]                     (void,read only)
  country name          India                      (string,read only)
  currency symbol       ₹                          (string,limited access)
  date format           D/M/YYYY                   (string,limited access)
  date format short     DMY                        (string,limited access)
  date separator        /                          (string,limited access)
  decimal separator     .                          (string,limited access)
  language              English                    (string,read only)
  list separator        ,                          (string,limited access)
  locale                en_IN                      (string,read only)
  thousand separator    ,                          (string,limited access)
  time format           HH:II:SS                   (string,limited access)
  time separator        :                          (string,limited access)

es_US:
  Martes, 14.Enero.2020
  12,345,678.9
de_AT:
  Dienstag, 14.Jänner.2020
  12 345 678,9
it_IT:
  Martedì, 14.Gennaio.2020
  12.345.678,9
Switzerland:
  Dienstag, 14.Januar.2020
  12'345'678.9
Try it yourself: Open LIB_Function_set_locale.b4p in B4P_Examples.zip. Decompress before use.

See also

quote path