Dropdowns Translation » History » Version 23

walid, 07/17/2011 11:17 AM

1 20 walid
h1. Translate dropdowns
2 1 ddurieux
3 21 walid
Since GLPI 0.78, dropdown items are now objects.
4 20 walid
In order to translate theses fields, here are the proposed modifications.
5 1 ddurieux
6 22 walid
h2. A new glpi_dropdown_translations table: 
7 1 ddurieux
8 1 ddurieux
<pre>
9 23 walid
CREATE TABLE IF NOT EXISTS `glpi_dropdown_translations` (
10 23 walid
  `id` int(11) NOT NULL AUTO_INCREMENT,
11 23 walid
  `items_id` int(11) NOT NULL DEFAULT '0',
12 23 walid
  `itemtype` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
13 23 walid
  `field` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
14 23 walid
  `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
15 23 walid
  `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
16 23 walid
  `completename` text COLLATE utf8_unicode_ci,
17 23 walid
  `comment` text COLLATE utf8_unicode_ci,
18 23 walid
  PRIMARY KEY (`id`),
19 23 walid
  UNIQUE KEY `typeid` (`items_id`,`itemtype`),
20 23 walid
  UNIQUE KEY `language` (`language`)
21 23 walid
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;</pre>
22 1 ddurieux
23 20 walid
Here is an example to translate in french the 'name' field of computer types from 'laptop' to 'portable':
24 1 ddurieux
25 1 ddurieux
<pre>
26 1 ddurieux
INSERT INTO `glpi_dropdowns_lang` 
27 1 ddurieux
(`id`, `items_id`, `itemtype`, `field`, `lang`, `traduction`) VALUES
28 1 ddurieux
(1, 10, 'ComputerType', 'name', 'fr_FR', 'Portable');
29 4 ddurieux
</pre>
30 4 ddurieux
31 20 walid
Moyo : how do you manage hierarchical dropdowns to rebuild the tree ?
32 20 walid
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).
33 17 ddurieux
34 20 walid
Moyo : my question was about the completename management, which is processed for tree dropdowns. In this case, do you recommand regenerating it when needed ?
35 20 walid
soin ?
36 18 moyo
37 20 walid
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.
38 15 ddurieux
39 15 ddurieux
40 20 walid
h2. Add a new configuration option
41 15 ddurieux
42 20 walid
* In Menu > Configuration > General > General config, add a new option to activate/deactive this feature (by default set to no)
43 15 ddurieux
44 20 walid
* Add a new field in "glpi_configs"
45 15 ddurieux
<pre>
46 20 walid
`translate_dropdowns` tinyint(1) NOT NULL DEFAULT '0',
47 15 ddurieux
</pre>
48 15 ddurieux
49 2 ddurieux
Donc : 
50 20 walid
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.
51 1 ddurieux
52 11 walid
Un onglet "traduction" permettra de traduire ces champs dans la/les langues que l'on souhaite.
53 12 ddurieux
54 12 ddurieux
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.