Enter selectMostSuitableLanguage()

This commit is contained in:
Veloman Yunkan 2022-11-29 12:54:45 +04:00 committed by Matthieu Gautier
parent 69b3e1f8a7
commit 88597e1834
3 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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";