Author: peter
Date: Sat Sep 19 21:46:00 2009
New Revision: 3434
Log:
use EAD 'langusage' value to detect language of XML content, set this as the
source culture of the imported record (if the language is supported by Symfony
i18n), and switch UI to the import language. Fixes issue #674
Modified:
trunk/lib/QubitXmlImport.class.php
Modified: trunk/lib/QubitXmlImport.class.php
==============================================================================
--- trunk/lib/QubitXmlImport.class.php Sat Sep 19 17:43:26 2009 (r3433)
+++ trunk/lib/QubitXmlImport.class.php Sat Sep 19 21:46:00 2009 (r3434)
@@ -159,19 +159,43 @@
// switch source culture if langusage is set in an EAD document
if ($importSchema == 'ead')
+ sfLoader::loadHelpers(array('I18N'));
{
if (is_object($langusage =
$importDOM->xpath->query('//eadheader/profiledesc/langusage/language/@langcode')))
{
+ $sf_user = sfContext::getInstance()->getUser();
+ $currentCulture = $sf_user->getCulture();
+ $langCodeConvertor = new fbISO639_Map;
foreach ($langusage as $language)
{
$isocode = trim(preg_replace('/[\n\r\s]+/', ' ',
$language->nodeValue));
- // 1) convert to Symfony culture code
- // 2) change sf_user to this culture
- // 3) make sure record is saved with this culture as default
- // 4) add an 'error' message to notify user that culture has been
changed?
+ // convert to Symfony culture code
+ if ($twoCharCode = strtolower($langCodeConvertor->getID2($isocode)))
+ {
+ // Check to make sure that the selected language is supported with
a Symfony i18n data file.
+ // If not it will cause a fatal error in the Language List
component on every response.
+ try
+ {
+ format_language($twoCharCode, $twoCharCode);
+ }
+ catch (Exception $e)
+ {
+ $qubitXmlImport->errors[] = __('EAD "langmaterial" is set
to').': "'.$isocode.'". '.__('This language is currently not supported.');
+ continue;
+ }
- // only use the first langusage value, have to assume this is the
primary language
- break;
+ if ($currentCulture !== $twoCharCode)
+ {
+ $qubitXmlImport->errors[] = __('EAD "langmaterial" is set
to').': "'.format_language($twoCharCode, $twoCharChode).'". '.__('Your XML
document has been saved in this language and your user interface has just been
switched to this language.');
+ }
+ $sf_user->setCulture($twoCharCode);
+ // can only set to one language, so have to break once the first
valid language is encountered
+ break;
+ }
+ else
+ {
+ $qubitXmlImport->errors[] = __('EAD "langmaterial" is set to').':
"'.$isocode.'". '.__('This language is currently not supported.');
+ }
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---