Added a function to get sorted available languages.

This commit is contained in:
King_DuckZ 2013-08-11 18:19:04 +02:00
parent f206a536c8
commit c7bb69e20a
2 changed files with 37 additions and 15 deletions

View file

@ -4,21 +4,22 @@
#include <boost/algorithm/string/trim_all.hpp> #include <boost/algorithm/string/trim_all.hpp>
namespace { namespace {
std::map<std::string, std::string> SupportedLanguages { typedef std::map<std::string, std::string> LanguageMapType;
std::make_pair<std::string, std::string>("ar", "Arabic"), const LanguageMapType SupportedLanguages {
std::make_pair<std::string, std::string>("zh", "Chinese"), std::pair<std::string, std::string>("ar", "Arabic"),
std::make_pair<std::string, std::string>("cz", "Czech"), std::pair<std::string, std::string>("zh", "Chinese"),
std::make_pair<std::string, std::string>("en", "English"), std::pair<std::string, std::string>("cz", "Czech"),
std::make_pair<std::string, std::string>("fr", "French"), std::pair<std::string, std::string>("en", "English"),
std::make_pair<std::string, std::string>("gr", "Greek"), std::pair<std::string, std::string>("fr", "French"),
std::make_pair<std::string, std::string>("it", "Italian"), std::pair<std::string, std::string>("gr", "Greek"),
std::make_pair<std::string, std::string>("ja", "Japanese"), std::pair<std::string, std::string>("it", "Italian"),
std::make_pair<std::string, std::string>("ko", "Korean"), std::pair<std::string, std::string>("ja", "Japanese"),
std::make_pair<std::string, std::string>("pl", "Polish"), std::pair<std::string, std::string>("ko", "Korean"),
std::make_pair<std::string, std::string>("pt", "Portuguese"), std::pair<std::string, std::string>("pl", "Polish"),
std::make_pair<std::string, std::string>("ro", "Romanian"), std::pair<std::string, std::string>("pt", "Portuguese"),
std::make_pair<std::string, std::string>("es", "Spanish"), std::pair<std::string, std::string>("ro", "Romanian"),
std::make_pair<std::string, std::string>("tr", "Turkish") std::pair<std::string, std::string>("es", "Spanish"),
std::pair<std::string, std::string>("tr", "Turkish")
}; };
std::string GetCleanWord (std::string parWord) __attribute__((pure)); std::string GetCleanWord (std::string parWord) __attribute__((pure));
@ -30,6 +31,25 @@ namespace {
} }
} //unnamed namespace } //unnamed namespace
///-----------------------------------------------------------------------------
///-----------------------------------------------------------------------------
void GetAvailableLanguages (std::vector<const std::string*>& parCodes, std::vector<const std::string*>& parNames) {
typedef std::vector<std::pair<const std::string*, const std::string*> > SortedListType;
SortedListType sorted;
sorted.reserve(SupportedLanguages.size());
parCodes.reserve(SupportedLanguages.size());
parNames.reserve(SupportedLanguages.size());
for (LanguageMapType::const_iterator itCurr = SupportedLanguages.begin(), itEND = SupportedLanguages.end(); itCurr != itEND; ++itCurr) {
sorted.push_back(std::make_pair(&itCurr->first, &itCurr->second));
}
std::sort(sorted.begin(), sorted.end(), [](const SortedListType::value_type& parA, const SortedListType::value_type& parB) { return *(parA.second) < *(parB.second); });
for (SortedListType::const_iterator itCurr = sorted.begin(), itEND = sorted.end(); itCurr != itEND; ++itCurr) {
parCodes.push_back(itCurr->first);
parNames.push_back(itCurr->second);
}
}
///----------------------------------------------------------------------------- ///-----------------------------------------------------------------------------
///----------------------------------------------------------------------------- ///-----------------------------------------------------------------------------
ErrBadLanguage::ErrBadLanguage (std::string&& parMessage) : ErrBadLanguage::ErrBadLanguage (std::string&& parMessage) :

View file

@ -6,6 +6,8 @@ enum WordReferenceLangDirection {
WordRefLangTo WordRefLangTo
}; };
void GetAvailableLanguages ( std::vector<const std::string*>& parCodes, std::vector<const std::string*>& parNames );
class ErrBadLanguage : public std::runtime_error { class ErrBadLanguage : public std::runtime_error {
public: public:
ErrBadLanguage ( std::string&& parMessage ); ErrBadLanguage ( std::string&& parMessage );