本文整理汇总了PHP中AppLocale::getParameterNames方法的典型用法代码示例。如果您正苦于以下问题:PHP AppLocale::getParameterNames方法的具体用法?PHP AppLocale::getParameterNames怎么用?PHP AppLocale::getParameterNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppLocale
的用法示例。
在下文中一共展示了AppLocale::getParameterNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmails
/**
* Test the emails in the supplied locale against those in the supplied
* reference locale.
* @param $locale string
* @param $referenceLocale string
* @return array List of errors
*/
function testEmails($locale, $referenceLocale)
{
$errors = array();
$emails = TranslatorAction::getEmailTemplates($locale);
$referenceEmails = TranslatorAction::getEmailTemplates($referenceLocale);
// Pass 1: For all translated emails, check that they match
// against reference translations.
foreach ($emails as $emailKey => $email) {
// Check if a matching reference email was found.
if (!isset($referenceEmails[$emailKey])) {
$errors[EMAIL_ERROR_EXTRA_EMAIL][] = array('key' => $emailKey);
continue;
}
// We've successfully found a matching reference email.
// Compare it against the translation.
$bodyParams = AppLocale::getParameterNames($email['body']);
$referenceBodyParams = AppLocale::getParameterNames($referenceEmails[$emailKey]['body']);
$diff = array_diff($bodyParams, $referenceBodyParams);
if (!empty($diff)) {
$errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $emailKey, 'mismatch' => $diff);
}
$subjectParams = AppLocale::getParameterNames($email['subject']);
$referenceSubjectParams = AppLocale::getParameterNames($referenceEmails[$emailKey]['subject']);
$diff = array_diff($subjectParams, $referenceSubjectParams);
if (!empty($diff)) {
$errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $emailKey, 'mismatch' => $diff);
}
$matchedReferenceEmails[] = $emailKey;
unset($email);
unset($referenceEmail);
}
// Pass 2: Make sure that there are no missing translations.
foreach ($referenceEmails as $emailKey => $email) {
// Extract the fields from the email to be tested.
if (!isset($emails[$emailKey])) {
$errors[EMAIL_ERROR_MISSING_EMAIL][] = array('key' => $emailKey);
}
}
return $errors;
}
示例2: testLocale
/**
* Test a locale file against the given reference locale file and
* return an array of errorType => array(errors).
* @param $referenceLocaleFile object
* @return array
*/
function testLocale(&$referenceLocaleFile)
{
$errors = array(LOCALE_ERROR_MISSING_KEY => array(), LOCALE_ERROR_EXTRA_KEY => array(), LOCALE_ERROR_DIFFERING_PARAMS => array(), LOCALE_ERROR_MISSING_FILE => array());
if ($referenceLocaleFile->isValid()) {
if (!$this->isValid()) {
$errors[LOCALE_ERROR_MISSING_FILE][] = array('locale' => $this->locale, 'filename' => $this->filename);
return $errors;
}
} else {
// If the reference file itself does not exist or is invalid then
// there's nothing to be translated here.
return $errors;
}
$localeContents = LocaleFile::load($this->filename);
$referenceContents = LocaleFile::load($referenceLocaleFile->filename);
foreach ($referenceContents as $key => $referenceValue) {
if (!isset($localeContents[$key])) {
$errors[LOCALE_ERROR_MISSING_KEY][] = array('key' => $key, 'locale' => $this->locale, 'filename' => $this->filename, 'reference' => $referenceValue);
continue;
}
$value = $localeContents[$key];
$referenceParams = AppLocale::getParameterNames($referenceValue);
$params = AppLocale::getParameterNames($value);
if (count(array_diff($referenceParams, $params)) > 0) {
$errors[LOCALE_ERROR_DIFFERING_PARAMS][] = array('key' => $key, 'locale' => $this->locale, 'mismatch' => array_diff($referenceParams, $params), 'filename' => $this->filename, 'reference' => $referenceValue, 'value' => $value);
}
// After processing a key, remove it from the list;
// this way, the remainder at the end of the loop
// will be extra unnecessary keys.
unset($localeContents[$key]);
}
// Leftover keys are extraneous.
foreach ($localeContents as $key => $value) {
$errors[LOCALE_ERROR_EXTRA_KEY][] = array('key' => $key, 'locale' => $this->locale, 'filename' => $this->filename);
}
return $errors;
}
示例3: _getEmailTemplates
/**
* Get a list of email templates for the supplied locale. Returns data in the
* following data structure:
* array(
* 'emailKey' => array(
* 'subject' => 'Localized Subject',
* 'body' => 'Localized Body',
* 'description' => 'Localized Description',
* 'templateFile' => '/path/to/template-file.xml',
* 'templateDataFile' => '/path/to/localized/data-file.xml'
* ), ...
* )
* @param $locale string Locale code
* @return array Email template data
*/
static function _getEmailTemplates($locale)
{
$files = TranslatorAction::getEmailFileMap($locale);
$returner = array();
foreach ($files as $templateFile => $templateDataFile) {
if (!file_exists($templateFile)) {
continue;
}
$xmlParser = new XMLParser();
$data = $xmlParser->parse($templateFile);
foreach ($data->getChildren() as $emailNode) {
$returner[$emailNode->getAttribute('key')] = array('subject' => null, 'body' => null, 'description' => null, 'templateFile' => $templateFile, 'statusCode' => 'doesNotExist');
}
if (!file_exists($templateDataFile)) {
continue;
}
$localeData = $xmlParser->parse($templateDataFile);
if ($localeData) {
foreach ($localeData->getChildren() as $emailNode) {
$key = $emailNode->getAttribute('key');
if (isset($returner[$key])) {
$returner[$key] = array_merge($returner[$key], array('subject' => $emailNode->getChildValue('subject'), 'body' => $emailNode->getChildValue('body'), 'description' => $emailNode->getChildValue('description'), 'templateDataFile' => $templateDataFile, 'statusCode' => 'exists'));
}
}
}
}
// Fill in status
if ($locale != MASTER_LOCALE) {
$masterLocale = self::_getEmailTemplates(MASTER_LOCALE);
}
foreach ($returner as $key => &$emailData) {
switch ($emailData['statusCode']) {
case 'doesNotExist':
$emailData['status'] = __('plugins.generic.translator.email.doesNotExist');
break;
case 'exists':
$emailData['status'] = __('plugins.generic.translator.email.complete');
if ($locale != MASTER_LOCALE) {
$referenceSubject = $masterLocale[$key]['subject'];
$referenceBody = $masterLocale[$key]['body'];
if (0 != count(array_diff(AppLocale::getParameterNames($emailData['subject']), AppLocale::getParameterNames($referenceSubject)))) {
$emailData['status'] = __('plugins.generic.translator.errors.EMAIL_ERROR_DIFFERING_PARAMS.title');
}
if (0 != count(array_diff(AppLocale::getParameterNames($emailData['body']), AppLocale::getParameterNames($referenceBody)))) {
$emailData['status'] = __('plugins.generic.translator.errors.LOCALE_ERROR_DIFFERING_PARAMS.title');
}
}
break;
}
}
return $returner;
}