aboutsummaryrefslogtreecommitdiff
path: root/articles/2025/Slstatus-date-with-alternative-locale.html
blob: 60d7b44ebf935ea8969e4c517645fec2acd78223 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!doctype html>
<html lang="EN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/style.css">
    <title>Slstatus date with alternative locale</title>
  </head>
  <body>
    <header>
      <h1>Bloggings</h1>
      <a href="/index.php">Back</a>
      
    </header>
    
<main>
<article>
<h2>Slstatus date with alternative locale</h2>
<h3>2025-04-26</h3>
<h4>Modifying slstatus to display French date</h4>
<p>My default locale is en-US, but I wanted to display weekdays in French in the slstatus bar.</p>
<p>The solution is to add setlocale to the function in <br><b>slstatus/components/datetime.c</b></p>
<p><img src="/images/blog/slstatus-french.png"></p>
<pre>
/* See LICENSE file for copyright and license details. */
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
<b>#include &lt;locale.h&gt;</b>

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


const char *
datetime(const char *fmt)
{    
	<b>setlocale(LC_ALL,"fr_FR.utf8");</b>
	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;
}
</pre>
</article>
</main>
<footer>

<p>&nbsp;</p>

<p>§</p>
  </footer>
</body>
</html>