Skip to content

Commit

Permalink
launcher: set preferred language list from system locale
Browse files Browse the repository at this point in the history
  • Loading branch information
rawoul committed Aug 28, 2024
1 parent edafaa0 commit d281298
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions launcher/cog-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ on_automation_started(WebKitWebContext *context, WebKitAutomationSession *sessio
static void
cog_launcher_startup(GApplication *application)
{
const gchar *const *locales;

G_APPLICATION_CLASS(cog_launcher_parent_class)->startup(application);

/*
Expand Down Expand Up @@ -318,6 +320,24 @@ cog_launcher_startup(GApplication *application)

g_object_set(self->shell, "device-scale-factor", s_options.device_scale_factor, NULL);

/* build Accept-Language from locale, filtering out encodings */
locales = g_get_language_names();
if (locales) {
guint i, n, length = g_strv_length((gchar **) locales);
gchar **languages = g_new0(gchar *, length);

for (n = 0, i = 0; locales[i]; i++) {
const gchar *lang = locales[i];
if (!strcmp(lang, "C") || !strcmp(lang, "POSIX") || strchr(lang, '.'))
continue;
languages[n++] = g_strdup(lang);
}

webkit_web_context_set_preferred_languages(cog_shell_get_web_context(self->shell),
(const gchar *const *) languages);
g_strfreev(languages);
}

if (s_options.handler_map) {
GHashTableIter i;
void *key, *value;
Expand Down

0 comments on commit d281298

Please sign in to comment.