Score:2

How to separate language from time format?

us flag

I want to set a custom time format or the time format specific to my localisation but I want to keep the names of days and months in English. How can I set it to something like YYYY-MM-DD, Monday, 20:05:47 CET?

There are multiple similar questions, e.g. How to change time and date language to English? and Combine English language and alternative locale

None of them are the solution - $LC_TIME bounds format to language and I want to know if there's a different way of handling formats in Linux, some kind of alternative to locale that'd allow to specify the time format and the language separately. Creating a custom locale is of course possible but it confuses most applications. Did anyone came out with anything better over all these years?

Score:2
ca flag

Hmm... this is not a direct answer, but something that might give a clear hint what to try:

$ sudo -i
...
# cp sv_SE_nerdy /usr/share/i18n/locales/
# echo "sv_SE_nerdy UTF-8" >> /etc/locale.gen
# locale-gen
# exit # sudo
$ localectl set-locale LC_MONETARY=sv_SE_nerdy
$ localectl set-locale LC_NUMERIC=sv_SE_nerdy
$ echo >>.bash_aliases "export LC_MONETARY=sv_SE_nerdy"
$ echo >>.bash_aliases "export LC_NUMERIC=sv_SE_nerdy"
$ localectl status
   System Locale: LANG=status
                  LC_NUMERIC=sv_SE_nerdy
                  LC_TIME=sv_SE.UTF-8
                  LC_MONETARY=sv_SE_nerdy
                  LC_PAPER=sv_SE.UTF-8
                  LC_NAME=sv_SE.UTF-8
                  LC_ADDRESS=sv_SE.UTF-8
                  LC_TELEPHONE=sv_SE.UTF-8
                  LC_MEASUREMENT=sv_SE.UTF-8
                  LC_IDENTIFICATION=sv_SE.UTF-8
       VC Keymap: sv-latin1
      X11 Layout: se
       X11 Model: asus_laptop
     X11 Options: terminate:ctrl_alt_bksp

and what I changed in sv_SE to create the ..._nerdy version:

$ cat sv_SE_diff 
--- /usr/share/i18n/locales/sv_SE   2022-04-07 03:24:41.000000000 +0200
+++ sv_SE_nerdy 2022-10-31 09:51:36.262570560 +0100
@@ -34 +34 @@
-title      "Swedish locale for Sweden"
+title      "Swedish locale for Sweden, decimal point in numbers and monetary values, narrow space number grouping"
@@ -41 +41 @@
-language   "Swedish"
+language   "Swedish, w DP"
@@ -44 +44 @@
-date       "2000-06-29"
+date       "2022-10-31"
@@ -182,2 +182,2 @@
-mon_decimal_point       ","
-mon_thousands_sep       "<U202F>"
+mon_decimal_point       "."
+mon_thousands_sep       "<U200A>"
@@ -198,2 +198,2 @@
-decimal_point           ","
-thousands_sep           "<U202F>"
+decimal_point           "."
+thousands_sep           "<U200A>"
@@ -276 +276 @@
-lang_name    "svenska"
+lang_name    "svenska, decimalpunkt"

... U200A defines unicode character 200A,
click on a char in character map to see the code for the selected character.
Display the character encoded (by a code) by typing e.g.CTRL+u followed by 202F+Enter in e.g. gnome-shell / Terminal.

and one more thing: the sv_SE locale formats dates as:

$ date 
sön  8 jan 2023 21:34:58 CET

... which may give a good hint on what to change the date format to.

cprn avatar
us flag
So you've made a custom locale. How does e.g. `soffice` work with that for you? Calc especially.
Hannu avatar
ca flag
I'm using LibreOffice, which accepts this perfectly, no noted issues so far (this *is* fairly new though).
Hannu avatar
ca flag
+ if the software is locale-aware, I would expect it to work well - at least for moderate changes, or changes / usage that exist in one or more of existing locales.
cprn avatar
us flag
I had issues with LibreOffice and currency settings in custom locale file in the past but it seems to be working okay now (i.e. LibreOffice seems to ignore `LC_MONETARY` as it should).
ye flag
I needed to run `sudo vi /etc/locale.gen` and add the altered locale, otherwise `sudo locale-gen` does not pick it up as new locale. (Ubuntu 22.04 LTS).
Hannu avatar
ca flag
The above revised to include that...
Hannu avatar
ca flag
Hmm.. `Ubuntu > Settings > Region & Language` still has `,` in numeric format.
Score:0
uz flag

Open your ~/.profile file for editing and add this line:

export LC_TIME=en_DK.UTF-8

While that is not exactly "specific to your localization" (unless you happen to be Danish), it gives you days and months in English and a sensible date/time format.

cprn avatar
us flag
This changes output of things like `ls -l` to `MM/DD/YY` which is out of order and therefore unacceptable.
Gunnar Hjalmarsson avatar
uz flag
@cprn: I assumed that `en_DK.UTF-8` had been generated on your system. Otherwise do: `sudo locale-gen en_DK.UTF-8`
cprn avatar
us flag
The only locale that seem to be generated are `en_GB`, `en_US`, `es_ES` and `pl_PL` - probably because the rest was commented out in `/etc/locale.gen` - I selected these 4 about 8 years ago when installing Linux. I've uncommented `en_DK` in `locale.gen` but it complained it needs to generate `da_DK` as well. I've uncommented `da_DK` but now it complains about missing file in `/usr/share/i18n/locales` (indeed there's no `da_DK` there). It's a mess. That's why I'm looking for a different solution to handle time altogether.
cprn avatar
us flag
I copied `pl_PL` and made a custom `en_PL` locale file for now but it's a silly solution. I'm going to Spain next week and will have to make another one, it seems.
Gunnar Hjalmarsson avatar
uz flag
@cprn: Why don't you just run the command I suggested? Are you on a non-Ubuntu system?
cprn avatar
us flag
I'm on Debian and I did - `sudo locale-gen en_DK.UTF-8` igored the argument and generated locale only for languages I selected during installation few years back. Adding `en_DK` was problematic, as described in my previous comment, so I made a custom `en_PL` and it works for now.
Gunnar Hjalmarsson avatar
uz flag
@cprn: Then your problem is off topic at Ask Ubuntu. (`locale-gen` in Ubuntu differs from `locale-gen` in Debian.)
cprn avatar
us flag
well it acts the same on my work laptop which runs Ubuntu so IDK what you mean. Also `man locale-gen` doesn't mention arguments and `man locale.gen` explicitly states the `locale-gen` command will generate all the locales from `/etc/locale.gen` file that that are correct, i.e. a template in `/usr/share/i18n/locales` for given locale exists and charset is correct - this is exactly what happened. Nevertheless, the question was about an alternative to `locale` - some more sensible standard of setting up formats that doesn't change the language - assuming it exists.
Gunnar Hjalmarsson avatar
uz flag
@cprn: It's correct that `man locale-gen` in Ubuntu does not reflect the Ubuntu changes to that script. That's a bug. I'm not aware of an alternative to `locale` which would achieve your goal. `en_DK.UTF-8` is the best workaround I know about. (And it ought to work on Debian too, but how to do it there is off topic here.)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.