本文整理汇总了PHP中AppLocale::getLocaleFrom3LetterIso方法的典型用法代码示例。如果您正苦于以下问题:PHP AppLocale::getLocaleFrom3LetterIso方法的具体用法?PHP AppLocale::getLocaleFrom3LetterIso怎么用?PHP AppLocale::getLocaleFrom3LetterIso使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppLocale
的用法示例。
在下文中一共展示了AppLocale::getLocaleFrom3LetterIso方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translateLanguageToLocale
/**
* Try to translate an ISO language code to an OJS locale.
* @param $language string 2- or 3-letter ISO language code
* @return string|null An OJS locale or null if no matching
* locale could be found.
*/
function translateLanguageToLocale($language)
{
$locale = null;
if (strlen($language) == 2) {
$language = AppLocale::get3LetterFrom2LetterIsoLanguage($language);
}
if (strlen($language) == 3) {
$language = AppLocale::getLocaleFrom3LetterIso($language);
}
if (AppLocale::isLocaleValid($language)) {
$locale = $language;
}
return $locale;
}
示例2: assert
/**
* @see MetadataDataObjectAdapter::injectMetadataIntoDataObject()
* @param $metadataDescription MetadataDescription
* @param $targetDataObject Submission
*/
function &injectMetadataIntoDataObject(&$metadataDescription, &$targetDataObject)
{
assert(is_a($targetDataObject, 'Submission'));
assert($metadataDescription->getMetadataSchemaName() == 'plugins.metadata.mods34.schema.Mods34Schema');
// Get the cataloging language.
$catalogingLanguage = $metadataDescription->getStatement('recordInfo/languageOfCataloging/languageTerm[@authority="iso639-2b"]');
$catalogingLocale = AppLocale::getLocaleFrom3LetterIso($catalogingLanguage);
assert(!is_null($catalogingLocale));
// Title
$localizedTitles = $metadataDescription->getStatementTranslations('titleInfo/title');
if (is_array($localizedTitles)) {
foreach ($localizedTitles as $locale => $title) {
$targetDataObject->setTitle($title, $locale);
}
}
// Names: authors and sponsor
$foundSponsor = false;
$nameDescriptions =& $metadataDescription->getStatement('name');
if (is_array($nameDescriptions)) {
foreach ($nameDescriptions as $nameDescription) {
/* @var $nameDescription MetadataDescription */
// Check that we find the expected name schema.
assert($nameDescription->getMetadataSchemaName() == 'lib.pkp.plugins.metadata.mods34.schema.Mods34NameSchema');
// Retrieve the name type and role.
$nameType = $nameDescription->getStatement('[@type]');
$nameRoles = $nameDescription->getStatement('role/roleTerm[@type="code" @authority="marcrelator"]');
// Transport the name into the submission depending
// on name type and role.
// FIXME: Move this to a dedicated adapter in the Author class.
if (is_array($nameRoles)) {
switch ($nameType) {
// Authors
case 'personal':
// Only authors go into the submission.
if (in_array('aut', $nameRoles)) {
// Instantiate a new author object.
$authorDao = DAORegistry::getDAO('AuthorDAO');
/* @var $authorDao AuthorDAO */
$author = $authorDao->newDataObject();
// Family Name
$author->setLastName($nameDescription->getStatement('namePart[@type="family"]'));
// Given Names
$givenNames = $nameDescription->getStatement('namePart[@type="given"]');
if (!empty($givenNames)) {
$givenNames = explode(' ', $givenNames, 2);
if (isset($givenNames[0])) {
$author->setFirstName($givenNames[0]);
}
if (isset($givenNames[1])) {
$author->setMiddleName($givenNames[1]);
}
}
// Affiliation
// NB: Our MODS mapping currently doesn't support translation for names.
// This can be added when required by data providers. We assume the cataloging
// language for the record.
$affiliation = $nameDescription->getStatement('affiliation');
if (!empty($affiliation)) {
$author->setAffiliation($affiliation, $catalogingLocale);
}
// Terms of address (unmapped field)
$termsOfAddress = $nameDescription->getStatement('namePart[@type="termsOfAddress"]');
if ($termsOfAddress) {
$author->setData('nlm34:namePart[@type="termsOfAddress"]', $termsOfAddress);
}
// Date (unmapped field)
$date = $nameDescription->getStatement('namePart[@type="date"]');
if ($date) {
$author->setData('nlm34:namePart[@type="date"]', $date);
}
// Add the author to the submission.
$authorDao->insertObject($author);
unset($author);
}
break;
// Sponsor
// NB: Our MODS mapping currently doesn't support translation for names.
// This can be added when required by data providers. We assume the cataloging
// language for the record.
// Sponsor
// NB: Our MODS mapping currently doesn't support translation for names.
// This can be added when required by data providers. We assume the cataloging
// language for the record.
case 'corporate':
// Only the first sponsor goes into the submission.
if (!$foundSponsor && in_array('spn', $nameRoles)) {
$foundSponsor = true;
$targetDataObject->setSponsor($nameDescription->getStatement('namePart'), $catalogingLocale);
}
break;
}
}
unset($nameDescription);
}
}
//.........这里部分代码省略.........
示例3: testGetLocaleFrom3LetterIso
/**
* @covers PKPLocale
*/
public function testGetLocaleFrom3LetterIso()
{
// A locale that does not have to be disambiguated.
self::assertEquals('en_US', AppLocale::getLocaleFrom3LetterIso('eng'));
// The primary locale will be used if that helps
// to disambiguate.
AppLocale::setSupportedLocales(array('en_US' => 'English', 'pt_BR' => 'Portuguese (Brazil)', 'pt_PT' => 'Portuguese (Portugal)'));
AppLocale::setPrimaryLocale('pt_BR');
self::assertEquals('pt_BR', AppLocale::getLocaleFrom3LetterIso('por'));
AppLocale::setPrimaryLocale('pt_PT');
self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
// If the primary locale doesn't help then use the first supported locale found.
AppLocale::setPrimaryLocale('en_US');
self::assertEquals('pt_BR', AppLocale::getLocaleFrom3LetterIso('por'));
AppLocale::setSupportedLocales(array('en_US' => 'English', 'pt_PT' => 'Portuguese (Portugal)', 'pt_BR' => 'Portuguese (Brazil)'));
self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
// If the locale isn't even in the supported localse then use the first locale found.
AppLocale::setSupportedLocales(array('en_US' => 'English'));
self::assertEquals('pt_PT', AppLocale::getLocaleFrom3LetterIso('por'));
// Unknown language.
self::assertNull(AppLocale::getLocaleFrom3LetterIso('xxx'));
}
示例4: _addArticleXml
//.........这里部分代码省略.........
}
// We need the router to build file URLs.
$router = $request->getRouter();
/* @var $router PageRouter */
// Add galley files
$articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
$galleys = $articleGalleyDao->getBySubmissionId($article->getId());
$galleyList = null;
while ($galley = $galleys->next()) {
/* @var $galley ArticleGalley */
$locale = $galley->getLocale();
$galleyUrl = $router->url($request, $journal->getPath(), 'article', 'download', array(intval($article->getId()), intval($galley->getId())));
if (!empty($locale) && !empty($galleyUrl)) {
if (is_null($galleyList)) {
$galleyList =& XMLCustomWriter::createElement($articleDoc, 'galleyList');
}
$galleyNode =& XMLCustomWriter::createElement($articleDoc, 'galley');
XMLCustomWriter::setAttribute($galleyNode, 'locale', $locale);
XMLCustomWriter::setAttribute($galleyNode, 'fileName', $galleyUrl);
XMLCustomWriter::appendChild($galleyList, $galleyNode);
}
}
// Wrap the galley XML as CDATA.
if (!is_null($galleyList)) {
if (is_callable(array($articleDoc, 'saveXml'))) {
$galleyXml = $articleDoc->saveXml($galleyList);
} else {
$galleyXml = $galleyList->toXml();
}
$galleyOuterNode =& XMLCustomWriter::createElement($articleDoc, 'galley-xml');
if (is_callable(array($articleDoc, 'createCDATASection'))) {
$cdataNode = $articleDoc->createCDATASection($galleyXml);
} else {
$cdataNode = new XMLNode();
$cdataNode->setValue('<![CDATA[' . $galleyXml . ']]>');
}
XMLCustomWriter::appendChild($galleyOuterNode, $cdataNode);
XMLCustomWriter::appendChild($articleNode, $galleyOuterNode);
}
// Add supplementary files
$fileDao = DAORegistry::getDAO('SuppFileDAO');
$suppFiles =& $fileDao->getSuppFilesByArticle($article->getId());
$suppFileList = null;
foreach ($suppFiles as $suppFile) {
/* @var $suppFile SuppFile */
// Try to map the supp-file language to a PKP locale.
$locale = null;
$language = $suppFile->getLanguage();
if (strlen($language) == 2) {
$language = AppLocale::get3LetterFrom2LetterIsoLanguage($language);
}
if (strlen($language) == 3) {
$locale = AppLocale::getLocaleFrom3LetterIso($language);
}
if (!AppLocale::isLocaleValid($locale)) {
$locale = 'unknown';
}
$suppFileUrl = $router->url($request, $journal->getPath(), 'article', 'downloadSuppFile', array(intval($article->getId()), intval($suppFile->getId())));
if (!empty($locale) && !empty($suppFileUrl)) {
if (is_null($suppFileList)) {
$suppFileList =& XMLCustomWriter::createElement($articleDoc, 'suppFileList');
}
$suppFileNode =& XMLCustomWriter::createElement($articleDoc, 'suppFile');
XMLCustomWriter::setAttribute($suppFileNode, 'locale', $locale);
XMLCustomWriter::setAttribute($suppFileNode, 'fileName', $suppFileUrl);
XMLCustomWriter::appendChild($suppFileList, $suppFileNode);
// Add supp file meta-data.
$suppFileMetadata = array('title' => $suppFile->getTitle(null), 'creator' => $suppFile->getCreator(null), 'subject' => $suppFile->getSubject(null), 'typeOther' => $suppFile->getTypeOther(null), 'description' => $suppFile->getDescription(null), 'source' => $suppFile->getSource(null));
foreach ($suppFileMetadata as $field => $data) {
if (!empty($data)) {
$suppFileMDListNode =& XMLCustomWriter::createElement($articleDoc, $field . 'List');
foreach ($data as $locale => $value) {
$suppFileMDNode =& XMLCustomWriter::createChildWithText($articleDoc, $suppFileMDListNode, $field, $value);
XMLCustomWriter::setAttribute($suppFileMDNode, 'locale', $locale);
unset($suppFileMDNode);
}
XMLCustomWriter::appendChild($suppFileNode, $suppFileMDListNode);
unset($suppFileMDListNode);
}
}
}
}
// Wrap the suppFile XML as CDATA.
if (!is_null($suppFileList)) {
if (is_callable(array($articleDoc, 'saveXml'))) {
$suppFileXml = $articleDoc->saveXml($suppFileList);
} else {
$suppFileXml = $suppFileList->toXml();
}
$suppFileOuterNode =& XMLCustomWriter::createElement($articleDoc, 'suppFile-xml');
if (is_callable(array($articleDoc, 'createCDATASection'))) {
$cdataNode = $articleDoc->createCDATASection($suppFileXml);
} else {
$cdataNode = new XMLNode();
$cdataNode->setValue('<![CDATA[' . $suppFileXml . ']]>');
}
XMLCustomWriter::appendChild($suppFileOuterNode, $cdataNode);
XMLCustomWriter::appendChild($articleNode, $suppFileOuterNode);
}
}
示例5: getPrimaryObjectLocale
/**
* @see DOIExportDom::getPrimaryObjectLocale()
* @param $suppFile SuppFile
*/
function getPrimaryObjectLocale(&$article, &$galley, &$suppFile)
{
$primaryObjectLocale = null;
if (is_a($suppFile, 'SuppFile')) {
// Try to map the supp-file language to a PKP locale.
$suppFileLanguage = $suppFile->getLanguage();
if (strlen($suppFileLanguage) == 2) {
$suppFileLanguage = AppLocale::get3LetterFrom2LetterIsoLanguage($suppFileLanguage);
}
if (strlen($suppFileLanguage) == 3) {
$primaryObjectLocale = AppLocale::getLocaleFrom3LetterIso($suppFileLanguage);
}
}
// If mapping didn't work or we do not have a supp file then
// retrieve the locale from the other objects.
if (!AppLocale::isLocaleValid($primaryObjectLocale)) {
$primaryObjectLocale = parent::getPrimaryObjectLocale($article, $galley);
}
return $primaryObjectLocale;
}