Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change locale for Google Colab

I want to change the local setting (to change the date format) in GoogleCollab

The following works for me in JupyterNotebook but not in GoogleColab:

locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8')

It always returns the error: unsupported locale setting

I have already looked at many other solutions and tried everything. One solution to change only the time zone I have seen is this one:

'!rm /etc/localtime
!ln -s /usr/share/zoneinfo/Asia/Bangkok /etc/localtime
!date
like image 869
Felix Avatar asked Apr 11 '21 13:04

Felix


People also ask

Can you run colab locally?

Using local runtimes 🖥 This way, you can execute code on your local hardware and access your local file system without leaving the Colab notebook. The following documentation goes deeper into the way it works.

How do I change the language on collab?

Select Aide > Afficher en anglais . Goodluck! Show activity on this post. The language presented is based on browser settings, so you'll want to change the language settings in your browser.


1 Answers

I figured this one out after a long time:

  1. In Colab, you will have to install the desired locales. You do this with:
    !sudo dpkg-reconfigure locales
    • This will prompt for a numeric input, e.g. 268 and 269 for Hungarian.
      So you enter 268 269.
    • It will also prompt for the default locale, after installation. Here you will need to select your desired custom locale. This time, it is a numeric selection out of 3-5 options, depending, on how many have you selected at the previous step. In my case, I have selected 3, and the default locale became hu_HU.
  2. You need to restart the Colab runtime: Ctrl + M then .
  3. You need to activate the locale:
    import locale
    locale.setlocale(locale.LC_ALL, 'hu_HU') <- make sure you do it for the LC_ALL context.
  4. The custom locale is now ready to use with pandas:
    pd.to_datetime('2021-01-01').day_name() returns Friday, but
    pd.to_datetime('2021-01-01').day_name('hu_HU') returns Péntek
like image 86
csaladenes Avatar answered Oct 24 '22 04:10

csaladenes