Skip to content

Date formatting doesn't take locale in account. #71

Description

@lowusage

Currently, date formatting doesn't take the current locale in account.
For example, this file :

#date %d %B %Y

Will produce the following outputs :

$ ./src/gpp test.gpp 
11 May 2026
$ LANG=fr_FR.utf8 ./src/gpp test.gpp 
11 May 2026
$ LC_ALL=fr_FR.utf8 ./src/gpp test.gpp 
11 May 2026

Instead of the correct localized outputs.

The expected output being :

$ ./src/gpp test.gpp 
11 May 2026
$ LANG=fr_FR.utf8 ./src/gpp test.gpp 
11 mai 2026
$ LC_ALL=fr_FR.utf8 ./src/gpp test.gpp 
11 mai 2026

This is an easy fix : include the locale C header and use setlocale(LC_ALL, "") at initialization. The attached patch does that (I don't exactly know if initthings() is the right place through).

Thanks.

0001-Fix-localization-support.patch

From d41e09dc44bad94a167f05dfa1df5faf5f507296 Mon Sep 17 00:00:00 2001
From: lzigmann <laura@zigmann.org>
Date: Mon, 11 May 2026 13:04:49 +0200
Subject: [PATCH] Fix localization support

Signed-off-by: lzigmann <laura@zigmann.org>
---
 src/gpp.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/gpp.c b/src/gpp.c
index 1ade1fa..9ee79bd 100644
--- a/src/gpp.c
+++ b/src/gpp.c
@@ -44,6 +44,7 @@
 #  include <fnmatch.h>
 #endif
 #include <time.h>
+#include <locale.h>
 
 #define STACKDEPTH 50
 #define MAXARGS 100
@@ -1247,6 +1248,9 @@ void initthings(int argc, char **argv) {
     autoswitch = 0;
     dosmode = DEFAULT_CRLF;
 
+    /* set locale global state for date formating */
+    setlocale(LC_ALL, "");
+
     for (arg = argv + 1; *arg; arg++) {
         if (!endofoptions && strcmp(*arg, "--") == 0) {
             endofoptions = 1;
-- 
2.47.3

EDIT: example outputs takes place on a system with "C" as its default locale.
EDIT2: added patch as plain text content

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions