8

Preliminary remark: This question is not about setting a locale by changing LC_ALL, LC_TIME, LANG, etc., it's rather about changing a locale definition, e.g. in /usr/share/i18n/locales/de_DE, or respectively, to get suggestions about more appropriate options than changing those system settings.

The intent is to obtain ISO time representations %Y-%m-%d and %H:%M:%S without undesired side effects.

Suggestions that I found on the net were yet all inappropriate (e.g., setting the locale to "danish" will not maintain the native language's spelled weekday names).

Now the only choice I currently see to get the desired behaviour is to change the definition of my native locale in /usr/share/i18n/locales/de_DE. This is not a perfect solution since with system updates those changed files may be overwritten again.

My questions are:

  1. Are there any better locale related options to get the desired function than changing the specific system locale file?
  2. Are there any problems to expect when changing a specific locale definition file? (And how could it be prevented that this file gets overwritten in case of system updates?)
  3. Would it be better to define a new specific variant of an existing locale file and use that in the LC_* settings? (And how would that new file/definition correctly be made known to the system?)
  4. Any other suggestions?
4
  • I'd suggest you copy the locale file you are interested in, give that copy a unique name (e.g., en_XX -- I don't know what the restrictions here are, trial and error might suffice), make whatever changes you want to that, and use it as the locale. You'll have to regenerate the list or whatever afterward, etc. – goldilocks May 19 '15 at 12:30
  • 1
    You might want to read my question, which contains details on what I did. I have yet to package it up, but for now this works quite nicely. Simply set LC_TIME (in /etc/environment or /etc/default/locale or /etc/locale.conf depending on distro) to the modified locale (I called mine isodate.UTF-8) and the respective format will get picked from that customized locale for only time/date. This is how I customized my otherwise en_US setting to display ISO date/time. – 0xC0000022L May 19 '15 at 12:36
  • 1
    @Janis: on Debian and Ubuntu you'll also want to put the name of your locale into /var/lib/locales/supported.d/local (or one of the other files in there) and run dpkg-reconfigure locales as superuser for the locale definition to be compiled. And yes, setting LC_TIME to point to a customized locale appears to be the least intrusive method of all I've seen so far. That's why your system has global settings where LC_TIME can be set different from the "overall locale". – 0xC0000022L May 19 '15 at 12:38
  • @0xC0000022L; Your experience here is very valuable. With the suggestions so far I'll go for a new locale file. I'm yet undecided whether I should use the copy on sections approach, or keep other sections redundant (so that I can diff against the original file). – Janis May 19 '15 at 12:56
6

In a recent question I asked what's the best practice for this kind of change. There was no answer yet. However, I can give you the recipe I am using, which has proven to work fine. All the programs pick the date up correctly.

My description is for Ubuntu, but will likely work on Debian and Mint.

Preparations

Copy the locale you want to customize from /usr/share/i18n/locales to a new file. E.g.

cp /usr/share/i18n/locales/de_DE /usr/share/i18n/locales/de_DE@isodate

Adjust all with the exception of the LC_TIME sections to:

copy "de_DE"

Adjust the LC_TIME section to match your desired outcome. You can use the settings from my above linked question as a template. It looks like this is pretty much exactly what you want.

If your locale doesn't make use of "AM/PM" notation, set those to empty:

t_fmt_ampm ""
am_pm   "";""

Making it known to the system

Edit the file /var/lib/locales/supported.d/local and add the info about your locale definition there. I.e. add a line like this if your file name above was isodate, adjust otherwise:

de_DE.UTF-8@isodate UTF-8

If /var/lib/locales/supported.d/local doesn't exist, create a file of that name. Don't put your changes into the respective en or de file in that folder, as they may get overwritten as soon as the language-pack-*-base and language-pack-* packages on your system receive an update.

Now run dpkg-reconfigure locales:

# dpkg-reconfigure locales
Generating locales...
  de_DE.UTF-8@isodate... done
  de_DE.UTF-8... up-to-date
Generation complete.

In your case this will indicate that the de_DE.UTF-8@isodate locale has been generated (assuming you have no syntax issues).

Last but not least add the following to /etc/default/locale:

LC_TIME="de_DE.UTF-8@isodate"

This will ensure that only LC_TIME overrides the default locale defined using LANG.

Log in anew and you should be able to see the new ISO date/time when using date or other tools using the respective libc runtime function.


The intent here is to make the least intrusive change while also not working against the system (e.g. against package manager and friends). Of course you can also simply create a copy of your locale, install it in a similar fashion as outlined above and then adjust LANG. The point is, as long as you don't want to run the risk of your changes being overwritten by a package update, you have to use a customized copy (whatever customization you go for; i.e. copy or simply keep the sections as they were in the original). And whether you change LANG to point to the full customized locale definition - or whether you add LC_TIME to point only to the relevant customized section of the same name of a customized locale definition file - you won't get around adjusting one of the global settings.

12
  • 3
    As a best-practice, you would suffix your locale with @something like en_US.UTF-8@isodate. – Stéphane Chazelas May 19 '15 at 12:59
  • @StéphaneChazelas: Hah! Awesome. However, then you cannot copy the LC_IDENTIFICATION and how would that affect the naming of the files and how you refer to the locale in /etc/default/locale and /var/lib/locales/supported.d/local respectively? Can you tell? – 0xC0000022L May 19 '15 at 13:01
  • 1
    You'd create a en_US@isodate definition file and use localedef to produce the correct files; see sourceware.org/git/?p=glibc.git;a=blob;f=localedata/README for details (and sourceware.org/git/?p=glibc.git;a=blob;f=localedata/locales/… for an example). – Stephen Kitt May 19 '15 at 13:05
  • 1
    Yes, in any case, you'd want to change the LC_IDENTIFICATION section (en_US@isodate) since it's a different locale, The end command would be localedef -i en_US@isodate -f UTF-8 en_US.UTF-8@isodate, I'm not sure about the Debian-specific configuration, my comment was mostly on how to name the locale. – Stéphane Chazelas May 19 '15 at 13:25
  • 1
    As I understand it, on Debian you'd add your locale definition in /usr/local/share/i18n/locales, add the supported locale/charmap pairs in /usr/local/share/i18n/SUPPORTED, and run dpkg-reconfigure locales (see also /etc/locale.gen). – Stephen Kitt May 19 '15 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.