LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-14-2019, 10:15 PM   #1
norn00b
LQ Newbie
 
Registered: Sep 2019
Posts: 4

Rep: Reputation: Disabled
Capitalize datetime when locale is lowercase?


Hi!

I'm using the extension Clock Override to format the top bar datetime on Ubuntu 18.04, and I'm using the %A option to display my locale's (Norwegian) full weekday. This, however, is in all lowercase ("søndag", which is grammatically correct Norwegian), but I want to have it capitalized in my top bar ("Søndag").

Is there any way I can achieve this?

Thank you in advance!
 
Old 09-14-2019, 11:38 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
does it display correctly if you use date command?

is it just søndag ?

ok I see it here on Debian
Code:
for i in {0..6};do LC_TIME=nb_NO.UTF-8 date +%A -d "+$i day";done
søndag
mandag
tirsdag
onsdag
torsdag
fredag
lørdag


Code:
strings /usr/lib/locale/nb_NO.utf8/LC_TIME
not capitalised

Code:
strings /usr/lib/locale/en_GB.utf8/LC_TIME
so it looks like a problem in the locales-all package

which comes from glibc source

looking at
localedata/locales/nb_NO
that is source of the problem ( no capitalisation )
 
Old 09-14-2019, 11:51 PM   #3
norn00b
LQ Newbie
 
Registered: Sep 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for replying!
I believe that the all-lowercase locale is correct, as weekdays are generally not capitalized in Norwegian.
However, when the weekday is written by itself in the top bar, I'd like to have it capitalized nevertheless (as if it was at the beginning of a sentence, or in a title).
Is there any way to tweak the datetime output, without modifying the locale? (As mentioned, I believe the locale is correct – just not what I want)
 
Old 09-15-2019, 12:20 AM   #4
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
In your login, create a sub-directory called myProgs - say.

In this, create a script called that takes the date and substitutes montag with Montag and so on. A simple if .. elif .. fi would do. The script can have the same name as date with options.

Make the script executable.

Put this sub directory first in your path like PATH=~myProgs:$PATH

Now date (which is your date command) should work as the regular date but Capitalizing (really Properizing) the day names.

OK
 
Old 09-15-2019, 12:20 AM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783

I was wondering why it was never fixed if it wasn't correct.

do you know what is actually displaying it?
I suspect the extension is just adding the format string to the configuration for that

if its not an option the code could be hacked to change the string

can you set the font?
since the first letter is not repeated ( in the days at least ) you could hack a custom font to have the lowercase s m t o f l be upper. but that is ugly.

it is probably easier ( and cleaner ) to just add a capitalise option to the "top bar" or the extension depending on what sets the string
 
Old 09-15-2019, 12:20 AM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
@AnanthaP

the date command was just me looking at the locales
Code:
Date=$(date +%A)
echo ${Date^}
is not going to fix the display in top bar

Last edited by Firerat; 09-15-2019 at 12:36 AM. Reason: <was duplicate post>
 
Old 09-15-2019, 12:55 AM   #7
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Firerat View Post
so it looks like a problem in the locales-all package

which comes from glibc source
The same is true in other languages, like Dutch (both nl_NL as well as nl_NL.utf8):
all weekdays AND months names are all lowercase, while in en_US.utf8 they are all capitalized.
For fun I tested German (de_DE*) and French (fr_FR*) too: the first is (properly) capitalized (in German all nouns are capitalized), the latter is not.
 
Old 09-15-2019, 02:00 AM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
yeah, post #3 and #5 clear that up ehartman


My Internet has gone all glitchy ( probably why that duplicate post happened )
but had a quick look at the code
I think it is doable

you could open a request here to get it done properly
https://github.com/stuartlangridge/g...verride/issues


as a hack ( this is untested *and* I don't know js )
https://github.com/stuartlangridge/g...r/extension.js
Code:
function overrider(lbl) {
    var FORMAT = settings.get_string("override-string");
    var now = GLib.DateTime.new_now_local();

    var desired = Format.format(FORMAT, now);
    //var Desired = desired.charAt(0).toUpperCase() + name.slice(1)
    var Desired = desired.charAt(0).toUpperCase() + desired.slice(1)
    // I believe that would make the fist char. Uppercase
    var t = lbl.get_text();
    //if (t != desired) {
    if (t != Desired) {
        last = t;
        //lbl.set_text(desired);
        lbl.set_text(Desired);
    }
}
That assumes day is the first thing in the string
I have no idea if it would work ( or is anywhere near correct )
It is a proof of concept, an ugly hack
I don't use gnome, so can't test it right now

I may install gnome soon, because now I just want to know if it works

Edit, was an error in my original edit
which is moot, since it doesn't work anyway
I'll plug away at it

Last edited by Firerat; 09-15-2019 at 01:24 PM.
 
Old 09-15-2019, 08:58 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by norn00b View Post
I'm using the extension Clock Override to format the top bar datetime on Ubuntu 18.04, and I'm using the %A option to display my locale's (Norwegian) full weekday. This, however, is in all lowercase ("søndag", which is grammatically correct Norwegian), but I want to have it capitalized in my top bar ("Søndag").

Is there any way I can achieve this?
Unless you want to get into coding, this depends on two things:
The capabilities of the clock override extension.
If it can execute external commands, we can help, if not I'm guessing you're dependent on the formatting options available, most likely only what is provided by strtime. See
Code:
man strftime
for details.
 
Old 09-15-2019, 09:50 AM   #10
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
using that manpage

Code:
for i in {0..6};do LC_TIME=nb_NO.UTF-8 date +%^A -d ' +'$i' day';done
SøNDAG
MANDAG
TIRSDAG
ONSDAG
TORSDAG
FREDAG
LøRDAG
looks a little odd
 
Old 09-15-2019, 02:43 PM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
ok, figured it out

I added a new format %;A

edit
~/.local/share/gnome-shell/extensions/clock-override@gnomeshell.kryogenix.org/format.js

add the bold bit

Code:
        if (FORMAT.indexOf("%;@") > -1) {
            var bmtnow = now.to_timezone(GLib.TimeZone.new('+01'));
            var beat_time = 0 | (bmtnow.get_hour() + (bmtnow.get_minute() / 60) + bmtnow.get_second() / 3600) * 1000 / 24;
            beat_time = ('000' + beat_time).slice(-3);
            desired = desired.replace(/%;@/g, beat_time);
        }
    }
    if (FORMAT.indexOf("%;A") > -1) {
        var cap_day = now.format("%A").charAt(0).toUpperCase() + now.format("%A").slice(1);
        desired = desired.replace(/%;A/g, cap_day);
    }
    if (FORMAT.indexOf("%") > -1) {
        desired = now.format(desired);
    }

    return desired;
};
you can then use %;A to get capitalised day
you may need to restart gnome



Note, this might be overcomplicated,. I didn't look to see what that replace function could do.. it may be able to do a toUpper idk
 
1 members found this post helpful.
Old 09-17-2019, 11:33 AM   #12
norn00b
LQ Newbie
 
Registered: Sep 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Firerat View Post
ok, figured it out

I added a new format %;A

edit
~/.local/share/gnome-shell/extensions/clock-override@gnomeshell.kryogenix.org/format.js

add the bold bit

Code:
        if (FORMAT.indexOf("%;@") > -1) {
            var bmtnow = now.to_timezone(GLib.TimeZone.new('+01'));
            var beat_time = 0 | (bmtnow.get_hour() + (bmtnow.get_minute() / 60) + bmtnow.get_second() / 3600) * 1000 / 24;
            beat_time = ('000' + beat_time).slice(-3);
            desired = desired.replace(/%;@/g, beat_time);
        }
    }
    if (FORMAT.indexOf("%;A") > -1) {
        var cap_day = now.format("%A").charAt(0).toUpperCase() + now.format("%A").slice(1);
        desired = desired.replace(/%;A/g, cap_day);
    }
    if (FORMAT.indexOf("%") > -1) {
        desired = now.format(desired);
    }

    return desired;
};
you can then use %;A to get capitalised day
you may need to restart gnome



Note, this might be overcomplicated,. I didn't look to see what that replace function could do.. it may be able to do a toUpper idk
Wow, that worked like a charm!
Thank you so much, Firerat!!
 
Old 09-17-2019, 02:35 PM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
and you should be able to see how to do the same for Month

obviously, you would need to re-do the changes after updates.

if it updates frequently you could fork the git and issue a pull request ( or open a request via issues )
Then everyone has the option

Edit: if you do a pull request you should probably come up with a better name than cap_day,
propercase is technically the correct term
propercase_day

Last edited by Firerat; 09-17-2019 at 02:44 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot lock locale archive "/usr/lib64/locale/locale-archive": Permission denied when building Multilib Cross Linux from Scratch Gunnersky2002 Linux - Software 2 06-13-2018 09:28 AM
Python: datetime.datetime.strptime() trouble PoleStar Programming 4 12-15-2015 06:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration