Debian Codegraph @

src/ws/cockpitlocale.c

raw
1 /*
2 * Copyright (C) 2016 Red Hat, Inc.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 #include "config.h"
7
8 /* This gets logged as part of the (more verbose) protocol logging */
9 #ifdef G_LOG_DOMAIN
10 #undef G_LOG_DOMAIN
11 #endif
12 #define G_LOG_DOMAIN "cockpit-protocol"
13
14 #include "cockpitlocale.h"
15 #include "cockpitsystem.h"
16
17 #include <locale.h>
18 #include <string.h>
19
20 gchar *
21 cockpit_locale_from_language (const gchar *value,
22 const gchar *encoding,
23 gchar **shorter)
24 {
25 const gchar *spot;
26 gchar *country = NULL;
27 gchar *lang = NULL;
28 gchar *result = NULL;
29 const gchar *dot;
30
31 if (value == NULL)
32 value = "C";
33
34 dot = ".";
35 if (!encoding)
36 dot = encoding = "";
37
38 spot = strchr (value, '-');
39 if (spot)
40 {
41 country = g_ascii_strup (spot + 1, -1);
42 lang = g_ascii_strdown (value, spot - value);
43 result = g_strconcat (lang, "_", country, dot, encoding, NULL);
44 if (shorter)
45 {
46 *shorter = lang;
47 lang = NULL;
48 }
49 }
50 else
51 {
52 result = g_strconcat (value, dot, encoding, NULL);
53 if (shorter)
54 *shorter = g_strdup (value);
55 }
56
57 g_free (country);
58 g_free (lang);
59 return result;
60 }