Importing string over rides fails because the file type *.po is not in the default list of allowed extentions.
To reproduce goto:
1) admin/config/regional/stringoverrides/import
2) select the *.po file that you exported successfully (after implementing this fix: http://drupal.org/node/1210180#comment-5384618)
3) Select the language
4) Click import button
5) get error message: The specified file my-string-overrides.en_.po could not be uploaded. Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.
_______
I've fixed this but adding upload_validators to the import file field:
stringoverrides_migrate.admin.inc
function stringoverrides_migrate_admin_import() {
$form = array();
$form['#attributes'] = array('enctype' => "multipart/form-data");
$languages = module_exists('locale') ? locale_language_list() : array('en' => t('English'));
$form['file'] = array(
//'#type' => 'file',
// hack matt: only managed_file type can have upload_validators
'#type' => 'managed_file',
'#title' => t('File'),
'#description' => t('Attach your *.po file here to import the string overrides.'),
// hack matt: *.po fails standard validation
'#upload_validators' => array(
'file_validate_extensions' => array('po'),
),
);
$form['lang'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#description' => t('Which language to import the overrides to.'),
'#options' => $languages,
);
$form['import'] = array(
'#type' => 'submit',
'#value' => t('Import'),
'#weight' => 3,
);
return $form;
}
This probably isn't actually what you want to do, but it does allow you to at least import the strings. Probably be better to keep the #type as 'file' and implement the extension validation a different way.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | stringoverrides-1377418-6-7.43.patch | 616 bytes | 4alldigital |
| #5 | import_fails_validation-1377418-4.patch | 784 bytes | aburrows |
| #1 | Import_fails_validation-1377418-1.patch | 733 bytes | mariacha1 |
Comments
Comment #1
mariacha1 commentedIt's perfectly acceptable to add the validation to the submit handler, and then you don't get stuck with the weird managed_file issues. I'm including a patch to do that.
Comment #2
bmx269 commentedThanks, but the patch did not work for me. Gave me:
PHP Parse error: parse error in /sites/all/modules/contrib/stringoverrides/stringoverrides_migrate.admin.inc on line 63
Comment #3
mariacha1 commentedHmm... The patch doesn't touch that line. Any chance you have an older version of the module? I tested this on stringoverrides_migrate version 7.x-1.8.
Comment #4
gbirch commentedThere's an easier way to fix this. In stringoverrides_migrate_admin_import_submit(),
change
$file = file_save_upload('file');
to
$file = file_save_upload('file', array(
'file_validate_extensions' => array('po'),
));
Comment #5
aburrows commentedPatch created as per gbirch suggestion
Comment #7
4alldigital commentedtrying above patch again from #5, with module directory paths, as above patch fails with make files.
Comment #8
nicrodgerspatch in #7 applies and fixes the issue for me
Comment #9
nicrodgerstriggering test bot - didn't notice the old status