[translations] autolocale automatic installation

Gabor Hojtsy gabor at hojtsy.hu
Fri Jan 19 14:09:28 UTC 2007


Well, I would not use a session for this task. It is (remotely) possible 
that two different admins access the module page simultaneosly, so you end 
up with stale data in the session about enabled modules, since inbetween 
modules can be enabled/disabled in another session. To get as close as 
possible, I would stuff a pre-submit callback into the form and a 
post-submit callback (ie. add a submit callback before the default submit 
callback and one after). You can do a select on enabled modules in the 
first callback, remember it (static function var). The second needs to do 
another select, ask for the static var from the first function and check 
the difference.

In an ideal world, it would be important that we should not only 
look at the status change (this is why the form array would not have 
enough information). If the status changed it only means that a module was 
enabled/disabled. But still, we don't know if a module was *installed* 
as part of being enabled, in which case the translations would import. 
Once a module is already installed, even if it is disabled, strings are 
kept in the database, so they should not be reimported (ie. because the 
user modified the translations) when reenabled.

Since we are not living in an ideal world, we would probably reload the 
strings into the database every time one module is enabled, but it would 
be good to keep the ideal situation in mind, so once this code gets into 
Drupal we have an already cleaner implementation and don't need to recode 
everything.

So, I would use two callback (not real function names :):

function autolocale_premoduleformsubmithandler($return = NULL) {
   static $module_data = array();
   if (!isset($return)) {
     // SELECT module data (name, status field, schema_version)
     // stuff into $module_data;
   }
   else {
     return $module_data;
   }
}

function autolocale_postmoduleformsubmithandler() {
   $pre_module_data = autolocale_premoduleformsubmithandler(TRUE);
   // SELECT module date (see above)
   // compare
   // import needed PO files
}

I don't have time immediately to do it unfortunately, so help would be 
appreciated.

Gabor

On Thu, 18 Jan 2007, Jakub Suchy wrote:
> Gabor Hojtsy wrote:
>> 1. Check the database (or the module_list()) in the early callback.
>> 2. Check it again at the callback called last.
>> 3. Compute the difference.
>> 4. Import what needs to be imported
>
> Is this clean and does it have some catch? It works for me
>
> function autolocale_form_alter($form_id, &$form) {
>  // Process only if module form is displayed
>  if ($form_id === "system_modules") {
>
>    // Determine which modules are enabled at the moment
>    if (is_array($form['status']['#default_value'])) {
>      $autolocale_modules = array();
>      foreach ($form['status']['#default_value'] as $module) {
>        array_push($autolocale_modules, $module);
>      }
>
>      // We MUST skip module confirm form
>      if ($_GET['q'] != "admin/build/modules/list/confirm") {
>        $enabled = array_diff($autolocale_modules, $_SESSION['autolocale_modules']);
>        if (!empty($enabled)) {
>          // These modules have been enabled
>          print_r($enabled); // TODO
>        }
>      }
>
>      // Store modules for next reload
>      $_SESSION['autolocale_modules'] = $autolocale_modules;
>    }
>
>  }
> }
> _______________________________________________
> translations mailing list
> translations at drupal.org
> http://lists.drupal.org/mailman/listinfo/translations
>


More information about the translations mailing list