Reply to comment

How to update translations with drupal? The core only imports translations when you enable the language. It does not support updating languages.

We all know how to import language translations in the first place. We go to http://drupal.org/project/Translations and pick our translation and we copy the files onto our drupal core.
Then we go to admin/settings/language/add and add a language. When we add a language drupal detects and imports all these packages. So no need to go add import them one by one.

Now we want to update our translations? We import them one by one? I dont think so. Here is a snippet that you could use to update your languages.

It makes use of the same function the locale module uses to import your translations. Existing translations will not be overwritten.

Here is the code:

Define a menu hook, build a form displaying your enabled languages and build a batch which will import all locale files. That's it.


<?php
/**
 *  Implementation hook_menu()
 */ 
function language_update_menu() {
  
$items = array();

  
$items['admin/settings/language_update'] = array(
    
'title' => 'Update language',
    
'page callback' => 'drupal_get_form',
    
'page arguments' => array('language_update_languages_update_form'),
    
'access callback' => TRUE,
    
'type' => MENU_NORMAL_ITEM,
  );
  
  return 
$items;
}

/**
 * Form with languages to select for updating
 */
function language_update_languages_update_form() {
  include_once 
'includes/locale.inc';
  
  
$predefined language_update_prepare_predefined_list();
  
$form = array();
  
$form['language list']['langcode'] = array('#type' => 'select',
    
'#title' => t('Language name'),
    
'#default_value' => key($predefined),
    
'#options' => $predefined,
    
'#description' => t('Select the desired language and click the <em>Update language</em> button.'),
  );
  
$form['language list']['submit'] = array('#type' => 'submit''#value' => t('Update language'));
  return 
$form;
}

/**
 * Submit function
 */
function language_update_languages_update_form_submit($form$form_values) { 
  if (
$batch locale_batch_by_language($form_values['values']['langcode'], '_locale_batch_language_finished')) {
    
batch_set($batch);
  }
}

/**
 * Prepares the language code list for a select form item with only the unsupported ones
 */
function language_update_prepare_predefined_list() {
  
$languages language_list('enabled');
  
$predefined _locale_get_predefined_list();
  
  foreach (
$predefined as $key => $value) {
    if (!isset(
$languages[1][$key]) || $key == 'en') {
      unset(
$predefined[$key]);
      continue;
    }
    
// Include native name in output, if possible
    
if (count($value) > 1) {
      
$tname t($value[0]);
      
$predefined[$key] = ($tname == $value[1]) ? $tname "$tname ($value[1])";
    }
    else {
      
$predefined[$key] = t($value[0]);
    }
  }
  
asort($predefined);
  return 
$predefined;
}

?>

You can download the snippet as a module. The module is too small to contribute. It should become a feature in the core locale module.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img><p><b><i><table><th><tr><td><blockquote><br /><img /><tbody><span><strike>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <codes>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.