Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concept type translations for autocomplete search #1631

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resource/js/vocab-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const vocabSearch = Vue.createApp({
return null
},
translateType (type) {
return window.SKOSMOS.msgs[window.SKOSMOS.lang][type]
return window.SKOSMOS.typeTranslations[type]
},
/*
* renderResults is used when the search string has been indexed in the cache
Expand Down
46 changes: 41 additions & 5 deletions src/controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function invokeLandingPage($request)
$sortedVocabs = $this->model->getVocabularyList(false, true);
$langList = $this->model->getLanguages($request->getLang());
$listStyle = $this->listStyle();
$typeTranslations = $this->getConceptTypeTranslations($request);

// render template
echo $template->render(
Expand All @@ -159,7 +160,8 @@ public function invokeLandingPage($request)
'languages' => $this->languages,
'lang_list' => $langList,
'request' => $request,
'list_style' => $listStyle
'list_style' => $listStyle,
'conceptTypeTranslations' => $typeTranslations,
)
);
}
Expand Down Expand Up @@ -190,6 +192,7 @@ public function invokeVocabularyConcept(Request $request)

$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());
$template = $this->twig->load('concept.twig');
$typeTranslations = $this->getConceptTypeTranslations($request);

$crumbs = $vocab->getBreadCrumbs($request->getContentLang(), $uri);
echo $template->render(
Expand All @@ -203,7 +206,9 @@ public function invokeVocabularyConcept(Request $request)
'hidden_breadcrumbs' => $crumbs['combined'],
'request' => $request,
'plugin_params' => $pluginParameters,
'custom_labels' => $customLabels)
'custom_labels' => $customLabels,
'conceptTypeTranslations' => $typeTranslations,
)
);
}

Expand Down Expand Up @@ -341,7 +346,9 @@ public function invokeGlobalSearch($request)
$lang = $request->getLang();
$template = $this->twig->load('global-search.twig');
$this->model->setLocale($request->getLang());

$typeTranslations = $this->getConceptTypeTranslations($request);
error_log('testataan');
error_log($typeTranslations);
$parameters = new ConceptSearchParameters($request, $this->model->getConfig());

$vocabs = $request->getQueryParam('vocabs'); # optional
Expand Down Expand Up @@ -398,7 +405,8 @@ public function invokeGlobalSearch($request)
'vocab_list' => $vocabList,
'sorted_vocabs' => $sortedVocabs,
'request' => $request,
'parameters' => $parameters
'parameters' => $parameters,
'conceptTypeTranslations' => $typeTranslations,
)
);
}
Expand All @@ -412,6 +420,8 @@ public function invokeVocabularySearch($request)
$this->model->setLocale($request->getLang());
$vocab = $request->getVocab();
$searchResults = null;
$typeTranslations = $this->getConceptTypeTranslations($request);

try {
$vocabTypes = $this->model->getTypes($request->getVocabid(), $request->getLang());
} catch (Exception $e) {
Expand Down Expand Up @@ -472,6 +482,7 @@ public function invokeVocabularySearch($request)
'types' => $vocabTypes,
'explicit_langcodes' => $langcodes,
'request' => $request,
'conceptTypeTranslations' => $typeTranslations,
)
);
}
Expand All @@ -496,6 +507,7 @@ public function invokeVocabularyHome($request)
$pluginParameters = json_encode($vocab->getConfig()->getPluginParameters());

$template = $this->twig->load('vocab-home.twig');
$typeTranslations = $this->getConceptTypeTranslations($request);

echo $template->render(
array(
Expand All @@ -504,11 +516,35 @@ public function invokeVocabularyHome($request)
'search_letter' => 'A',
'active_tab' => $defaultView,
'request' => $request,
'plugin_params' => $pluginParameters
'plugin_params' => $pluginParameters,
'conceptTypeTranslations' => $typeTranslations,
)
);
}
/**
* Get the translation strings to be displayed in the autocomplete search results
*/
private function getConceptTypeTranslations($request)
{
$vocid = $request->getVocab() ? $request->getVocab()->getId() : null;
if ($vocid === null && !$request->getLang()) {
return $this->returnError(400, "Bad Request", "lang parameter missing");
}
if ($this->notModified($request->getVocab())) {
return null;
}

$this->model->setLocale($request->getLang());
$queriedtypes = $this->model->getTypes($vocid, $request->getLang());
$types = array();

foreach ($queriedtypes as $uri => $typedata) {
if ($typedata['label']) {
$types[$uri] = $typedata['label'];
}
}
return json_encode($types, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
/**
* Invokes a very generic errorpage.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/view/scripts.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ window.SKOSMOS = {
"pluginCallbacks": [{% for function in request.plugins.callbacks %}{% if not loop.first %}, {% endif %}"{{ function }}"{% endfor %}],
{%- endif ~%}
"baseHref": "{{ BaseHref }}",
{%~ if conceptTypeTranslations %}
"typeTranslations": {{ conceptTypeTranslations|raw }},
{%- endif ~%}
"language_strings": { "fi": { "fi": "suomi",
"en": "englanti",
"se": "pohjoissaame",
Expand Down
Loading