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 <wtf/Vector.h> 24#include <wtf/gobject/GUniquePtr.h> 25#include <wtf/text/CString.h> 26#include <wtf/text/WTFString.h> 27 28#include <glib.h> 29#include <locale.h> 30 31namespace WebCore { 32 33// Using pango_language_get_default() here is not an option, because 34// it doesn't support changing the locale in runtime, so it returns 35// always the same value. 36static String platformLanguage() 37{ 38 char* localeDefault = setlocale(LC_CTYPE, NULL); 39 40 if (!localeDefault) 41 return String("c"); 42 43 GUniquePtr<gchar> normalizedDefault(g_ascii_strdown(localeDefault, -1)); 44 char* ptr = strchr(normalizedDefault.get(), '_'); 45 46 if (ptr) 47 *ptr = '-'; 48 49 ptr = strchr(normalizedDefault.get(), '.'); 50 51 if (ptr) 52 *ptr = '\0'; 53 54 return String(normalizedDefault.get()); 55} 56 57Vector<String> platformUserPreferredLanguages() 58{ 59 Vector<String> userPreferredLanguages; 60 userPreferredLanguages.append(platformLanguage()); 61 return userPreferredLanguages; 62} 63 64} 65