Dropdowns Translation » History » Version 33

orthagh, 03/05/2013 02:27 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 32 orthagh
   `id` int(11) NOT NULL AUTO_INCREMENT,
11 32 orthagh
   `items_id` int(11) NOT NULL DEFAULT '0',
12 32 orthagh
   `itemtype` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
13 32 orthagh
   `language` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
14 32 orthagh
   `field` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
15 32 orthagh
   `value` text COLLATE utf8_unicode_ci,
16 32 orthagh
   PRIMARY KEY (`id`),
17 33 orthagh
   KEY `typeid` (`itemtype`,`items_id`),
18 33 orthagh
   KEY `language` (`language`)
19 29 walid
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;</pre>
20 32 orthagh
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 28 walid
INSERT INTO `glpi_dropdowntranslations` 
26 28 walid
(`id`, `items_id`, `itemtype`, `field`, `language`, `value`) 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 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.
36 1 ddurieux
37 27 walid
Walid : 
38 27 walid
* for each field there's a record in the new table with a pair field => value
39 27 walid
* each field that is varchar(255) or TEXT can be translated
40 15 ddurieux
41 30 walid
h2. How to manage hierarchical dropdowns
42 30 walid
43 30 walid
When at least one field in translated : insert in the table a record for completename in this language
44 30 walid
When the last field is removed for this language, delete the completename record
45 30 walid
46 30 walid
Completename generation :
47 30 walid
* regenerate completename
48 30 walid
* check ancestor_cache : if it's null in DB, regenerate it first
49 30 walid
* foreach ancestor : if a translated name exists, use it, otherwise use name in main table
50 30 walid
* stores the translated completename in the glpi_dropdowntranslations table
51 30 walid
52 30 walid
53 31 moyo
MoYo : Insert a record for completename : what do you mean ? Childs of a translated dropdown will not use the translation of a father ?
54 31 moyo
55 20 walid
h2. Add a new configuration option
56 15 ddurieux
57 20 walid
* In Menu > Configuration > General > General config, add a new option to activate/deactive this feature (by default set to no)
58 15 ddurieux
59 20 walid
* Add a new field in "glpi_configs"
60 15 ddurieux
<pre>
61 20 walid
`translate_dropdowns` tinyint(1) NOT NULL DEFAULT '0',
62 15 ddurieux
</pre>
63 15 ddurieux
64 24 walid
h3. Right to add
65 24 walid
66 24 walid
Add a new right : translate_dropdown in glpi_profiles with values NULL / 'r' / 'w'.
67 1 ddurieux
Moyo: dropdown right is not enough ?
68 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 
69 24 walid
70 2 ddurieux
Donc : 
71 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.
72 1 ddurieux
73 11 walid
Un onglet "traduction" permettra de traduire ces champs dans la/les langues que l'on souhaite.
74 12 ddurieux
75 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.