Python - How to set French locale?
Asked Answered
L

2

7

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
Lyrebird answered 5/4, 2019 at 9:50 Comment(5)
Possible duplicate of What is the correct way to set Python's locale on Windows?Sweetmeat
@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.Marocain
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. Note that BCP 47 language tags are preferred, which use hyphen instead of underscore (e.g. "fr-FR"). Python's locale.getlocale function doesn't parse these yet.Inna
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.Inna
The Universal CRT still supports legacy Windows locale names of the form "language[_country[.codepage]]". Note that these use either the full English name or Microsoft's non-standard abbreviations. For example, the abbreviated name for the "French_France" locale is "fre_FRA", or "fre_FRA.1252" with a codepage.Inna
L
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
Lyrebird answered 11/4, 2019 at 6:37 Comment(0)
S
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://mcmap.net/q/204958/-what-is-the-correct-way-to-set-python-39-s-locale-on-windows

Sweetmeat answered 5/4, 2019 at 9:55 Comment(1)
That's right. I'm using Ubuntu and I needed to install a specific language pack.Oriana
L
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
Lyrebird answered 11/4, 2019 at 6:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.