1 /* LanguageUtils.h */ 2 3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras) 4 * 5 * This file is part of sayonara player 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (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, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef LANGUAGEUTILS_H 22 #define LANGUAGEUTILS_H 23 24 #include "Utils/Macros.h" 25 26 class QString; 27 class QStringList; 28 class QLocale; 29 30 template<typename A, typename B> 31 class QMap; 32 33 namespace Util 34 { 35 /** 36 * @brief language namespace 37 * @ingroup Language 38 */ 39 namespace Language 40 { 41 /** 42 * @brief get the complete path to a language file out of the share directory 43 * @ingroup Language 44 * @param fourLetter 45 * @return 46 */ 47 QString getSharePath(const QString& fourLetter); 48 49 /** 50 * @brief get the complete path to a language file out of the ftp directory 51 * @ingroup Language 52 * @param fourLetter 53 * @return 54 */ 55 QString getFtpPath(const QString& fourLetter); 56 57 /** 58 * @brief get the complete http url to a language file 59 * @ingroup Language 60 * @param fourLetter 61 * @return 62 */ 63 QString getHttpPath(const QString& fourLetter); 64 65 /** 66 * @brief Returns the path where checksums can be fetched from 67 * @ingroup Language 68 * @return ftp url 69 */ 70 QString getChecksumFtpPath(); 71 72 /** 73 * @brief Returns the path where checksums can be fetched from 74 * @ingroup Language 75 * @return http url 76 */ 77 QString getChecksumHttpPath(); 78 79 /** 80 * @brief get_home_target_path 81 * @ingroup Language 82 * @param fourLetter 83 * @return 84 */ 85 QString getHomeTargetPath(const QString& fourLetter); 86 87 /** 88 * @brief Returns the correct language file either from share dir 89 * or home dir 90 * @ingroup Language 91 * @param fourLetter language code 92 * @return path to qm language file 93 */ 94 QString getUsedLanguageFile(const QString& fourLetter); 95 96 /** 97 * @brief Returns the icon path in share directory 98 * @ingroup Language 99 * @param fourLetter language code 100 * @return 101 */ 102 QString getIconPath(const QString& fourLetter); 103 104 /** 105 * @brief Extracts the language Code out of a sayonara_lang string 106 * @ingroup Language 107 * @param language_file filename containing sayonara_lang 108 * @return four or two letter code 109 */ 110 QString extractLanguageCode(const QString& languageFile); 111 112 /** 113 * @brief calculates the checksum for the currently used language 114 * file (either home or share directory) 115 * @ingroup Language 116 * @param fourLetter language code 117 * @return md5 checksum 118 */ 119 QString getChecksum(const QString& fourLetter); 120 121 /** 122 * @brief Get the language version out of translations/versions file 123 * in home dir 124 * @ingroup Language 125 * @param fourLetter language code 126 * @return Sayonara version where the file belongs to 127 */ 128 QString getLanguageVersion(const QString& fourLetter); 129 130 /** 131 * @brief Update language version in translations/versions file 132 * to current Sayonara Version 133 * @ingroup Language 134 * @param fourLetter 135 */ 136 void updateLanguageVersion(const QString& fourLetter); 137 138 /** 139 * @brief Returns if the language version in translations/versions 140 * file is smaller than the current sayonara version 141 * @ingroup Language 142 * @param fourLetter 143 * @return false if Sayonara Version <= Language version, true else 144 */ 145 bool isOutdated(const QString& fourLetter); 146 147 /** 148 * @brief get_similar_language_4 149 * @ingroup Language 150 * @param fourLetter language code 151 * @return four letter code if there's a language from another region, 152 * empty string else 153 */ 154 QString getSimilarLanguage4(const QString& fourLetter); 155 156 /** 157 * @brief get the current selected locale based on the current language file 158 * @return 159 */ 160 QLocale getCurrentLocale(); 161 162 /** 163 * @brief get all qt paths which include translations 164 * @return 165 */ 166 QStringList getCurrentQtTranslationPaths(); 167 168 /** 169 * @brief Imports a qm file. The filename must contain a valid four 170 * or two letter code 171 * @param filename 172 * @return true, if the filename matches the pattern 173 */ 174 bool importLanguageFile(const QString& filename); 175 176 177 /** 178 * @brief Converts two letter into four letter 179 * @param two letter language filename 180 * @return four letter key if available, en_GB per default 181 */ 182 QString convertOldLanguage(const QString& languageCode); 183 184 185 /** 186 * @brief Returns all languages located in user path and all 187 * languages in sayonara path 188 * @return map with four letter key as key and the locale as value 189 */ 190 QMap<QString, QLocale> availableLanguages(); 191 192 #ifdef SAYONARA_WITH_TESTS 193 void setTestMode(); 194 void setLanguageVersion(const QString& fourLetter, const QString& version); 195 #endif 196 } 197 } 198 199 #endif // LANGUAGEUTILS_H 200