Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have to reformat the languages.

MDN says the format is en-US yet this will return en_US.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language

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