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 	{    "ar",    "ar", "Arabic", AR_ARB }, // Modern Standard Arabic
31 	{    "ca", "ca_ES", "Catalan", CA_ESP },
32 	{    "nz",    "nz", "Chinese", ZH_ANY }, // Generic Chinese (when only one game version exist)
33 	{ "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA },
34 	{    "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN },
35 	{    "hr", "hr_HR", "Croatian", HR_HRV },
36 	{    "cz", "cs_CZ", "Czech", CZ_CZE },
37 	{    "da",    "da", "Danish", DA_DAN },
38 	{    "nl", "nl_NL", "Dutch", NL_NLD },
39 	{    "en",    "en", "English", EN_ANY }, // Generic English (when only one game version exist)
40 	{    "gb", "en_GB", "English (GB)", EN_GRB },
41 	{    "us", "en_US", "English (US)", EN_USA },
42 	{    "et", "et_EE", "Estonian", ET_EST },
43 	{    "fi", "fi_FI", "Finnish", FI_FIN },
44 	{    "vl", "nl_BE", "Flemish", NL_BEL },
45 	{    "fr", "fr_FR", "French", FR_FRA },
46 	{    "de", "de_DE", "German", DE_DEU },
47 	{    "gr", "el_GR", "Greek", GR_GRE },
48 	{    "he", "he_IL", "Hebrew", HE_ISR },
49 	{    "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated
50 	{    "hu", "hu_HU", "Hungarian", HU_HUN },
51 	{    "it", "it_IT", "Italian", IT_ITA },
52 	{    "jp", "ja_JP", "Japanese", JA_JPN },
53 	{    "kr", "ko_KR", "Korean", KO_KOR },
54 	{    "lv", "lv_LV", "Latvian", LV_LAT },
55 	{    "nb", "nb_NO", "Norwegian Bokm\xC3\xA5l", NB_NOR },
56 	{    "fa", "fa_IR", "Persian", FA_IRN },
57 	{    "pl", "pl_PL", "Polish", PL_POL },
58 	{    "br", "pt_BR", "Portuguese (Brazil)", PT_BRA },
59 	{    "pt", "pt_PT", "Portuguese (Portugal)", PT_POR },
60 	{    "ru", "ru_RU", "Russian", RU_RUS },
61 	{    "sr", "sr_SP", "Serbian", SR_SER },
62 	{    "sk", "sk_SK", "Slovak", SK_SVK },
63 	{    "es", "es_ES", "Spanish", ES_ESP },
64 	{    "se", "sv_SE", "Swedish", SE_SWE },
65 	{    "tr", "tr_TR", "Turkish", TR_TUR },
66 	{    "uk", "uk_UA", "Ukrainian", UA_UKR },
67 	{ nullptr, nullptr, nullptr, UNK_LANG }
68 };
69 
parseLanguage(const String & str)70 Language parseLanguage(const String &str) {
71 	if (str.empty())
72 		return UNK_LANG;
73 
74 	const LanguageDescription *l = g_languages;
75 	for (; l->code; ++l) {
76 		if (str.equalsIgnoreCase(l->code))
77 			return l->id;
78 	}
79 
80 	return UNK_LANG;
81 }
82 
parseLanguageFromLocale(const char * locale)83 Language parseLanguageFromLocale(const char *locale) {
84 	if (!locale || !*locale)
85 		return UNK_LANG;
86 
87 	const LanguageDescription *l = g_languages;
88 	for (; l->code; ++l) {
89 		if (!strcmp(l->unixLocale, locale))
90 			return l->id;
91 	}
92 
93 	return UNK_LANG;
94 }
95 
getLanguageCode(Language id)96 const char *getLanguageCode(Language id) {
97 	const LanguageDescription *l = g_languages;
98 	for (; l->code; ++l) {
99 		if (l->id == id)
100 			return l->code;
101 	}
102 	return nullptr;
103 }
104 
getLanguageLocale(Language id)105 const char *getLanguageLocale(Language id) {
106 	const LanguageDescription *l = g_languages;
107 	for (; l->code; ++l) {
108 		if (l->id == id)
109 			return l->unixLocale;
110 	}
111 	return nullptr;
112 }
113 
getLanguageDescription(Language id)114 const char *getLanguageDescription(Language id) {
115 	const LanguageDescription *l = g_languages;
116 	for (; l->code; ++l) {
117 		if (l->id == id)
118 			return l->description;
119 	}
120 	return nullptr;
121 }
122 
checkGameGUIOptionLanguage(Language lang,const String & str)123 bool checkGameGUIOptionLanguage(Language lang, const String &str) {
124 	if (!str.contains("lang_")) // If no languages are specified
125 		return true;
126 
127 	if (str.contains(getGameGUIOptionsDescriptionLanguage(lang)))
128 		return true;
129 
130 	return false;
131 }
132 
getGameGUIOptionsDescriptionLanguage(Language lang)133 const String getGameGUIOptionsDescriptionLanguage(Language lang) {
134 	if (lang == UNK_LANG)
135 		return "";
136 
137 	return String("lang_") + getLanguageDescription(lang);
138 }
139 
140 } // End of namespace Common
141