metadataplayer/docs/widget-api.fr.md
author ymh <ymh.work@gmail.com>
Fri, 16 Nov 2012 12:53:37 +0100
changeset 34 5da687a9458d
parent 15 ed7ac7e94090
permissions -rw-r--r--
Fix the ldt lib name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     1
# API de programmation de widgets #
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     2
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     3
ATTENTION !
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
     4
Cette documentation se réfère à la dernière version du Metadataplayer, disponible dans la branche **default** du repository
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     5
http://www.iri.centrepompidou.fr/dev/hg/metadataplayer
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     6
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     7
## Types et fichiers ##
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     8
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
     9
Les widgets sont créés au moment de l’instanciation du Metadataplayer, en lisant la propriété *gui.widgets* des paramètres de configuration.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    10
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    11
Exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    12
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    13
    var monPlayer = new IriSP.Metadataplayer({
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    14
        player: {...},
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    15
        gui: {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    16
            container: ...,
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    17
            widgets: [
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    18
                {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    19
                    type: "Slider"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    20
                },
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    21
                {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    22
                    type: "Controller"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    23
                },
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    24
                {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    25
                    type: "MonWidget",
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    26
                    option: "valeur"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    27
                },
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    28
                ...
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    29
            ]
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    30
        }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    31
    });
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    32
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    33
Le *type* du widget détermine quels fichiers, javascript et CSS, seront appelés et quelle classe d'objet sera instanciée.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    34
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    35
Par exemple, pour le *type* **MonWidget**, seront appelés **MonWidget.js**, **MonWidget.css** et l’initialisation du widget se fera en appelant la classe **IriSP.Widgets.MonWidget**
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    36
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    37
Le fichier **MonWidget.js** doit donc contenir une implémentation de **IriSP.Widgets.MonWidget**
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    38
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    39
## Implémentation d’une classe de widget ##
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    40
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    41
La classe de Widget doit hériter de IriSP.Widgets.Widget. Le code permettant l’héritage est le suivant:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    42
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    43
    IriSP.Widgets.MonWidget = function(player, config) {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    44
        IriSP.Widgets.Widget.call(this, player, config);
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    45
    }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    46
    
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    47
    IriSP.Widgets.MonWidget.prototype = new IriSP.Widgets.Widget();
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    48
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    49
### Paramètres d’appel de l’objet Widget ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    50
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    51
Le paramètre **player** correspond à l’objet IriSP.Metadataplayer qui a appelé le widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    52
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    53
Il sera ensuite accessible dans les fonctions du widget par:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    54
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    55
    this.player
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    56
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    57
Le paramètre **config** correspond aux paramètres de configuration du widget. Dans notre exemple, il s’agit d’un objet contenant:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    58
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    59
    {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    60
        type: "MonWidget",
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    61
        option: "valeur de l’option"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    62
    }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    63
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    64
Les options de configuration sont recopiées dans les propriétés de l’objet widget:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    65
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    66
    this.type    => "MonWidget"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    67
    this.option  => "valeur de l’option"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    68
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    69
### Propriétés accessibles par le widget ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    70
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
    71
#### Media ####
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    72
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
    73
Les fonctions de gestion de la lecture vidéo sont accessibles via les objets **media**.
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    74
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    75
Par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    76
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
    77
    this.media.trigger("Evenement"); => déclenche un événement Popcorn de type "Evenement"
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
    78
    this.media.play();               => met le player en lecture
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
    79
    this.media.currentTime()         => obtient le timecode courant, en secondes
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    80
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    81
#### Source de métadonnées ####
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    82
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    83
La source de métadonnées est accessible par la propriété **source** du Widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    84
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    85
Par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    86
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    87
    this.source.getAnnotations();  => obtient la liste des annotations
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    88
    this.source.getDuration();     => obtient la durée du média en cours, en millisecondes
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    89
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    90
#### Sélecteur jQuery ####
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    91
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    92
Le contenu du widget est géré par la bibliothèque jQuery. Pour accéder à ce contenu, il suffit d’appeller la propriété **$** du widget
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    93
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    94
Par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    95
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    96
    this.$.html();                         => renvoie le code HTML contenu dans le widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    97
    this.$.find("p").html("Hello, world")  => écrit "Hello, world" dans le(s) élément(s) <P> du widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    98
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
    99
### Fonctions facilitatrices du widget ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   100
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   101
Quelques fonctions ont été rajoutées pour faciliter quelques tâches courantes:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   102
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   103
#### getWidgetAnnotations ####
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   104
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   105
Retourne la liste des annotations selon la valeur de la propriété **annotation\_type** du widget:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   106
    - Chaîne de caractères: prend en compte les types d’annotations dont le titre contient la chaîne. Exemple: "chap" permet notamment d’afficher les annotations dans le type d’annotation "Chapitrage"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   107
    - Tableau de chaînes: pour prendre en compte plusieurs types d’annotations
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   108
    - false: pour prendre en compte toutes les annotations du projet
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   109
    
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   110
    this.getWidgetAnnotations();
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   111
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   112
#### functionWrapper ####
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   113
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   114
Gère l’accès au fonctions du widget dans des callbacks. Ceci sert à pallier au fait qu’en Javascript, appeler directement une fonction dans un callback ne l’applique pas à l’objet dans lequel elle a été appelée.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   115
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   116
**functionWrapper** demande un argument, une chaîne qui est le nom de la fonction à appeler.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   117
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   118
Par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   119
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   120
    this.$.click(this.functionWrapper("onClick"));  => Appellera this.onClick() lors d’un click sur le widget
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   121
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   122
#### onMediaEvent ####
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   123
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   124
Attache un événement *Media* ("play", "timeupdate", ...) à une fonction désignée
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   125
- par son nom, quand celle-ci est une méthode du widget, ce qui permet de l’associer directement au widget, sur le même mode que *functionWrapper*
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   126
- comme fonction anonyme
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   127
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   128
Par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   129
15
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   130
    this.onMediaEvent("timeupdate","onTimeupdate");                => Appellera this.onTimeupdate() lorsque l’événement media "timeupdate" est déclenché.
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   131
    this.onMediaEvent("play", function() { console.log("play") }); => Affichera "play" dans la console JavaScript
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   132
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   133
#### onMdpEvent ####
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   134
ed7ac7e94090 Update Metadataplayer
veltr
parents: 0
diff changeset
   135
Attache un événement Metadataplayer global ("Annotation.show", "search.found", ...) à une fonction. Utilisé de manière similaire à onMediaEvent.
0
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   136
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   137
#### Autres fonctions ####
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   138
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   139
Les fonctions relatives aux gabarits seront explicités dans la section Gabarits
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   140
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   141
### Implémentation de la fonction draw ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   142
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   143
La fonction **draw()** est appelée automatiquement lorsque les métadonnées ont fini d’être chargées. C’est le lieu privilégié pour les fonctions gérant l’apparence du widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   144
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   145
    IriSP.Widgets.MonWidget.prototype.draw = function() {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   146
        this.$.html("Hello, world");
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   147
    }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   148
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   149
## Utilisation des gabarits ##
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   150
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   151
Les gabarits ou *templates* en anglais permettent d’injecter des données dans du code HTML.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   152
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   153
### Utilisation de Mustache ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   154
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   155
Le Metadataplayer utilise la bibliothèque *Mustache.js* pour réaliser cette opération.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   156
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   157
Voici un exemple d’utilisation de *Mustache* seul:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   158
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   159
    var gabarit = "<b>{{hello}}</b>, {{world}}";
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   160
    var donnees = {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   161
        hello: "Bonjour",
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   162
        world: "monde"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   163
    }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   164
    Mustache.to_html(gabarit, donnees);           => "<b>Bonjour</b>, monde"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   165
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   166
### templateToHtml ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   167
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   168
Les gabarits sont souvent utilisés directement avec les propriétés du widget. Un raccourci existe pour injecter directement celles-ci dans un gabarit:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   169
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   170
    this.templateToHtml("<h3>{{type}}</h3><p>{{option}}</p>");  => "<h3>MonWidget</h3><p>valeur de l’option</p>"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   171
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   172
### renderTemplate ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   173
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   174
Dans les cas les plus fréquents, le gabarit sera implémenté directement dans la propriété *template* du widget, par exemple:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   175
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   176
    IriSP.Widgets.MonWidget.prototype.template = "<h3>{{type}}</h3><p>{{option}}</p>";
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   177
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   178
De plus, le code généré par le gabarit a pour vocation d’être rajouté directement au contenu du widget, généralement à l’intérieur de la fonction draw(). Ceci peut être réalisé avec la fonction *renderTemplate*.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   179
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   180
    this.renderTemplate();   => ajoute directement "<h3>MonWidget</h3><p>valeur de l’option</p>" dans le code HTML du widget
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   181
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   182
## Internationalisation du widget ##
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   183
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   184
Le Metadataplayer a été conçu pour être multilingue. Pour ceci, les différents textes de l’interface doivent être séparés du reste du code et des gabarits.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   185
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   186
### Définition des textes ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   187
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   188
Les textes sont définis dans la propriété **messages** du widget et regroupés par langue, dans un objet dont les clés sont les codes ISO 639-1 de la langue. Chaque langue est elle-même un objet, associant un nom de texte unique à sa traduction.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   189
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   190
    IriSP.Widgets.MonWidget.prototype.message = {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   191
        en: {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   192
            hello: "Hello",
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   193
            world: "world"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   194
        },
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   195
        fr: {
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   196
            hello: "Bonjour",
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   197
            world: "monde"
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   198
        }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   199
    }
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   200
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   201
### Accès aux textes dans la langue de l’interface ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   202
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   203
La langue de l’interface est définie par *IriSP.language*. Un accès direct aux messages se fait par la propriété *l10n* (raccourci pour "localization") du widget.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   204
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   205
    this.l10n.hello;   => "Hello" si l’interface est en anglais, "Bonjour" si l’interface est en français.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   206
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   207
### Accès aux textes dans un gabarit ###
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   208
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   209
Cette propriété *l10n* permet d’accéder directement aux textes dans les gabarits:
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   210
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   211
    this.templateToHtml("{{l10n.hello}}, {{l10n.world}}!");  => "Hello, world!" en anglais ou "Bonjour, monde!" en français.
222f9654ed39 Added metadataplayer with examples and docs
veltr
parents:
diff changeset
   212