mirror of https://github.com/kiwix/libkiwix.git
User language control via userlang query param
This is a draft commit enabling the testing of the support for kiwix-serve internationalization.
This commit is contained in:
parent
507e111f34
commit
e4a0a029ff
|
@ -443,11 +443,11 @@ SuggestionsList_t getSuggestions(SuggestionSearcherCache& cache, const zim::Arch
|
|||
namespace
|
||||
{
|
||||
|
||||
std::string makeFulltextSearchSuggestion(const std::string& queryString)
|
||||
std::string makeFulltextSearchSuggestion(const std::string& lang, const std::string& queryString)
|
||||
{
|
||||
MustacheData data;
|
||||
data.set("SEARCH_TERMS", queryString);
|
||||
const std::string tmpl = getTranslatedString("en", "suggest-full-text-search");
|
||||
const std::string tmpl = getTranslatedString(lang, "suggest-full-text-search");
|
||||
return render_template(tmpl, data);
|
||||
}
|
||||
|
||||
|
@ -523,7 +523,8 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
|||
/* Propose the fulltext search if possible */
|
||||
if (archive->hasFulltextIndex()) {
|
||||
MustacheData result;
|
||||
result.set("label", makeFulltextSearchSuggestion(queryString));
|
||||
const auto lang = request.get_user_language();
|
||||
result.set("label", makeFulltextSearchSuggestion(lang, queryString));
|
||||
result.set("value", queryString + " ");
|
||||
result.set("kind", "pattern");
|
||||
result.set("first", first);
|
||||
|
|
|
@ -193,4 +193,9 @@ std::string RequestContext::get_query() const {
|
|||
return q;
|
||||
}
|
||||
|
||||
std::string RequestContext::get_user_language() const
|
||||
{
|
||||
return get_optional_param<std::string>("userlang", "en");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -94,6 +94,8 @@ class RequestContext {
|
|||
|
||||
bool can_compress() const { return acceptEncodingDeflate; }
|
||||
|
||||
std::string get_user_language() const;
|
||||
|
||||
private: // data
|
||||
std::string full_url;
|
||||
std::string url;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"@metadata": {
|
||||
"authors": [
|
||||
]
|
||||
},
|
||||
"name":"Հայերեն",
|
||||
"suggest-full-text-search": "որոնել '{{{SEARCH_TERMS}}}'..."
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
i18n/en.json
|
||||
i18n/hy.json
|
||||
|
|
|
@ -12,9 +12,10 @@ jq(document).ready(() => {
|
|||
? (new URLSearchParams(window.location.search)).get('content')
|
||||
: window.location.pathname.split(`${root}/`)[1].split('/')[0];
|
||||
|
||||
const userlang = (new URLSearchParams(window.location.search)).get('userlang') || "en";
|
||||
$( "#kiwixsearchbox" ).autocomplete({
|
||||
|
||||
source: `${root}/suggest?content=${bookName}`,
|
||||
source: `${root}/suggest?content=${bookName}&userlang=${userlang}`,
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
|
||||
|
|
|
@ -1182,6 +1182,17 @@ R"EXPECTEDRESPONSE([
|
|||
//EOLWHITESPACEMARKER
|
||||
}
|
||||
]
|
||||
)EXPECTEDRESPONSE"
|
||||
},
|
||||
{ /* url: */ "/ROOT/suggest?content=zimfile&term=abracadabra&userlang=hy",
|
||||
R"EXPECTEDRESPONSE([
|
||||
{
|
||||
"value" : "abracadabra ",
|
||||
"label" : "որոնել 'abracadabra'...",
|
||||
"kind" : "pattern"
|
||||
//EOLWHITESPACEMARKER
|
||||
}
|
||||
]
|
||||
)EXPECTEDRESPONSE"
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue