I want to format the date on the lock screen without the use of extensions.
I have already used the answer to this question to set up my top bar clock formatting. However, it did not affect the lock screen formatting.
I want to format the date on the lock screen without the use of extensions.
I have already used the answer to this question to set up my top bar clock formatting. However, it did not affect the lock screen formatting.
BLUF: This is a permanent and clean way to alter formatting of the date on the "lock screen" aka screen shield/unlock dialog without the use of extensions.
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 unlock dialog 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 lock screen/unlock dialog date 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 unlock dialog version used in Ubuntu 20.04:
https://github.com/GNOME/gnome-shell/blob/gnome-3-36/js/ui/unlockDialog.js
If you examine the function 'updateClock' beginning at line 365, you'll see the localization/internationalization lookup key in use. What you see in quotations below is not the formatting string itself but rather the key to look up the actual formatting string. The N( that surrounds the key performs the lookup:
I wanted a custom format string for displaying day-of-week, month, and day in that order. The string key in the javascript appeared to be OK and accomplish what I wanted but I needed to find the actual mapping to be sure.
So the key I needed to find in the localization/internationalization .po file was:
Unfortunately, I couldn't find the 'en' locale file I needed so I grabbed the en_GB file.
https://github.com/GNOME/gnome-shell/blob/gnome-3-36/po/en_GB.po
Then, I searched for unlockDialog.js in hopes of finding the mapping... and I did on line 2174:
This mapping would provide the day-of-week, day, and month instead of day-of-week, month, day that I wanted.
To obtain the desired date format I changed the mapping to:
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 unlock dialog uses a file with the specific name of gnome-shell.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-shell/tree/gnome-3-36/po
Prior to the change reflected in the above 'msgstr' the lock screen date would have displayed as:
But after the above change(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 can be installed via 'sudo apt install gettext' in 20.04:
Next, rename the resulting messages.mo file to gnome-shell.mo and copy it to your specific locale LC_MESSAGE directory:
Then, to effect the change, reboot.
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: