本文整理汇总了PHP中Locale::getLocaleFrom3LetterIso方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getLocaleFrom3LetterIso方法的具体用法?PHP Locale::getLocaleFrom3LetterIso怎么用?PHP Locale::getLocaleFrom3LetterIso使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locale
的用法示例。
在下文中一共展示了Locale::getLocaleFrom3LetterIso方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assert
/**
* @see MetadataDataObjectAdapter::injectMetadataIntoDataObject()
* @param $mods34Description MetadataDescription
* @param $submission Submission
* @param $authorClassName string the application specific author class name
*/
function &injectMetadataIntoDataObject(&$mods34Description, &$submission, $authorClassName)
{
assert(is_a($submission, 'Submission'));
assert($mods34Description->getMetadataSchemaName() == 'plugins.metadata.mods34.schema.Mods34Schema');
// Get the cataloging language.
$catalogingLanguage = $mods34Description->getStatement('recordInfo/languageOfCataloging/languageTerm[@authority="iso639-2b"]');
$catalogingLocale = Locale::getLocaleFrom3LetterIso($catalogingLanguage);
assert(!is_null($catalogingLocale));
// Title
$localizedTitles = $mods34Description->getStatementTranslations('titleInfo/title');
if (is_array($localizedTitles)) {
foreach ($localizedTitles as $locale => $title) {
$submission->setTitle($title, $locale);
}
}
// Names: authors and sponsor
$foundSponsor = false;
$nameDescriptions =& $mods34Description->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.
import($authorClassName);
$author = new Author();
// 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.
$submission->addAuthor($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;
$submission->setSponsor($nameDescription->getStatement('namePart'), $catalogingLocale);
}
break;
}
}
unset($nameDescription);
}
}
//.........这里部分代码省略.........
示例2: testGetLocaleFrom3LetterIso
/**
* @covers PKPLocale
*/
public function testGetLocaleFrom3LetterIso()
{
// A locale that does not have to be disambiguated.
self::assertEquals('en_US', Locale::getLocaleFrom3LetterIso('eng'));
// The primary locale will be used if that helps
// to disambiguate.
Locale::setSupportedLocales(array('en_US' => 'English', 'pt_BR' => 'Portuguese (Brazil)', 'pt_PT' => 'Portuguese (Portugal)'));
Locale::setPrimaryLocale('pt_BR');
self::assertEquals('pt_BR', Locale::getLocaleFrom3LetterIso('por'));
Locale::setPrimaryLocale('pt_PT');
self::assertEquals('pt_PT', Locale::getLocaleFrom3LetterIso('por'));
// If the primary locale doesn't help then use the first supported locale found.
Locale::setPrimaryLocale('en_US');
self::assertEquals('pt_BR', Locale::getLocaleFrom3LetterIso('por'));
Locale::setSupportedLocales(array('en_US' => 'English', 'pt_PT' => 'Portuguese (Portugal)', 'pt_BR' => 'Portuguese (Brazil)'));
self::assertEquals('pt_PT', Locale::getLocaleFrom3LetterIso('por'));
// If the locale isn't even in the supported localse then use the first locale found.
Locale::setSupportedLocales(array('en_US' => 'English'));
self::assertEquals('pt_PT', Locale::getLocaleFrom3LetterIso('por'));
// Unknown language.
self::assertNull(Locale::getLocaleFrom3LetterIso('xxx'));
}