-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a general utility which other ports can get use of. Added tests
- Loading branch information
Showing
6 changed files
with
124 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "tools.h" | ||
#include "stringTools.h" | ||
#include <mutex> | ||
|
||
namespace kiwix | ||
{ | ||
|
||
namespace | ||
{ | ||
|
||
// These mappings are not provided by the ICU library, any such mappings can be manually added here | ||
std::map<std::string, std::string> iso639_3 = { | ||
{"atj", "atikamekw"}, | ||
{"azb", "آذربایجان دیلی"}, | ||
{"bcl", "central bikol"}, | ||
{"bgs", "tagabawa"}, | ||
{"bxr", "буряад хэлэн"}, | ||
{"cbk", "chavacano"}, | ||
{"cdo", "閩東語"}, | ||
{"dag", "Dagbani"}, | ||
{"diq", "dimli"}, | ||
{"dty", "डोटेली"}, | ||
{"eml", "emiliân-rumagnōl"}, | ||
{"fbs", "српскохрватски"}, | ||
{"guw", "Gungbe"}, | ||
{"hbs", "srpskohrvatski"}, | ||
{"ido", "ido"}, | ||
{"kbp", "kabɩyɛ"}, | ||
{"kld", "Gamilaraay"}, | ||
{"lbe", "лакку маз"}, | ||
{"lbj", "ལ་དྭགས་སྐད་"}, | ||
{"map", "Austronesian"}, | ||
{"mhr", "марий йылме"}, | ||
{"mnw", "ဘာသာမန်"}, | ||
{"myn", "mayan"}, | ||
{"nah", "nahuatl"}, | ||
{"nai", "north American Indian"}, | ||
{"nds", "plattdütsch"}, | ||
{"nrm", "bhasa narom"}, | ||
{"olo", "livvi"}, | ||
{"pih", "Pitcairn-Norfolk"}, | ||
{"pnb", "Western Panjabi"}, | ||
{"rmr", "Caló"}, | ||
{"rmy", "romani shib"}, | ||
{"roa", "romance languages"}, | ||
{"twi", "twi"}, | ||
}; | ||
|
||
std::once_flag fillLanguagesFlag; | ||
|
||
void fillLanguagesMap() | ||
{ | ||
for (auto icuLangPtr = icu::Locale::getISOLanguages(); *icuLangPtr != NULL; ++icuLangPtr) { | ||
const kiwix::ICULanguageInfo lang(*icuLangPtr); | ||
iso639_3.insert({lang.iso3Code(), lang.selfName()}); | ||
} | ||
} | ||
|
||
} // unnamed namespace | ||
|
||
std::string getLanguageSelfName(const std::string& lang) | ||
{ | ||
std::call_once(fillLanguagesFlag, fillLanguagesMap); | ||
if (lang == "") | ||
return "und"; | ||
const auto itr = iso639_3.find(lang); | ||
if (itr != iso639_3.end()) { | ||
return itr->second; | ||
} | ||
return lang; | ||
}; | ||
|
||
} // namespace kiwix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2023 Nikhil Tanwar (2002nikhiltanwar@gmail.com) | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but | ||
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and | ||
* NON-INFRINGEMENT. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
#include "../include/tools.h" | ||
|
||
namespace | ||
{ | ||
|
||
TEST(LanguageToolsTest, englishTest) | ||
{ | ||
EXPECT_EQ(kiwix::getLanguageSelfName("eng"), "English"); | ||
} | ||
|
||
TEST(LanguageToolsTest, manualValuesTest) | ||
{ | ||
EXPECT_EQ(kiwix::getLanguageSelfName("dty"), "डोटेली"); | ||
} | ||
|
||
TEST(LanguageToolsTest, emptyStringTest) | ||
{ | ||
EXPECT_EQ(kiwix::getLanguageSelfName(""), "und"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters