mirror of https://github.com/kiwix/libkiwix.git
Enter selectMostSuitableLanguage()
This commit is contained in:
parent
69b3e1f8a7
commit
88597e1834
|
@ -128,4 +128,10 @@ UserLangPreferences parseUserLanguagePreferences(const std::string& s)
|
||||||
return {{s, 1}};
|
return {{s, 1}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string selectMostSuitableLanguage(const UserLangPreferences& prefs)
|
||||||
|
{
|
||||||
|
// TOOD: implement properly
|
||||||
|
return prefs[0].lang;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
|
@ -99,6 +99,8 @@ typedef std::vector<LangPreference> UserLangPreferences;
|
||||||
|
|
||||||
UserLangPreferences parseUserLanguagePreferences(const std::string& s);
|
UserLangPreferences parseUserLanguagePreferences(const std::string& s);
|
||||||
|
|
||||||
|
std::string selectMostSuitableLanguage(const UserLangPreferences& prefs);
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
||||||
#endif // KIWIX_SERVER_I18N
|
#endif // KIWIX_SERVER_I18N
|
||||||
|
|
|
@ -227,7 +227,8 @@ std::string RequestContext::determine_user_language() const
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const std::string acceptLanguage = get_header("Accept-Language");
|
const std::string acceptLanguage = get_header("Accept-Language");
|
||||||
return parseUserLanguagePreferences(acceptLanguage)[0].lang;
|
const auto userLangPrefs = parseUserLanguagePreferences(acceptLanguage);
|
||||||
|
return selectMostSuitableLanguage(userLangPrefs);
|
||||||
} catch(const std::out_of_range&) {}
|
} catch(const std::out_of_range&) {}
|
||||||
|
|
||||||
return "en";
|
return "en";
|
||||||
|
|
Loading…
Reference in New Issue