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 Dec 5, 2023
1 parent eac92c2 commit f95676a
Show file tree
Hide file tree
Showing 50 changed files with 359 additions and 35 deletions.
84 changes: 82 additions & 2 deletions pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand All @@ -38,6 +39,7 @@
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 @@ -167,8 +169,8 @@ public function initialize($request, $args = [])
$this->galley = $galley;
break;

// In some cases, a URL to a galley may use the ID when it should use
// the urlPath. Redirect to the galley's correct URL.
// In some cases, a URL to a galley may use the ID when it should use
// the urlPath. Redirect to the galley's correct URL.
} elseif (ctype_digit($galleyId) && $galley->getId() == $galleyId) {
$request->redirect(null, $request->getRequestedPage(), $request->getRequestedOp(), [$submission->getBestId(), $galley->getBestGalleyId()]);
}
Expand Down Expand Up @@ -357,6 +359,13 @@ public function view($args, $request)
$templateMgr->assign('purchaseArticleEnabled', true);
}

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

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 @@ -616,4 +625,75 @@ public function userCanViewGalley($request, $articleId, $galleyId = null)
}
return true;
}

/**
* Multilingual publication metadata for template:
* If 0 multilingual metadata options selected, use the default multilingual metadata display
*/
protected function getPublicationMetadata(Publication $publication, string $currentUILocale, array $showMultilingualMetadataOpts, array $showMetadataOpts): array
{
$pubLocaleData = collect($this->getPublicationLocaleData($publication, $currentUILocale, $showMultilingualMetadataOpts, $showMetadataOpts));

if (!empty(count($showMultilingualMetadataOpts))) {
return $pubLocaleData->toArray();
}

// Exclude titles, languages, and titleLocale to get metadata options
$metadataOpts = $pubLocaleData->keys()->diff(['title', 'subtitle', 'fullTitle', 'languages', 'titleLocale']);

// Use getLocalizedData to add metadata in some other language if missing in title's locale
$metadataOpts->each(function (string $opt) use ($pubLocaleData, $publication, $currentUILocale): void {
if (empty(count($pubLocaleData->get($opt)['text']))) {
$locale = $pubLocaleData->get('titleLocale');
$data = $publication->getLocalizedData($opt, $locale, $locale);
$pubLocaleData->when(isset($data), fn ($pld) => $pld->put($opt, [
'text' => [$locale => $data], 'headingLang' => [$locale => $currentUILocale],
]));
}
});

return $pubLocaleData
// Reorder languages to match the order of $metadataOpts
->put('languages', $metadataOpts->map(fn (string $opt): ?string => array_key_first($pubLocaleData->get($opt)['text']))
->filter()->unique()->values())
->put('displayDefault', true)
->toArray();
}

/**
* Multilingual publication metadata for template:
* Default metadata at least includes: full title, title, subtitle, keywords, abstract
* showMultilingualMetadataOpts adds multilingual metadata: title (by default includes fullTitle and subtitle), keywords, abstract, etc.
* showMetadataOpts: additional metadata
*/
protected function getPublicationLocaleData(Publication $publication, string $currentUILocale, array $showMultilingualMetadataOpts, array $showMetadataOpts): array
{
$titles = collect([
'title' => $publication->getTitles('html'),
'subtitle' => $publication->getSubtitles('html'),
'fullTitle' => $publication->getFullTitles('html'),
]);
$defaultMdata = collect(['keywords', 'abstract']);
$metadataOpts = $defaultMdata->concat($showMetadataOpts)
->filter(fn ($opt) => in_array($opt, Services::get('schema')->getMultilingualProps(PKPSchemaService::SCHEMA_PUBLICATION)))
->unique()->diff($titles->keys())->values();
$multilingualOpts = collect($showMultilingualMetadataOpts)
->when(in_array('title', $showMultilingualMetadataOpts), fn ($m) => $m->concat($titles->keys())->unique()->values());
$titleLocale = isset($titles->get('title')[$currentUILocale]) ? $currentUILocale : $publication->getData('locale');

$getText = fn (array $item, string $opt): array => [
$opt => [
'text' => ($text = array_filter($item, fn (string $locale) => $multilingualOpts->contains($opt) || $locale === $titleLocale, ARRAY_FILTER_USE_KEY)),
'headingLang' => collect($text)->map(fn ($_, string $locale): string => $locale === $titleLocale ? $currentUILocale : $locale)
],
];

$pubLocaleData = $titles->mapWithKeys($getText)
->union($metadataOpts->mapWithKeys(fn (string $opt): array => $getText($publication->getData($opt) ?? [], $opt)));
return $pubLocaleData
->put('languages', $pubLocaleData->map(fn (array $item): array => array_keys($item['text']))
->flatten()->sort()->prepend($titleLocale)->unique()->values())
->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 English"

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 " — "
Loading

0 comments on commit f95676a

Please sign in to comment.