16

I'd like to customize exclusively the date and time format for my system, while sticking to the rest of the locale as is. I know that environment variable LC_TIME will make it possible to customize that aspect only by pointing to an alternate locale. Since I am using Linux (Ubuntu 14.04 to be precise), I want to use the format understood by localedef as input.

I have read the following three pieces of documentation:

The last one was particularly helpful.

Now, I only want to customize the section for LC_TIME and would like to inherit verything else.

So I copied en_US to a file named isodate in /usr/share/i18n/locales and adjusted the values I care about. After sifting through the documentation I decided also to replace all other section contents with a copy-keyword.

Question: It's not clear to me what method is supposed to be best practice. Does anyone know that (or even another alternative than those given by me)?

For example, since I care only about a few values (d_t_fmt, d_fmt, t_fmt, t_fmt_ampm, am_pm, date_fmt) it would be sweet to inherit all of en_US for LC_TIME and then merely overwrite those values with my ISO-like format (ISO 8601). However, the documentation about copy states (emphasis mine):

copy

Specify the name of an existing locale which shall be used as the definition of this category. If this keyword is specified, no other keyword shall be specified.

This means I cannot simply throw in a copy and then add more keywords.

Also, might it be legit to only define the LC_TIME section or will localedef outright refuse to compile that?

TL;DR

What is the best practice for customizing my date and time format settings, while sticking to the DRY-principle, i.e. without repeating stuff unnecessarily?


What I came up with so far:

escape_char /
comment_char %

LC_IDENTIFICATION
copy "en_US"
END LC_IDENTIFICATION

LC_CTYPE
copy "en_US"
END LC_CTYPE

LC_COLLATE
copy "en_US"
END LC_COLLATE

LC_MONETARY
copy "en_US"
END LC_MONETARY

LC_NUMERIC
copy "en_US"
END LC_NUMERIC

LC_TIME
abday   "<U0053><U0075><U006E>";"<U004D><U006F><U006E>";/
    "<U0054><U0075><U0065>";"<U0057><U0065><U0064>";/
    "<U0054><U0068><U0075>";"<U0046><U0072><U0069>";/
    "<U0053><U0061><U0074>"
day "<U0053><U0075><U006E><U0064><U0061><U0079>";/
    "<U004D><U006F><U006E><U0064><U0061><U0079>";/
    "<U0054><U0075><U0065><U0073><U0064><U0061><U0079>";/
    "<U0057><U0065><U0064><U006E><U0065><U0073><U0064><U0061><U0079>";/
    "<U0054><U0068><U0075><U0072><U0073><U0064><U0061><U0079>";/
    "<U0046><U0072><U0069><U0064><U0061><U0079>";/
    "<U0053><U0061><U0074><U0075><U0072><U0064><U0061><U0079>"

week    7;19971130;7
first_weekday   1
first_workday   2
abmon   "<U004A><U0061><U006E>";"<U0046><U0065><U0062>";/
    "<U004D><U0061><U0072>";"<U0041><U0070><U0072>";/
    "<U004D><U0061><U0079>";"<U004A><U0075><U006E>";/
    "<U004A><U0075><U006C>";"<U0041><U0075><U0067>";/
    "<U0053><U0065><U0070>";"<U004F><U0063><U0074>";/
    "<U004E><U006F><U0076>";"<U0044><U0065><U0063>"
mon "<U004A><U0061><U006E><U0075><U0061><U0072><U0079>";/
    "<U0046><U0065><U0062><U0072><U0075><U0061><U0072><U0079>";/
    "<U004D><U0061><U0072><U0063><U0068>";/
    "<U0041><U0070><U0072><U0069><U006C>";/
    "<U004D><U0061><U0079>";/
    "<U004A><U0075><U006E><U0065>";/
    "<U004A><U0075><U006C><U0079>";/
    "<U0041><U0075><U0067><U0075><U0073><U0074>";/
    "<U0053><U0065><U0070><U0074><U0065><U006D><U0062><U0065><U0072>";/
    "<U004F><U0063><U0074><U006F><U0062><U0065><U0072>";/
    "<U004E><U006F><U0076><U0065><U006D><U0062><U0065><U0072>";/
    "<U0044><U0065><U0063><U0065><U006D><U0062><U0065><U0072>"
% Appropriate date and time representation (%c)
%   "%Y-%m-%d %H:%M:%S"
d_t_fmt "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064><U0020><U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
%
% Appropriate date representation (%x)
%   "%Y-%m-%d"
d_fmt   "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064>"
%
% Appropriate time representation (%X)
%   "%H:%M:%S"
t_fmt   "<U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
%
t_fmt_ampm ""
%
am_pm   "";""
%
% Appropriate date representation (date(1))   "%Y-%m-%d %H:%M:%S"
date_fmt    "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064><U0020><U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
END LC_TIME

LC_MESSAGES
copy "en_US"
END LC_MESSAGES

LC_PAPER
copy "en_US"
END LC_PAPER

LC_NAME
copy "en_US"
END LC_NAME


LC_ADDRESS
copy "en_US"
END LC_ADDRESS

LC_TELEPHONE
copy "en_US"
END LC_TELEPHONE

LC_MEASUREMENT
copy "en_US"
END LC_MEASUREMENT
  • 3
    It's ok to only define one section and copy the other ones... – don_crissti May 17 '15 at 23:23
  • 2
    @K7AAY - that tag is completely irrelevant. There is absolutely nothing Ubuntu-specific here. – don_crissti Aug 21 '18 at 18:38
  • You might want to take a look at en_DK.UTF-8 :) I guess it's what you want. – Pierre-Alain TORET Oct 17 '18 at 10:07
1

I created a very similar locale recently and as Pierre-Alain suggested I used en_DK.UTF-8 as my template. I don't think that there are any strict best practices as can be seen by looking at the differences between the standard locales that are shipped with most Linux distributions.

You can read about how I solved my problem on my web site and look at the final result on gitlab.

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.