Skip to content

Commit

Permalink
Simultaneously Displaying Multilingual Metadata on the Article Landin…
Browse files Browse the repository at this point in the history
…g Page
  • Loading branch information
jyhein committed Apr 29, 2024
1 parent 3cdeadf commit 7d7cde1
Show file tree
Hide file tree
Showing 51 changed files with 381 additions and 34 deletions.
56 changes: 56 additions & 0 deletions pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@
use APP\observers\events\UsageEvent;
use APP\payment\ojs\OJSCompletedPaymentDAO;
use APP\payment\ojs\OJSPaymentManager;
use APP\publication\Publication;
use APP\security\authorization\OjsJournalMustPublishPolicy;
use APP\submission\Submission;
use APP\template\TemplateManager;
use Firebase\JWT\Key;
use PKP\citation\CitationDAO;
use PKP\config\Config;
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\core\PKPJwt as JWT;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\Validation;
use PKP\services\PKPSchemaService;
use PKP\submission\Genre;
use PKP\submission\GenreDAO;
use PKP\submission\PKPSubmission;
Expand Down Expand Up @@ -356,6 +360,13 @@ public function view($args, $request)
$templateMgr->assign('purchaseArticleEnabled', true);
}

$templateMgr->assign('pubLocaleData', $this->getPublicationLocaleData(
$publication,
$templateMgr->getTemplateVars('currentLocale'),
$templateMgr->getTemplateVars('activeTheme')->getOption('showMultilingualMetadata') ?: [],
$context
));

if (!Hook::call('ArticleHandler::view', [&$request, &$issue, &$article, $publication])) {
$templateMgr->display('frontend/pages/article.tpl');
event(new UsageEvent(Application::ASSOC_TYPE_SUBMISSION, $context, $article, null, null, $this->issue));
Expand Down Expand Up @@ -615,4 +626,49 @@ public function userCanViewGalley($request, $articleId, $galleyId = null)
}
return true;
}

/**
* Multilingual publication metadata for template:
* showMultilingualMetadataOpts - Show metadata in other languages: title (by default includes fullTitle and subtitle), keywords, abstract, etc.
*/
protected function getPublicationLocaleData(Publication $publication, string $currentUILocale, array $showMultilingualMetadataOpts, Context $context): array
{
$submissionLocale = $publication->getData('locale');
$titles = collect([
'title' => $publication->getTitles('html'),
'subtitle' => $publication->getSubtitles('html'),
'fullTitle' => $publication->getFullTitles('html'),
]);
$multilingualProps = collect(Services::get('schema')->getMultilingualProps(PKPSchemaService::SCHEMA_PUBLICATION))->diff($titles->keys());
$multilingualOpts = collect($showMultilingualMetadataOpts)
->when(in_array('title', $showMultilingualMetadataOpts), fn ($m) => $m->concat($titles->keys())->unique()->values());
$titleLocale = isset($titles->get('title')[$currentUILocale]) ? $currentUILocale : $submissionLocale;
$uiLocales = collect($context->getSupportedLocaleNames());
$localeShowOrder = collect([$titleLocale, $currentUILocale, $submissionLocale])->concat($uiLocales->keys())->unique()->values();

$getText = fn (array $item, string $opt): array => [
$opt => [
// Select 1 text to show in some locale if not in $multilingualOpts
'text' => ($text = $multilingualOpts->contains($opt)
? $item
: collect($item)->only([$localeShowOrder->concat(array_keys($item))->first(fn (string $l) => isset($item[$l]))])->toArray()),
// Show headings in supported ui locale if possible
'hLang' => collect($text)->map(fn ($_, string $locale): string => ($locale === $titleLocale || !$uiLocales->has($locale)) ? $currentUILocale : $locale)
],
];

$pubLocaleData = $titles->mapWithKeys($getText)
->union($multilingualProps->mapWithKeys(fn (string $opt): array => ($data = $publication->getData($opt)) ? $getText($data, $opt) : []))
->filter();
$metadataLocales = $pubLocaleData->map(fn (array $item): array => array_keys($item['text']))->flatten()->unique()->sort()->values();
return $pubLocaleData
->put('locales', $localeShowOrder
->intersect($metadataLocales) // Remove ui locales not in $metadataLocales
->concat($metadataLocales) // Show rest locales in alphabetical order
->unique()
->values())
->put('localeNames', $uiLocales->map(fn ($_, string $l): array => Locale::getSubmissionLocaleDisplayNames($metadataLocales->toArray(), $l)))
->put('titleLocale', $titleLocale)
->toArray();
}
}
20 changes: 20 additions & 0 deletions plugins/themes/default/DefaultThemePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ public function init()
'default' => 'none',
]);

$this->addOption('showMultilingualMetadata', 'FieldOptions', [
'label' => __('plugins.themes.default.option.metadata.label'),
'description' => __('plugins.themes.default.option.metadata.description'),
'options' => [
[
'value' => 'title',
'label' => __('submission.title'),
],
[
'value' => 'keywords',
'label' => __('common.keywords'),
],
[
'value' => 'abstract',
'label' => __('common.abstract'),
],
],
'default' => [],
]);


// Load primary stylesheet
$this->addStyle('stylesheet', 'styles/index.less');
Expand Down
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ar/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ msgstr "التنزيلات"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "تنزيل البيانات ليس متاحًا بعد."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/az/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ msgid "plugins.themes.default.option.useHomepageImageAsHeader.description"
msgstr ""
"Bir ana səhifə şəkli yükləndiyində, ana səhifədəki normal başlıq yerinə "
"başlığın arxa planında baxın."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/bg/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ msgstr "Сваляния"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Данните за свалянията все още не са налични."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/bs/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ca/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ msgstr "Descàrregues"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Les dades de descàrrega encara no estan disponibles."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ckb/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/cs/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Stažení"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Údaje o počtu stažení nejsou zatím k dispozici."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/da/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Downloads"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Download-data er endnu ikke tilgængelige."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/de/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ msgstr "Downloads"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Download-Daten sind nocht nicht verfügbar."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/el/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ msgstr ""
msgid "plugins.themes.default.option.displayStats.none"
msgstr ""
"Να μην εμφανίζονται στατιστικά στοιχεία χρήσης υποβολής για τον αναγνώστη."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
12 changes: 12 additions & 0 deletions plugins/themes/default/locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ msgstr "Next slide"

msgid "plugins.themes.default.prevSlide"
msgstr "Previous slide"

msgid "plugins.themes.default.option.metadata.label"
msgstr "Show article metadata on the article landing page"

msgid "plugins.themes.default.option.metadata.description"
msgstr "Select the article metadata to show in other languages."

msgid "plugins.themes.default.submissionMetadataInLanguage"
msgstr "Article Metadata in {$inlang}"

msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/es/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Descargas"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Los datos de descarga aún no están disponibles."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/es_MX/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ msgstr "Descargas"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Los datos de descarga aún no están disponibles."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/fa/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ msgstr "دانلودها"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "دسترسی به دانلود اطلاعات مقدور نیست."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/fi/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ msgstr "Lataukset"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Lataustiedot eivät ole vielä saatavilla."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/fr_CA/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ msgstr "Les données de téléchargement ne sont pas encore disponible."

#~ msgid "plugins.themes.default.option.showDescriptionInJournalIndex.label"
#~ msgstr "Description de la revue"

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/fr_FR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/gl/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/hu/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/hy/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ msgstr "Ներբեռնումներ"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Ներբեռնման տվյալները դեռ հասանելի չեն:"

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/id/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ msgstr "Unduhan"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Data unduhan tidak tersedia."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/it/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ msgstr "Downloads"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "La data di download non è ancora disponibile."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ja/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ka/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/kk/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ko/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/lv/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Lejupielādes"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Lejupielādes dati vēl nav pieejami."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/mk/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ msgstr "Превземања"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Податоците за превземање не се сè уште достапни."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/ms/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ msgstr "Muat turun"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Muat turun data belum tersedia."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/nb/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Nedlastinger"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Nedlastingsdata er foreløpig ikke tilgjengelig."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/nl/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ msgstr ""

msgid "plugins.themes.default.displayStats.noStats"
msgstr ""

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/pl/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ msgstr "Pobrania"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Statystyki pobrań niedostępne."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Downloads"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Os dados de download ainda não estão disponíveis."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
4 changes: 4 additions & 0 deletions plugins/themes/default/locale/pt_PT/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,7 @@ msgstr "Downloads"

msgid "plugins.themes.default.displayStats.noStats"
msgstr "Os dados de download ainda não estão disponíveis."

#, fuzzy
msgid "plugins.themes.default.titleSubtitleSeparator"
msgstr " — "
Loading

0 comments on commit 7d7cde1

Please sign in to comment.