0

How to set locale (French) valid for Windows and Unix?

My full robot test is:

*** Settings ***
Library    SeleniumLibrary
Library    DateTime

*** Keywords ***
Get Next Week French date
    Evaluate    locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')    locale
    ${today}=               Get Time
    ${tomorrow}=            Add Time To Date  ${today}  1 days
    ${three_day_after}=     Add Time To Date  ${today}  3 days
    ${today_day}=           Convert Date      ${today}  result_format=%a
    Log To Console  ${today_day}
    ${next_date}=           Set Variable If   "${today_day}"=="ven."  ${three_day_after}  ${tomorrow}
    ${next_week}=           Add Time To Date  ${next_date}  7 days
    ${day_of_week}=         Convert Date   ${next_week}  result_format=%A
    ${day_of_week_fr}=      Evaluate  """${day_of_week}""".title()
    ${day}=                 Convert Date   ${next_week}  result_format=%d
    ${month}=               Convert Date   ${next_week}  result_format=%B
    [Return]  ${day_of_week_fr} ${day} ${month} 

test
    ${val}=  Get Next Week French date
    Log To Console  ${val}

*** Test Cases ***

MY SUPER TEST
    [Tags]  foo|AC0
    Given test

On my local machine (Windows 7) OK:

Evaluate    locale.setlocale(locale.LC_ALL, 'french')    locale

On my CI machine (Unix) OK:

Evaluate    locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')    locale

If I use fr_FR.UTF-8 on my local machine, I have this error:

locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')' failed: unsupported locale setting

EDIT

May be Python 2 (fr_FR.UTF-8) Vs. Python 3 (french) ??

Todor Minakov
  • 19,097
  • 3
  • 55
  • 60
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
  • Doesn't seem to be an issue with python version. If so, you would have to make sure to use same version in both platforms. This seems more to like an issue with the OS. You might want to have a look at this [post](https://stackoverflow.com/questions/955986/what-is-the-correct-way-to-set-pythons-locale-on-windows/956084#956084). – Sameem Apr 05 '19 at 13:40
  • @Sameem, 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 14:15

1 Answers1

2

Since the Windows and Unix machines use different syntax to set the locale you should evaluate the operating system first and then set the locale accordingly.

*** Keywords ***
Get next week french date 
    ${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
Sameem
  • 831
  • 1
  • 8
  • 23