Dropdowns Translation » History » Version 29

walid, 07/18/2011 03:52 PM

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 28 walid
h2. A new glpi_dropdowntranslations table: 
7 1 ddurieux
8 1 ddurieux
<pre>
9 28 walid
CREATE TABLE IF NOT EXISTS `glpi_dropdowntranslations` (
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 1 ddurieux
  `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
14 26 walid
  `field` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
15 26 walid
  `value` text COLLATE utf8_unicode_ci,
16 23 walid
  PRIMARY KEY (`id`),
17 29 walid
  KEY `typeid` (`items_id`,`itemtype`),
18 29 walid
  KEY `language` (`language`)
19 23 walid
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;</pre>
20 1 ddurieux
21 20 walid
Here is an example to translate in french the 'name' field of computer types from 'laptop' to 'portable':
22 1 ddurieux
23 1 ddurieux
<pre>
24 28 walid
INSERT INTO `glpi_dropdowntranslations` 
25 28 walid
(`id`, `items_id`, `itemtype`, `field`, `language`, `value`) VALUES
26 1 ddurieux
(1, 10, 'ComputerType', 'name', 'fr_FR', 'Portable');
27 4 ddurieux
</pre>
28 4 ddurieux
29 20 walid
Moyo : how do you manage hierarchical dropdowns to rebuild the tree ?
30 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).
31 17 ddurieux
32 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 ?
33 20 walid
soin ?
34 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.
35 1 ddurieux
36 27 walid
Walid : 
37 27 walid
* for each field there's a record in the new table with a pair field => value
38 27 walid
* each field that is varchar(255) or TEXT can be translated
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 24 walid
h3. Right to add
50 24 walid
51 24 walid
Add a new right : translate_dropdown in glpi_profiles with values NULL / 'r' / 'w'.
52 1 ddurieux
Moyo: dropdown right is not enough ?
53 27 walid
Walid : I don't know to be honnest, it sounds interesting. Let's start without a specific right and add it later if needed 
54 24 walid
55 2 ddurieux
Donc : 
56 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.
57 1 ddurieux
58 11 walid
Un onglet "traduction" permettra de traduire ces champs dans la/les langues que l'on souhaite.
59 12 ddurieux
60 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.