Dropdowns Translation » History » Version 20

walid, 07/17/2011 11:01 AM

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