Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/arInstall.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ public static function loadData($dispatcher, $formatter)
$accessConditionalWarning = $i18n->__(
'This record has not yet been reviewed for personal or confidential information. Please contact the Reference Archivist to request access and initiate an access review.'
);
$translations = QubitI18N::getTranslationsForStrings([
$accessDisallowWarning,
$accessConditionalWarning,
]);
$accessDisallowWarningTranslations = $translations[$accessDisallowWarning];
$accessConditionalWarningTranslations = $translations[$accessConditionalWarning];

foreach (
QubitTaxonomy::getTermsById(QubitTaxonomy::RIGHT_BASIS_ID) as $item
Expand All @@ -396,9 +402,7 @@ public static function loadData($dispatcher, $formatter)
$setting->scope = 'access_statement';
$setting->setValue($accessDisallowWarning, ['culture' => 'en']);

foreach (
QubitI18N::getTranslations($accessDisallowWarning) as $langCode => $message
) {
foreach ($accessDisallowWarningTranslations as $langCode => $message) {
$setting->setValue($message, ['culture' => $langCode]);
}

Expand All @@ -409,9 +413,7 @@ public static function loadData($dispatcher, $formatter)
$setting->scope = 'access_statement';
$setting->setValue($accessConditionalWarning, ['culture' => 'en']);

foreach (
QubitI18N::getTranslations($accessConditionalWarning) as $langCode => $message
) {
foreach ($accessConditionalWarningTranslations as $langCode => $message) {
$setting->setValue($message, ['culture' => $langCode]);
}

Expand Down
39 changes: 28 additions & 11 deletions lib/i18n/QubitI18N.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,49 @@ class QubitI18N
* @param mixed $string
*/
public static function getTranslations($string)
{
$translations = self::getTranslationsForStrings([$string]);

return $translations[$string];
}

/**
* Return translations for several source strings in one pass over the
* configured application languages. This keeps getTranslations() compatible
* while allowing install tasks to avoid rebuilding i18n state for each
* string.
*/
public static function getTranslationsForStrings(array $strings)
{
$translations = [];
foreach ($strings as $string) {
$translations[$string] = [];
}

// Index the array with all the language codes available in the application
// Index the language codes available in the application.
$languageCodes = [];
foreach (new DirectoryIterator(sfConfig::get('sf_app_i18n_dir')) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}

$translations[$fileInfo->getBasename()] = '';
$languageCodes[] = $fileInfo->getBasename();
}

$configuration = sfContext::getInstance()->getConfiguration();
$cache = new sfNoCache();
foreach ($translations as $langCode => &$value) {
$i18n = new sfI18N($configuration, $cache, ['culture' => $langCode]);
foreach ($languageCodes as $langCode) {
$i18n = new sfI18N($configuration, new sfNoCache(), ['culture' => $langCode]);

// Mark untranslated messages
// Mark untranslated messages so they can be omitted below.
$i18n->getMessageFormat()->setUntranslatedPS(['[T]', '[/T]']);

// Update the value of this language in the dictionary
$value = $i18n->__($string);
foreach ($strings as $string) {
$value = $i18n->__($string);

// But discard the message if it's untranslated
if (empty($value) || 0 === strpos($value, '[T]', 0)) {
unset($translations[$langCode]);
// Discard empty and untranslated messages.
if (!empty($value) && 0 !== strpos($value, '[T]', 0)) {
$translations[$string][$langCode] = $value;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function loadDataFromArray($data)

// foreign key?
$columnCheck = !empty($column) && (isset($column) ? true : false);
- $objectCheck = !empty($value) && is_string($value) && (isset($this->object_references[$value]) ? true : false);
$objectCheck = !empty($value) && is_string($value) && (isset($this->object_references[$value]) ? true : false);
if ($columnCheck && $column->isForeignKey() && $objectCheck)
{
$value = $this->object_references[$value]->getPrimaryKey();
Expand Down
Loading