I have a pretty specific problem, that I have had no luck trying to find a working solution to. I have a laptop running Ubuntu 18.04 docked using 2 external monitors resulting in 3 screens. I want to have my top bar on all 3 screens to easily look up on the current screen to see the time. I enable this using the Multi Monitors Add-On Gnome extension. I am running Ubuntu in English, but set to Swedish formats. This makes for a very ugly and incorrect date format in the top bar.
This is pretty much English format with Swedish names for days and months. On a side note, this localization "bug" has been fixed and is ready for an upcoming gnome release.
My main issue is that I want to change the format of the date displayed to something like:
I can easily get this format using any of the many clock formatting Gnome extensions (Clock Override, Datetime Format). However, none of these extensions work with my Multi Monitors Add-On, leaving me with a nicely formatted clock on the main monitor, but ugly formatted clocks on the other two screens. I have tried getting the developers of these addons to collaborate, but apparently dependencies between gnome extensions is "hell".
I have also tried editing the locale files directly, both the en_US and sv_SE. Specifically the LC_TIME
d_t_fmt
format for date and time strings, but this seems to have no impact on the clock format.
In a last attempt I also unpacked the libgnome-shell.so
file located in /usr/lib/gnome-shell/
to try and edit the JavaScript files used to display the clock, using this answer. I had a look in dateMenu.js
and calendar.js
and changed most of the format strings that I could find to my desired format %Y-%m-%d
. I then ran GNOME_SHELL_JS=$HOME/gnome-shell-js gnome-shell --replace
, but again it seemed to have no effect. To be fair, I am in deep waters here and could definitely have failed in my attempts. As such, the solution could still be in this method.
Have anyone had any experience with a situation like this? Changing the format of date and time displayed on multiple monitors using Ubuntu 18.04? Feel free to try what I have tried already as I can certainly have missed something that could have made it work.
BLUF: This is a permanent and clean way to alter formatting of the Gnome top bar clock to your liking without the use of extensions.
I also wanted to display a custom-formatted string for the clock in the Gnome top bar but with just a single display. However, this answer will extend to your problem as well and allow you to use just the multi-monitor top bar extension. My goal was to simply do this without any extension in my case so the custom time format would be seen consistently at the initial gdm login screen upon boot, while in active logged-in sessions, and on the session unlock screen. It took some digging but the key lies in how Gnome handles localization/internationalization and how the Gnome wall clock, as it's called, obtains the string to actually display in the top bar.
First, a bit of background on the use of .po and .mo files in Gnome localization/internationalization can be found here:
https://wiki.gnome.org/TranslationProject/LocalisationGuide
Basically, at runtime, Gnome wall clock takes the current time and applies localization/internationalization string formatting. It uses a string key to look up a formatting string to use for a given locale to determine what to actually display -- it does not rely on the locale file formatting strings. If you modify the value returned for a given key in the localization/internationalization file, the clock display will reflect the change. Localization/internationalization uses two files. The first is the human-readable .po file that translators populate for each locale and this is where the mapping from lookup keys to formatting strings can be found. The second is the .mo file that is generated from the .po file... more on this and how it relates in just a bit...
Below is a link to the source for the Gnome wall clock version used in Ubuntu 18.04:
https://github.com/GNOME/gnome-desktop/blob/gnome-3-28/libgnome-desktop/gnome-wall-clock.c
If you examine the function 'gnome_wall_clock_string_for_datetime' beginning at line 261, you'll see the localization/internationalization lookup keys in use. There are several. Ubuntu has various display settings for the wall clock depending on whether you want to display just the time, time with day, time with day and date, etc. Each of these corresponds to a given localization/internationalization lookup key that wall clock uses. What you see in quotations below is not the formatting string itself but rather the key to look up the actual formatting string. The _() that surrounds each key performs the lookup:
For instance, I wanted a custom format string for displaying day, and date, and time in 12 hour format. That is in Ubuntu, I had set the clock to display the day, date, and time in 12 hour format which corresponds to the 'full date' in the above code. Examining the function, I was able to determine that this 'full date' lookup key occurred at line 288:
I wasn't interested in seconds so the key I needed to find in the localization/internationalization .po file was:
The localization/internationalization .mo files are binary in format but easily generated from a human-readable plain-text mapping .po files that maps a given lookup key to formatting string. Gnome wall clock uses a file with the specific name of gnome-desktop-3.0.mo for localization/internationalization. It was not present on my system under the prescribed location for any locale:
So, I didn't need to worry about replacing it but rather creating it anew. Regardless, you need to first obtain the .po file for your locale:
https://github.com/GNOME/gnome-desktop/tree/gnome-3-28/po
Next, find the above mentioned specific key(or the key for which you want to change the formatting string based on your clock setting in Ubuntu) in the .po file. The string key is 'msgid' and the formatting string to be returned is 'msgstr'. For instance, the snippet from my .po file is(ignore their comment since the code lines don't actually match up):
After the modification:
Prior to the change reflected in the above 'msgstr' it would have displayed:
But after the above change the day is no longer abbreviated and the leading space in front of the date has been removed(see the end of this answer for the formatting specifiers):
Next, take this .po file and run it through the following on the command line to obtain the messages.mo file where XX is your locale. The binary msgfmt is already installed on Ubuntu 18.04:
Next, rename the resulting messages.mo file to gnome-desktop-3.0.mo and copy it to your specific locale LC_MESSAGE directory:
Then, to effect the change, log out and log back in. If you find that the formatting did not change then double check that your current clock settings truly correspond to the key for which you changed the formatting string.
Finally, here are some formatting string specifiers to help you along. I borrowed these from another site so no guarantees that these all work in Gnome: