Dropdowns Translation » History » Version 30

walid, 07/20/2011 12:14 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 30 walid
h2. How to manage hierarchical dropdowns
41 30 walid
42 30 walid
When at least one field in translated : insert in the table a record for completename in this language
43 30 walid
When the last field is removed for this language, delete the completename record
44 30 walid
45 30 walid
Completename generation :
46 30 walid
* regenerate completename
47 30 walid
* check ancestor_cache : if it's null in DB, regenerate it first
48 30 walid
* foreach ancestor : if a translated name exists, use it, otherwise use name in main table
49 30 walid
* stores the translated completename in the glpi_dropdowntranslations table
50 30 walid
51 30 walid
52 20 walid
h2. Add a new configuration option
53 15 ddurieux
54 20 walid
* In Menu > Configuration > General > General config, add a new option to activate/deactive this feature (by default set to no)
55 15 ddurieux
56 20 walid
* Add a new field in "glpi_configs"
57 15 ddurieux
<pre>
58 20 walid
`translate_dropdowns` tinyint(1) NOT NULL DEFAULT '0',
59 15 ddurieux
</pre>
60 15 ddurieux
61 24 walid
h3. Right to add
62 24 walid
63 24 walid
Add a new right : translate_dropdown in glpi_profiles with values NULL / 'r' / 'w'.
64 1 ddurieux
Moyo: dropdown right is not enough ?
65 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 
66 24 walid
67 2 ddurieux
Donc : 
68 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.
69 1 ddurieux
70 11 walid
Un onglet "traduction" permettra de traduire ces champs dans la/les langues que l'on souhaite.
71 12 ddurieux
72 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.