Commit 05714da2 authored by Steven Wittens's avatar Steven Wittens
Browse files

Locale:

- Fixing broken .po import (due to file.inc changes).
- Do not show error notice on import page when no languages have been added (no longer necessary due to ability to add-and-import in one step).
- Added a notice about importing possibly taking a while.
- Raised the PHP execution time limit for importing (if not in safe mode, similar to cron.php).
parent f5289871
......@@ -94,20 +94,21 @@ function _locale_admin_import_screen() {
unset($languages['en']);
if (!count($languages)) {
drupal_set_message(t('You need to have at least one language set up to import translations.'), 'error');
$languages = _locale_prepare_iso_list();
}
else {
$languages = array(
t('Already added languages') => $languages,
t('Languages not yet added') => _locale_prepare_iso_list()
);
$form = form_file(t('Language file'), 'file', 50, t('A gettext Portable Object (.po) file.'));
$form .= form_select(t('Import into'), 'langcode', '', $languages, t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
$form .= form_radios(t('Mode'), 'mode', 'overwrite', array("overwrite" => t('Strings in the uploaded file replace existing ones, new ones are added'), "keep" => t('Existing strings are kept, only new strings are added')));
$form .= form_submit(t('Import'));
$output = form($form, 'POST', url('admin/locale/language/import'), array('enctype' => 'multipart/form-data'));
}
$form = form_file(t('Language file'), 'file', 50, t('A gettext Portable Object (.po) file.'));
$form .= form_select(t('Import into'), 'langcode', '', $languages, t('Choose the language you want to add strings into. If you choose a language which is not yet set up, then it will be added.'));
$form .= form_radios(t('Mode'), 'mode', 'overwrite', array("overwrite" => t('Strings in the uploaded file replace existing ones, new ones are added'), "keep" => t('Existing strings are kept, only new strings are added')));
$form .= '<p><strong>Note</strong>: Importing a translation file might take a while.</p>';
$form .= form_submit(t('Import'));
$output = form($form, 'POST', url('admin/locale/language/import'), array('enctype' => 'multipart/form-data'));
return $output;
}
......@@ -119,6 +120,11 @@ function _locale_admin_import_screen() {
* @param $mode should existing translations be replaced?
*/
function _locale_import_po($file, $lang, $mode) {
// If not in 'safe mode', increase the maximum execution time:
if (!ini_get('safe_mode')) {
set_time_limit(240);
}
// Check if we have the language already in the database
if (!db_fetch_object(db_query("SELECT locale FROM {locales_meta} WHERE locale = '%s'", $lang))) {
drupal_set_message(t('Unsupported language selected for import.'), 'error');
......
......@@ -26,7 +26,7 @@ function locale_help($section = "admin/help#locale") {
case 'admin/locale/language/add':
return t("<p>You need to add all languages you would like to provide the site interface in. If you can't find the desired language in the quick add dropdown, then need to provide the proper language code yourself. The language code might be used to negotiate with browsers and present flags, so it is important to pick one that is standardised for the desired language. You can also add languages by <a href=\"%import\">importing translations</a> directly into a language not yet set up.</p>", array("%import" => url("admin/locale/language/import")));
case 'admin/locale/language/import':
return t("<p>This page allows you to import a translation provided in the gettext Portable Object (.po) format. The easiest way to get your site translated is to grab an existing Drupal translation and to import it. You can obtain translations from the <a href=\"%url\">Drupal localization page</a>.</p>", array('%url' => 'http://drupal.org/localization'));
return t("<p>This page allows you to import a translation provided in the gettext Portable Object (.po) format. The easiest way to get your site translated is to grab an existing Drupal translation and to import it. You can obtain translations from the <a href=\"%url\">Drupal translation page</a>.</p>", array('%url' => 'http://drupal.org/translations'));
case 'admin/locale/language/export':
return t("<p>This page allows you to export Drupal strings. The first option is to export a translation so it can be shared. The second option is to generate a translation template, which contains all Drupal strings, but without their translations. You can use this template to start a new translation using a specialized desktop application.</p>");
case 'admin/locale/string/search':
......@@ -385,7 +385,7 @@ function locale_admin_import() {
// Now import strings into the language
$file = file_check_upload('file');
if ($ret = _locale_import_po($file->path, $edit['langcode'], $edit['mode']) == FALSE) {
if ($ret = _locale_import_po($file->filepath, $edit['langcode'], $edit['mode']) == FALSE) {
watchdog('error', t('Translation import failed.'));
watchdog('locale', t('Translation import failed.'));
}
......
......@@ -26,7 +26,7 @@ function locale_help($section = "admin/help#locale") {
case 'admin/locale/language/add':
return t("<p>You need to add all languages you would like to provide the site interface in. If you can't find the desired language in the quick add dropdown, then need to provide the proper language code yourself. The language code might be used to negotiate with browsers and present flags, so it is important to pick one that is standardised for the desired language. You can also add languages by <a href=\"%import\">importing translations</a> directly into a language not yet set up.</p>", array("%import" => url("admin/locale/language/import")));
case 'admin/locale/language/import':
return t("<p>This page allows you to import a translation provided in the gettext Portable Object (.po) format. The easiest way to get your site translated is to grab an existing Drupal translation and to import it. You can obtain translations from the <a href=\"%url\">Drupal localization page</a>.</p>", array('%url' => 'http://drupal.org/localization'));
return t("<p>This page allows you to import a translation provided in the gettext Portable Object (.po) format. The easiest way to get your site translated is to grab an existing Drupal translation and to import it. You can obtain translations from the <a href=\"%url\">Drupal translation page</a>.</p>", array('%url' => 'http://drupal.org/translations'));
case 'admin/locale/language/export':
return t("<p>This page allows you to export Drupal strings. The first option is to export a translation so it can be shared. The second option is to generate a translation template, which contains all Drupal strings, but without their translations. You can use this template to start a new translation using a specialized desktop application.</p>");
case 'admin/locale/string/search':
......@@ -385,7 +385,7 @@ function locale_admin_import() {
// Now import strings into the language
$file = file_check_upload('file');
if ($ret = _locale_import_po($file->path, $edit['langcode'], $edit['mode']) == FALSE) {
if ($ret = _locale_import_po($file->filepath, $edit['langcode'], $edit['mode']) == FALSE) {
watchdog('error', t('Translation import failed.'));
watchdog('locale', t('Translation import failed.'));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment