6

locale.setlocale(locale.LC_ALL, 'french') work on my local machine (windows 7 + Python 3)

locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') work on my other machine (Unix) but if I use this on my local machine, I have this error:

locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')' failed: unsupported locale setting
num3ri
  • 822
  • 16
  • 20
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
  • 1
    Possible duplicate of [What is the correct way to set Python's locale on Windows?](https://stackoverflow.com/questions/955986/what-is-the-correct-way-to-set-pythons-locale-on-windows) – Jonathan Apr 05 '19 at 09:58
  • @Jonathan, no duplicate, `fr_FR.UTF-8` work only on one machien and `french` on other. I have already seen this post before asking my question and it is precisely by doing so that I have the problem. – Stéphane GRILLON Apr 05 '19 at 10:04
  • Supported locale names depend on the platform and version. For Windows Python 3.5+, which uses the Windows Universal C Runtime (UCRT) library, see [UCRT Locale names, Languages, and Country/Region strings](https://learn.microsoft.com/en-us/cpp/c-runtime-library/locale-names-languages-and-country-region-strings?view=vs-2019). Note that [BCP 47](https://tools.ietf.org/html/bcp47) language tags are preferred, which use hyphen instead of underscore (e.g. "fr-FR"). Python's `locale.getlocale` function doesn't parse these yet. – Eryk Sun Apr 06 '19 at 00:01
  • The BCP 47 form doesn't allow a ".codepage" suffix, except recently they started allowing ".utf-8" or ".utf8". Windows is Unicode and doesn't conflate language/region locale settings with text encodings. – Eryk Sun Apr 06 '19 at 00:02
  • The Universal CRT still supports legacy Windows locale names of the form "language[_country[.codepage]]". Note that these use either the [full English name](https://learn.microsoft.com/en-us/windows/desktop/Intl/locale-senglish-constants) or Microsoft's [non-standard abbreviations](https://learn.microsoft.com/en-us/windows/desktop/Intl/locale-sabbrev-constants). For example, the abbreviated name for the "French_France" locale is "fre_FRA", or "fre_FRA.1252" with a codepage. – Eryk Sun Apr 06 '19 at 00:04

2 Answers2

1

Locale settings are OS dependent and, at least on *nix systems, might even depend on whether they are installed or not.

This SO post might be a good pointer to what locales to use on Windows systems: https://stackoverflow.com/a/956084/2186184

Jonathan
  • 748
  • 3
  • 20
0

add this in RobotFramework (at the beginning):

${osName}=    Evaluate    platform.system()    platform
Run keyword if    "${osName}"=='Windows'    Evaluate    locale.setlocale(locale.LC_ALL, 'french')    locale
    ...         ELSE    Evaluate    locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')    locale
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154