mirror of https://github.com/kiwix/libkiwix.git
Moved user language preferences into i18n.{h,cpp}
This commit is contained in:
parent
669d8898ac
commit
69b3e1f8a7
|
@ -111,4 +111,21 @@ std::string ParameterizedMessage::getText(const std::string& lang) const
|
||||||
return i18n::expandParameterizedString(lang, msgId, params);
|
return i18n::expandParameterizedString(lang, msgId, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UserLangPreferences parseUserLanguagePreferences(const std::string& s)
|
||||||
|
{
|
||||||
|
// TODO: implement properly
|
||||||
|
const UserLangPreferences defaultPref{{"en", 1}};
|
||||||
|
|
||||||
|
if ( s.empty() )
|
||||||
|
return defaultPref;
|
||||||
|
|
||||||
|
for ( const char c : s ) {
|
||||||
|
if ( ! std::isalpha(c) ) {
|
||||||
|
return defaultPref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {{s, 1}};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
|
@ -89,6 +89,16 @@ private: // data
|
||||||
const Parameters params;
|
const Parameters params;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LangPreference
|
||||||
|
{
|
||||||
|
const std::string lang;
|
||||||
|
const float preference;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<LangPreference> UserLangPreferences;
|
||||||
|
|
||||||
|
UserLangPreferences parseUserLanguagePreferences(const std::string& s);
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
||||||
#endif // KIWIX_SERVER_I18N
|
#endif // KIWIX_SERVER_I18N
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
#include "tools/stringTools.h"
|
#include "tools/stringTools.h"
|
||||||
|
#include "i18n.h"
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
|
@ -64,31 +65,6 @@ fullURL2LocalURL(const std::string& full_url, const std::string& rootLocation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LangPreference
|
|
||||||
{
|
|
||||||
const std::string lang;
|
|
||||||
const float preference;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<LangPreference> UserLangPreferences;
|
|
||||||
|
|
||||||
UserLangPreferences parseUserLanguagePreferences(const std::string& s)
|
|
||||||
{
|
|
||||||
// TODO: implement properly
|
|
||||||
const UserLangPreferences defaultPref{{"en", 1}};
|
|
||||||
|
|
||||||
if ( s.empty() )
|
|
||||||
return defaultPref;
|
|
||||||
|
|
||||||
for ( const char c : s ) {
|
|
||||||
if ( ! std::isalpha(c) ) {
|
|
||||||
return defaultPref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {{s, 1}};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
RequestContext::RequestContext(struct MHD_Connection* connection,
|
RequestContext::RequestContext(struct MHD_Connection* connection,
|
||||||
|
|
Loading…
Reference in New Issue