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 29, 2024
1 parent edafaa0 commit 125f665
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions launcher/cog-launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,29 @@ on_automation_started(WebKitWebContext *context, WebKitAutomationSession *sessio
g_signal_connect(session, "create-web-view", G_CALLBACK(on_automation_session_create_web_view), launcher);
}

static void
cog_launcher_set_preferred_languages(CogLauncher *self)
{
const gchar *const *locales;
const gchar **languages;
guint i, n, length;

/* build Accept-Language from locale, filtering out encodings */
locales = g_get_language_names();
length = g_strv_length((gchar **) g_get_language_names());
languages = g_new0(const gchar *, length + 1);

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++] = lang;
}

webkit_web_context_set_preferred_languages(cog_shell_get_web_context(self->shell), languages);
g_free(languages);
}

static void
cog_launcher_startup(GApplication *application)
{
Expand Down Expand Up @@ -318,6 +341,8 @@ cog_launcher_startup(GApplication *application)

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

cog_launcher_set_preferred_languages(self);

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

0 comments on commit 125f665

Please sign in to comment.