ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

language.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/language.h"
00024 #include "common/gui_options.h"
00025 #include "common/str.h"
00026 
00027 namespace Common {
00028 
00029 const LanguageDescription g_languages[] = {
00030     { "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA },
00031     {    "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN },
00032     {    "hr", "hr_HR", "Croatian", HR_HRV },
00033     {    "cz", "cs_CZ", "Czech", CZ_CZE },
00034     {    "da",    "da", "Danish", DA_DAN },
00035     {    "nl", "nl_NL", "Dutch", NL_NLD },
00036     {    "en",    "en", "English", EN_ANY }, // Generic English (when only one game version exist)
00037     {    "gb", "en_GB", "English (GB)", EN_GRB },
00038     {    "us", "en_US", "English (US)", EN_USA },
00039     {    "et", "et_EE", "Estonian", ET_EST },
00040     {    "fi", "fi_FI", "Finnish", FI_FIN },
00041     {    "fr", "fr_FR", "French", FR_FRA },
00042     {    "de", "de_DE", "German", DE_DEU },
00043     {    "gr", "el_GR", "Greek", GR_GRE },
00044     {    "he", "he_IL", "Hebrew", HE_ISR },
00045     {    "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated
00046     {    "hu", "hu_HU", "Hungarian", HU_HUN },
00047     {    "it", "it_IT", "Italian", IT_ITA },
00048     {    "jp", "ja_JP", "Japanese", JA_JPN },
00049     {    "kr", "ko_KR", "Korean", KO_KOR },
00050     {    "lv", "lv_LV", "Latvian", LV_LAT },
00051     {    "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR },
00052     {    "pl", "pl_PL", "Polish", PL_POL },
00053     {    "br", "pt_BR", "Portuguese (Brazil)", PT_BRA },
00054     {    "pt", "pt_PT", "Portuguese (Portugal)", PT_POR },
00055     {    "ru", "ru_RU", "Russian", RU_RUS },
00056     {    "sk", "sk_SK", "Slovak", SK_SVK },
00057     {    "es", "es_ES", "Spanish", ES_ESP },
00058     {    "se", "sv_SE", "Swedish", SE_SWE },
00059     {    "uk", "uk_UA", "Ukrainian", UA_UKR },
00060     { nullptr, nullptr, nullptr, UNK_LANG }
00061 };
00062 
00063 Language parseLanguage(const String &str) {
00064     if (str.empty())
00065         return UNK_LANG;
00066 
00067     const LanguageDescription *l = g_languages;
00068     for (; l->code; ++l) {
00069         if (str.equalsIgnoreCase(l->code))
00070             return l->id;
00071     }
00072 
00073     return UNK_LANG;
00074 }
00075 
00076 Language parseLanguageFromLocale(const char *locale) {
00077     if (!locale || !*locale)
00078         return UNK_LANG;
00079 
00080     const LanguageDescription *l = g_languages;
00081     for (; l->code; ++l) {
00082         if (!strcmp(l->unixLocale, locale))
00083             return l->id;
00084     }
00085 
00086     return UNK_LANG;
00087 }
00088 
00089 const char *getLanguageCode(Language id) {
00090     const LanguageDescription *l = g_languages;
00091     for (; l->code; ++l) {
00092         if (l->id == id)
00093             return l->code;
00094     }
00095     return nullptr;
00096 }
00097 
00098 const char *getLanguageLocale(Language id) {
00099     const LanguageDescription *l = g_languages;
00100     for (; l->code; ++l) {
00101         if (l->id == id)
00102             return l->unixLocale;
00103     }
00104     return nullptr;
00105 }
00106 
00107 const char *getLanguageDescription(Language id) {
00108     const LanguageDescription *l = g_languages;
00109     for (; l->code; ++l) {
00110         if (l->id == id)
00111             return l->description;
00112     }
00113     return nullptr;
00114 }
00115 
00116 bool checkGameGUIOptionLanguage(Language lang, const String &str) {
00117     if (!str.contains("lang_")) // If no languages are specified
00118         return true;
00119 
00120     if (str.contains(getGameGUIOptionsDescriptionLanguage(lang)))
00121         return true;
00122 
00123     return false;
00124 }
00125 
00126 const String getGameGUIOptionsDescriptionLanguage(Language lang) {
00127     if (lang == UNK_LANG)
00128         return "";
00129 
00130     return String("lang_") + getLanguageDescription(lang);
00131 }
00132 
00133 } // End of namespace Common


Generated on Sat Feb 16 2019 05:00:55 for ResidualVM by doxygen 1.7.1
curved edge   curved edge