1 /*
2 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "Language.h"
22
23 #include "GOwnPtr.h"
24 #include "PlatformString.h"
25 #include <wtf/text/CString.h>
26
27 #include <glib.h>
28 #include <locale.h>
29
30 namespace WebCore {
31
32 // Using pango_language_get_default() here is not an option, because
33 // it doesn't support changing the locale in runtime, so it returns
34 // always the same value.
platformDefaultLanguage()35 String platformDefaultLanguage()
36 {
37 char* localeDefault = setlocale(LC_CTYPE, NULL);
38
39 if (!localeDefault)
40 return String("c");
41
42 GOwnPtr<gchar> normalizedDefault(g_ascii_strdown(localeDefault, -1));
43 char* ptr = strchr(normalizedDefault.get(), '_');
44
45 if (ptr)
46 *ptr = '-';
47
48 ptr = strchr(normalizedDefault.get(), '.');
49
50 if (ptr)
51 *ptr = '\0';
52
53 return String(normalizedDefault.get());
54 }
55
56 }
57