1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/language.h"
24 #include "common/gui_options.h"
25 #include "common/str.h"
26
27 namespace Common {
28
29 const LanguageDescription g_languages[] = {
30 { "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA },
31 { "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN },
32 { "hr", "hr_HR", "Croatian", HR_HRV },
33 { "cz", "cs_CZ", "Czech", CZ_CZE },
34 { "nl", "nl_NL", "Dutch", NL_NLD },
35 { "en", "en", "English", EN_ANY }, // Generic English (when only one game version exist)
36 { "gb", "en_GB", "English (GB)", EN_GRB },
37 { "us", "en_US", "English (US)", EN_USA },
38 { "et", "et_EE", "Estonian", ET_EST },
39 { "fr", "fr_FR", "French", FR_FRA },
40 { "de", "de_DE", "German", DE_DEU },
41 { "gr", "el_GR", "Greek", GR_GRE },
42 { "he", "he_IL", "Hebrew", HE_ISR },
43 { "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated
44 { "hu", "hu_HU", "Hungarian", HU_HUN },
45 { "it", "it_IT", "Italian", IT_ITA },
46 { "jp", "ja_JP", "Japanese", JA_JPN },
47 { "kr", "ko_KR", "Korean", KO_KOR },
48 { "lv", "lv_LV", "Latvian", LV_LAT },
49 { "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale
50 { "pl", "pl_PL", "Polish", PL_POL },
51 { "br", "pt_BR", "Portuguese", PT_BRA },
52 { "ru", "ru_RU", "Russian", RU_RUS },
53 { "es", "es_ES", "Spanish", ES_ESP },
54 { "se", "sv_SE", "Swedish", SE_SWE },
55 { 0, 0, 0, UNK_LANG }
56 };
57
parseLanguage(const String & str)58 Language parseLanguage(const String &str) {
59 if (str.empty())
60 return UNK_LANG;
61
62 const LanguageDescription *l = g_languages;
63 for (; l->code; ++l) {
64 if (str.equalsIgnoreCase(l->code))
65 return l->id;
66 }
67
68 return UNK_LANG;
69 }
70
parseLanguageFromLocale(const char * locale)71 Language parseLanguageFromLocale(const char *locale) {
72 if (!locale || !*locale)
73 return UNK_LANG;
74
75 const LanguageDescription *l = g_languages;
76 for (; l->code; ++l) {
77 if (!strcmp(l->unixLocale, locale))
78 return l->id;
79 }
80
81 return UNK_LANG;
82 }
83
getLanguageCode(Language id)84 const char *getLanguageCode(Language id) {
85 const LanguageDescription *l = g_languages;
86 for (; l->code; ++l) {
87 if (l->id == id)
88 return l->code;
89 }
90 return 0;
91 }
92
getLanguageLocale(Language id)93 const char *getLanguageLocale(Language id) {
94 const LanguageDescription *l = g_languages;
95 for (; l->code; ++l) {
96 if (l->id == id)
97 return l->unixLocale;
98 }
99 return 0;
100 }
101
getLanguageDescription(Language id)102 const char *getLanguageDescription(Language id) {
103 const LanguageDescription *l = g_languages;
104 for (; l->code; ++l) {
105 if (l->id == id)
106 return l->description;
107 }
108 return 0;
109 }
110
checkGameGUIOptionLanguage(Language lang,const String & str)111 bool checkGameGUIOptionLanguage(Language lang, const String &str) {
112 if (!str.contains("lang_")) // If no languages are specified
113 return true;
114
115 if (str.contains(getGameGUIOptionsDescriptionLanguage(lang)))
116 return true;
117
118 return false;
119 }
120
getGameGUIOptionsDescriptionLanguage(Language lang)121 const String getGameGUIOptionsDescriptionLanguage(Language lang) {
122 if (lang == UNK_LANG)
123 return "";
124
125 return String("lang_") + getLanguageDescription(lang);
126 }
127
128 } // End of namespace Common
129