Skip to content

Commit

Permalink
Merge pull request #1545 from jyhein/f699
Browse files Browse the repository at this point in the history
pkp/pkp-lib#699 Show locale in url in multilingual contexts
  • Loading branch information
bozana authored Apr 25, 2024
2 parents e42336b + 82ba34c commit 16d5f5b
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Cypress.Commands.add('createSubmissionWithApi', (data, csrfToken) => {
if (typeof data.files === 'undefined' || !data.files.length) {
return;
}
cy.visit('/index.php/publicknowledge/submission?id=' + submissionId);
cy.visit('/index.php/publicknowledge/en/submission?id=' + submissionId);
cy.get('button:contains("Continue")').click();

// Must use the UI to upload files until we upgrade Cypress
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/data/60-content/CallanSubmission.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('Data suite tests', function() {
cy.contains('Bomb Canada and Other Unkind Remarks in the American Media').should('not.exist');
cy.logout();
cy.request({
url: 'index.php/publicknowledge/catalog/book/' + submission.id,
url: 'index.php/publicknowledge/en/catalog/book/' + submission.id,
failOnStatusCode: false
})
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/integration/Doi.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('DOI tests', function() {

cy.log('Check Submission Visibility');
// Select a monograph
cy.visit(`/index.php/publicknowledge/catalog/book/${submissionId}`);
cy.visit(`/index.php/publicknowledge/en/catalog/book/${submissionId}`);

// Monograph DOI
cy.get('div.item.doi')
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/integration/Payments.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Payments', function() {

it('Visit Submission page and check Direct Sales', function () {
cy.login('gfavio');
cy.visit('index.php/publicknowledge/catalog');
cy.visit('index.php/publicknowledge/en/catalog');
cy.get('a').contains('Bomb Canada and Other Unkind Remarks in the American Media').click();
cy.get('a.cmp_download_link').contains('9.99 Purchase PDF (9.99 USD)').should('be.visible').click();
cy.get('p').contains('You could send a message to us.').should('be.visible');
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/integration/Z_MonographViewDCMetadata.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ describe('Monograph View Metadata - DC Plugin', function() {
return cy.submitSubmissionWithApi(submission.id, this.csrfToken);
})
.then(xhr => {
cy.visit('/index.php/publicknowledge/workflow/index/' + submission.id + '/1');
cy.visit('/index.php/publicknowledge/en/workflow/index/' + submission.id + '/1');
});


Expand Down Expand Up @@ -522,7 +522,7 @@ describe('Monograph View Metadata - DC Plugin', function() {
});

it('Tests if Header DC Metadata are present and consistent', function() {
cy.visit('/index.php/publicknowledge/catalog/book/' + submission.urlPath);
cy.visit('/index.php/publicknowledge/en/catalog/book/' + submission.urlPath);

cy.get('meta[name^="DC."]').each((item, index, list) => {
cy.wrap(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Monograph report plugin tests', () => {
const {itemsMax: submissionCount, items: [firstMonograph]} = submissionResponse.body;
const publication = firstMonograph.publications.pop();
expect(reportResponse.headers['content-type']).to.contain('text/comma-separated-values');
expect(reportResponse.body.match(/\/publicknowledge\/workflow\/access\/\d+/g).length).to.equal(submissionCount);
expect(reportResponse.body.match(/\/publicknowledge\/en\/workflow\/access\/\d+/g).length).to.equal(submissionCount);
expect(reportResponse.body).contains(publication.title.en);
for (const author of publication.chapters.flatMap(chapter => Object.values(chapter.authors))) {
expect(reportResponse.body).contains(author.givenName.en);
Expand Down
1 change: 0 additions & 1 deletion pages/user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// Misc.
//
case 'index':
case 'setLocale':
case 'authorizationDenied':
case 'getInterests':
case 'toggleHelp':
Expand Down
6 changes: 2 additions & 4 deletions plugins/blocks/languageToggle/LanguageToggleBlockPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ public function getContents($templateMgr, $request = null)
}
}

if (isset($locales) && count($locales) > 1) {
$templateMgr->assign('enableLanguageToggle', true);
$templateMgr->assign('languageToggleLocales', $locales);
}
$templateMgr->assign('enableLanguageToggle', $locales && count($locales) > 1);
$templateMgr->assign('languageToggleLocales', $locales);

return parent::getContents($templateMgr);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/blocks/languageToggle/templates/block.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ul>
{foreach from=$languageToggleLocales item=localeName key=localeKey}
<li class="locale_{$localeKey|escape}{if $localeKey == $currentLocale} current{/if}" lang="{$localeKey|replace:"_":"-"}">
<a href="{url router=PKPApplication::ROUTE_PAGE page="user" op="setLocale" path=$localeKey source=$smarty.server.REQUEST_URI}">
<a href="{url router=PKPApplication::ROUTE_PAGE page="user" op="setLocale" path=$localeKey}">
{$localeName}
</a>
</li>
Expand Down
8 changes: 4 additions & 4 deletions plugins/generic/dublinCoreMeta/DublinCoreMetaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function monographView($hookName, $args)
}
}

$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->url(null, 'catalog', 'book', [$submissionBestId]) . '"/>');
$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'catalog', 'book', [$submissionBestId], urlLocaleForPage: '') . '"/>');

$templateMgr->addHeader('dublinCoreLanguage', '<meta name="DC.Language" scheme="ISO639-1" content="' . substr($publicationLocale, 0, 2) . '"/>');

Expand All @@ -145,7 +145,7 @@ public function monographView($hookName, $args)
}

$templateMgr->addHeader('dublinCoreSource', '<meta name="DC.Source" content="' . htmlspecialchars($press->getName($press->getPrimaryLocale())) . '"/>');
$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->url($press->getPath()) . '"/>');
$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $press->getPath(), urlLocaleForPage: '') . '"/>');

if ($subjects = $publication->getData('subjects')) {
foreach ($subjects as $locale => $localeSubjects) {
Expand Down Expand Up @@ -276,7 +276,7 @@ public function monographFileView($hookName, $args)
}
}

$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->url(null, 'catalog', 'book', [$submissionBestId, $publicationFormat->getId(), $submissionFile->getId()]) . '"/>');
$templateMgr->addHeader('dublinCoreUri', '<meta name="DC.Identifier.URI" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'catalog', 'book', [$submissionBestId, $publicationFormat->getId(), $submissionFile->getId()], urlLocaleForPage: '') . '"/>');

$templateMgr->addHeader('dublinCoreLanguage', '<meta name="DC.Language" scheme="ISO639-1" content="' . substr($publicationLocale, 0, 2) . '"/>');

Expand All @@ -292,7 +292,7 @@ public function monographFileView($hookName, $args)
$templateMgr->addHeader('dublinCoreIssn', '<meta name="DC.Source.ISSN" content="' . htmlspecialchars($issn) . '"/>');
}

$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->url($press->getPath()) . '"/>');
$templateMgr->addHeader('dublinCoreSourceUri', '<meta name="DC.Source.URI" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $press->getPath(), urlLocaleForPage: '') . '"/>');

if ($subjects = $publication->getData('subjects')) {
foreach ($subjects as $locale => $localeSubjects) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/generic/googleScholar/GoogleScholarPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace APP\plugins\generic\googleScholar;

use APP\core\Application;
use APP\template\TemplateManager;
use PKP\citation\CitationDAO;
use PKP\db\DAORegistry;
Expand Down Expand Up @@ -211,10 +212,10 @@ private function _setFileUrl($availableFile, TemplateManager $templateMgr, int $
{
switch ($availableFile->getData('mimetype')) {
case 'application/pdf':
$templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->url(null, 'catalog', 'download', [$submission->getId(), $availableFile->getData('assocId'), $availableFile->getId()]) . '"/>');
$templateMgr->addHeader('googleScholarPdfUrl' . $i++, '<meta name="citation_pdf_url" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'catalog', 'download', [$submission->getId(), $availableFile->getData('assocId'), $availableFile->getId()], urlLocaleForPage: '') . '"/>');
break;
case 'text/xml' or 'text/html':
$templateMgr->addHeader('googleScholarHtmlUrl' . $i++, '<meta name="citation_fulltext_html_url" content="' . $request->url(null, 'catalog', 'download', [$submission->getId(), $availableFile->getData('assocId'), $availableFile->getId()]) . '"/>');
$templateMgr->addHeader('googleScholarHtmlUrl' . $i++, '<meta name="citation_fulltext_html_url" content="' . $request->getDispatcher()->url($request, Application::ROUTE_PAGE, null, 'catalog', 'download', [$submission->getId(), $availableFile->getData('assocId'), $availableFile->getId()], urlLocaleForPage: '') . '"/>');
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$productNode = $doc->createElementNS($deployment->getNamespace(), 'Product');

$request = Application::get()->getRequest();
$productNode->appendChild($this->_buildTextNode($doc, 'RecordReference', $request->url($context->getPath(), 'monograph', 'view', [$submission->getId()])));
$productNode->appendChild($this->_buildTextNode($doc, 'RecordReference', $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $context->getPath(), 'monograph', 'view', [$submission->getId()], urlLocaleForPage: '')));
$productNode->appendChild($this->_buildTextNode($doc, 'NotificationType', '03'));
$productNode->appendChild($this->_buildTextNode($doc, 'RecordSourceType', '04')); // Bibliographic agency

Expand Down Expand Up @@ -492,7 +492,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$publisherNode->appendChild($websiteNode);

$websiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Publisher's B2C website
$websiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath())));
$websiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $context->getPath(), urlLocaleForPage: '')));

/* --- Publishing Dates --- */

Expand Down Expand Up @@ -672,7 +672,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$supplierNode->appendChild($supplierWebsiteNode);

$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteRole', '18')); // 18 -> Public website
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->url($context->getPath())));
$supplierWebsiteNode->appendChild($this->_buildTextNode($doc, 'WebsiteLink', $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $context->getPath(), urlLocaleForPage: '')));

unset($supplierNode);
unset($supplierWebsiteNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function extractMetadataFromDataObject(&$publicationFormat)
// Identifier: URL
$request = Application::get()->getRequest();
if ($monograph instanceof Submission) {
$dc11Description->addStatement('dc:identifier', $request->url($press->getPath(), 'catalog', 'book', [$publication->getData('urlPath') ?? $monograph->getId()]));
$dc11Description->addStatement('dc:identifier', $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $press->getPath(), 'catalog', 'book', [$publication->getData('urlPath') ?? $monograph->getId()], urlLocaleForPage: ''));
}

// Public identifiers (e.g. DOI, URN)
Expand Down Expand Up @@ -214,7 +214,7 @@ public function extractMetadataFromDataObject(&$publicationFormat)
foreach ($pubFormatFiles as $file) {
{
if ($file->getData('assocId') == $publicationFormat->getData('id')) {
$relation = $request->url($press->getData('urlPath'), 'catalog', 'view', [$publication->getData('urlPath') ?? $monograph->getId(), $publicationFormat->getId(), $file->getId()]);
$relation = $request->getDispatcher()->url($request, Application::ROUTE_PAGE, $press->getData('urlPath'), 'catalog', 'view', [$publication->getData('urlPath') ?? $monograph->getId(), $publicationFormat->getId(), $file->getId()], urlLocaleForPage: '');
$dc11Description->addStatement('dc:relation', $relation);
}
}
Expand Down

0 comments on commit 16d5f5b

Please sign in to comment.