Skip to content

Commit fbc9164

Browse files
text-frontend: Get locale via GLib (#51)
Instead of only supporting the LANGUAGE environment variable that's not necessarily set, use GLib's `g_get_language_names` to detect the locale to use in the text frontend which takes other environment variables into account as well [1]: > The returned list is sorted from most desirable to > least desirable and always contains the default locale “C”. Also, make `locale` a local variable in the control thread that's the only user instead of using a static variable. This e.g. makes > get-all-translations PDF CUPS print the translations for the current language in a fresh Ubuntu 23.10 installation where the `LANGUAGE` environment variable is not set, and the result without this commit in place was therefore just > get-all-translations PDF CUPS No translations found [1] https://docs.gtk.org/glib/func.get_language_names.html
1 parent cc51ac3 commit fbc9164

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tools/cpdb-text-frontend.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ gpointer control_thread(gpointer user_data);
1818
gpointer background_thread(gpointer user_data);
1919

2020
cpdb_frontend_obj_t *f;
21-
static const char *locale;
2221

2322
static void printMedia(const cpdb_media_t *media)
2423
{
@@ -108,8 +107,6 @@ int main(int argc, char **argv)
108107
setlocale (LC_ALL, "");
109108
cpdbInit();
110109

111-
locale = getenv("LANGUAGE");
112-
113110
pid_t pid_temp = getpid();
114111
char pid[20];
115112
snprintf(pid, sizeof(pid), "%d", (int)pid_temp);
@@ -135,6 +132,8 @@ gpointer control_thread(gpointer user_data)
135132
fflush(stdout);
136133
char buf[BUFSIZE];
137134

135+
const char *locale = g_get_language_names()[0];
136+
138137
cpdbConnectToDBus(f);
139138
displayAllPrinters(f);
140139

0 commit comments

Comments
 (0)