Skip to content

Commit

Permalink
pkp/pkp-lib#10785 introduce LocaleConversion::toBcp47()
Browse files Browse the repository at this point in the history
  • Loading branch information
bozana committed Feb 5, 2025
1 parent 9585658 commit 5706a84
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions OAIMetadataFormat_JATS.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PKP\core\DataObject;
use PKP\oai\OAIMetadataFormat;
use PKP\db\DAORegistry;
use PKP\i18n\LocaleConversion;
use PKP\submission\Genre;
use PKP\submissionFile\SubmissionFile;
use PKP\plugins\PluginRegistry;
Expand Down Expand Up @@ -195,7 +196,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
$publication = $article->getCurrentPublication();

$articleNode = $xpath->query('//article')->item(0);
$articleNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $article->getData('locale')));
$articleNode->setAttribute('xml:lang', LocaleConversion::toBcp47($article->getData('locale')));
$articleNode->setAttribute('dtd-version', '1.1');
$articleNode->setAttribute('specific-use', 'eps-0.1');
$articleNode->setAttribute('xmlns', 'https://jats.nlm.nih.gov/publishing/1.1/');
Expand Down Expand Up @@ -303,7 +304,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
$titleNode = $this->_addChildInOrder($articleMetaNode, $doc->createElement('issue-title'));
$titleText = $doc->createTextNode($title);
$titleNode->appendChild($titleText);
$titleNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $locale));
$titleNode->setAttribute('xml:lang', LocaleConversion::toBcp47($locale));
}
}

Expand All @@ -313,7 +314,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
$titleGroupNode->removeChild($titleGroupNode->firstChild);
}
$titleNode = $titleGroupNode->appendChild($doc->createElement('article-title'));
$titleNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $article->getData('locale')));
$titleNode->setAttribute('xml:lang', LocaleConversion::toBcp47($article->getData('locale')));

$articleTitleHtml = $doc->createDocumentFragment();
$articleTitleHtml->appendXML(
Expand All @@ -331,7 +332,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
$subtitleHtml->appendXML($this->mapHtmlTagsForTitle($subtitle));

$subtitleNode = $titleGroupNode->appendChild($doc->createElement('subtitle'));
$subtitleNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $article->getData('locale')));
$subtitleNode->setAttribute('xml:lang', LocaleConversion::toBcp47($article->getData('locale')));

$subtitleNode->appendChild($subtitleHtml);
}
Expand All @@ -345,7 +346,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
}

$transTitleGroupNode = $titleGroupNode->appendChild($doc->createElement('trans-title-group'));
$transTitleGroupNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $locale));
$transTitleGroupNode->setAttribute('xml:lang', LocaleConversion::toBcp47($locale));
$titleNode = $transTitleGroupNode->appendChild($doc->createElement('trans-title'));

$titleHtml = $doc->createDocumentFragment();
Expand Down Expand Up @@ -380,7 +381,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
}

$kwdGroupNode = $this->_addChildInOrder($articleMetaNode, $doc->createElement('kwd-group'));
$kwdGroupNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $locale));
$kwdGroupNode->setAttribute('xml:lang', LocaleConversion::toBcp47($locale));
$kwdGroupNode->appendChild($doc->createElement('title'))->appendChild($doc->createTextNode(__('article.subject', [], $locale)));
foreach ($keywords as $keyword) {
$kwdGroupNode->appendChild($doc->createElement('kwd'))->appendChild($doc->createTextNode($keyword));
Expand Down Expand Up @@ -411,7 +412,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
$abstractDoc->loadXML(($isPrimary ? '<abstract>' : '<trans-abstract>') . $purifier->purify($abstract) . ($isPrimary ? '</abstract>' : '</trans-abstract>'));
$abstractNode = $this->_addChildInOrder($articleMetaNode, $doc->importNode($abstractDoc->documentElement, true));
if (!$isPrimary) {
$abstractNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $locale));
$abstractNode->setAttribute('xml:lang', LocaleConversion::toBcp47($locale));
}
}

Expand Down Expand Up @@ -489,7 +490,7 @@ protected function _mungeMetadata($doc, $journal, $article, $section, $issue)
}
$subjGroupNode = $articleCategoriesNode->appendChild($doc->createElement('subj-group'));
$subjGroupNode->setAttribute('subj-group-type', 'heading');
$subjGroupNode->setAttribute('xml:lang', str_replace(['_', '@'], '-', $locale));
$subjGroupNode->setAttribute('xml:lang', LocaleConversion::toBcp47($locale));
$subjectNode = $subjGroupNode->appendChild($doc->createElement('subject'));
$subjectNode->appendChild($doc->createTextNode($title));
}
Expand Down

0 comments on commit 5706a84

Please sign in to comment.