Dropdowns Translation » History » Version 30

« Previous - Version 30/33 (diff) - Next » - Current version
walid, 07/20/2011 12:14 PM

Translate dropdowns

Since GLPI 0.78, dropdown items are now objects.
In order to translate theses fields, here are the proposed modifications.

A new glpi_dropdowntranslations table:

CREATE TABLE IF NOT EXISTS `glpi_dropdowntranslations` (
  `items_id` int(11) NOT NULL DEFAULT '0',
  `itemtype` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `field` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `value` text COLLATE utf8_unicode_ci,
  PRIMARY KEY (`id`),
  KEY `typeid` (`items_id`,`itemtype`),
  KEY `language` (`language`)

Here is an example to translate in french the 'name' field of computer types from 'laptop' to 'portable':

INSERT INTO `glpi_dropdowntranslations` 
(`id`, `items_id`, `itemtype`, `field`, `language`, `value`) VALUES
(1, 10, 'ComputerType', 'name', 'fr_FR', 'Portable');

Moyo : how do you manage hierarchical dropdowns to rebuild the tree ?
David : each tree dropdown item is an object, so it'll get a new 'Translation' tab. I'll need to modify dropdown functions to get translations (if there's one when the translation feature is activated in the general configuration. If a field is not translated, then we'll get the default value (ie the one defined in the main dropdown table).

Moyo : my question was about the completename management, which is processed for tree dropdowns. In this case, do you recommand regenerating it when needed ?
soin ?
David : yes you're right. The most logical would be to regenerate it when a new langage translation is added or modified. Let's adde a 'completename' field in the 'glpi_dropdown_lang' table which corresponds to his language.

Walid :
  • for each field there's a record in the new table with a pair field => value
  • each field that is varchar(255) or TEXT can be translated

How to manage hierarchical dropdowns

When at least one field in translated : insert in the table a record for completename in this language
When the last field is removed for this language, delete the completename record

Completename generation :
  • regenerate completename
  • check ancestor_cache : if it's null in DB, regenerate it first
  • foreach ancestor : if a translated name exists, use it, otherwise use name in main table
  • stores the translated completename in the glpi_dropdowntranslations table

Add a new configuration option

  • In Menu > Configuration > General > General config, add a new option to activate/deactive this feature (by default set to no)
  • Add a new field in "glpi_configs"
    `translate_dropdowns` tinyint(1) NOT NULL DEFAULT '0',

Right to add

Add a new right : translate_dropdown in glpi_profiles with values NULL / 'r' / 'w'.
Moyo: dropdown right is not enough ?
Walid : I don't know to be honnest, it sounds interesting. Let's start without a specific right and add it later if needed

Donc :
Les champs des tables intitulés auraient une valeur définie par l'utilisateur (par exemple tous les champs en anglais) et on gère la traduction pour chacun de ces champs en base MySQL. c'est la référence absolue (pour les règles / dictionnaires par exemple) ou si la traduction n'existe pas en russe, il affiche cette valeur.

Un onglet "traduction" permettra de traduire ces champs dans la/les langues que l'on souhaite.

Lors de l'affichage de ces champs, on irait chercher les champs dans la langue de l'utilisateur si l'option est activés dans la configuration.