Bloggings

Back

Slstatus date with alternative locale

2025-04-26

Modifying slstatus to display French date

My default locale is en-US, but I wanted to display weekdays in French in the slstatus bar.

The solution is to add setlocale to the function in
slstatus/components/datetime.c

/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <time.h>
#include <locale.h>

#include "../slstatus.h"
#include "../util.h"


const char *
datetime(const char *fmt)
{    
	setlocale(LC_ALL,"fr_FR.utf8");
	time_t t;

	t = time(NULL);

	if (!strftime(buf, sizeof(buf), fmt, localtime(&t))) {
		warn("strftime: Result string exceeds buffer size");
		return NULL;
	}

	return buf;
}

 


ยง