# HG changeset patch # User veltr # Date 1332438151 -3600 # Node ID 353a78021ebc0538e203c5fa70a5478dee3907fc # Parent 526f91f5253e44caf3501989ba656333e10b42ea Added Internationalization diff -r 526f91f5253e -r 353a78021ebc sbin/build/client.xml --- a/sbin/build/client.xml Wed Mar 21 16:43:25 2012 +0100 +++ b/sbin/build/client.xml Thu Mar 22 18:42:31 2012 +0100 @@ -59,7 +59,7 @@ - + diff -r 526f91f5253e -r 353a78021ebc src/js/i18n.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/js/i18n.js Thu Mar 22 18:42:31 2012 +0100 @@ -0,0 +1,107 @@ +IriSP.i18n_factory = function() { + this.messages = {}; + this.base_lang = 'en'; +} + +IriSP.i18n_factory.prototype.getLanguage = function(lang) { + var _lang = ( + typeof lang != "undefined" + ? lang + : ( + typeof IriSP.language != "undefined" + ? IriSP.language + : this.base_lang + ) + ); + return ( + typeof this.messages[_lang] == "object" + ? _lang + : ( + typeof this.messages[this.base_lang] == "object" + ? this.base_lang + : null + ) + ) +} + +IriSP.i18n_factory.prototype.getMessages = function(lang) { + var _lang = this.getLanguage(lang); + return ( + _lang != null + ? this.messages[_lang] + : {} + ); +} + +IriSP.i18n_factory.prototype.getMessage = function(message, lang) { + var _msgs = this.getMessages(lang); + return ( + typeof _msgs[message] != "undefined" + ? _msgs[message] + : message + ) +} + +IriSP.i18n_factory.prototype.addLanguage = function(lang, messages) { + this.messages[lang] = messages; +} + +IriSP.i18n_factory.prototype.addLanguages = function(messages) { + var _this = this; + IriSP.underscore(messages).each(function(_messages, _lang) { + _this.addLanguage(_lang, _messages); + }); +} + +IriSP.i18n = new IriSP.i18n_factory(); + +IriSP.i18n.addLanguages( + { + en: { + submit: "Submit", + add_keywords: "Add keywords", + add_polemic_keywords: "Add polemic keywords", + your_name: "Your name", + type_here: "Type your annotation here.", + wait_while_processed: "Please wait while your request is being processed...", + error_while_contacting: "An error happened while contacting the server. Your annotation has not been saved.", + empty_annotation: "Your annotation is empty. Please write something before submitting.", + annotation_saved: "Thank you, your annotation has been saved.", + share_annotation: "Would you like to share it on social networks ?", + share_on: "Share on", + play_pause: "Play/Pause", + mute_unmute: "Mute/Unmute", + play: "Play", + pause: "Pause", + mute: "Mute", + unmute: "Unmute", + annotate: "Annotate", + search: "Search", + elapsed_time: "Elapsed time", + total_time: "Total time" + }, + fr: { + submit: "Envoyer", + add_keywords: "Ajouter des mots-clés", + add_polemic_keywords: "Ajouter des mots-clés polémiques", + your_name: "Votre nom", + type_here: "Rédigez votre annotation ici.", + wait_while_processed: "Veuillez patienter pendant le traitement de votre requête...", + error_while_contacting: "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée", + empty_annotation: "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.", + annotation_saved: "Merci, votre annotation a été enregistrée.", + share_annotation: "Souhaitez-vous la partager sur les réseaux sociaux ?", + share_on: "Partager sur", + play_pause: "Lecture/Pause", + mute_unmute: "Couper/Activer le son", + play: "Lecture", + pause: "Pause", + mute: "Couper le son", + unmute: "Activer le son", + annotate: "Annoter", + search: "Rechercher", + elapsed_time: "Durée écoulée", + total_time: "Durée totale" + } + } +); diff -r 526f91f5253e -r 353a78021ebc src/js/site.js.templ --- a/src/js/site.js.templ Wed Mar 21 16:43:25 2012 +0100 +++ b/src/js/site.js.templ Thu Mar 22 18:42:31 2012 +0100 @@ -17,6 +17,8 @@ IriSP.platform_url = "http://localhost/pf"; IriSP.default_templates_vars = { }; +IriSP.language = 'en'; + /** ugly ugly ugly ugly - returns an object defining the paths to the libs We need it that way cause it's called at runtime by diff -r 526f91f5253e -r 353a78021ebc src/js/utils.js --- a/src/js/utils.js Wed Mar 21 16:43:25 2012 +0100 +++ b/src/js/utils.js Thu Mar 22 18:42:31 2012 +0100 @@ -113,7 +113,11 @@ /* shortcut to have global variables in templates */ IriSP.templToHTML = function(template, values) { - var params = IriSP.jQuery.extend(IriSP.default_templates_vars, values); + var params = IriSP.jQuery.extend( + { "defaults" : IriSP.default_templates_vars, + "l10n" : IriSP.i18n.getMessages() + }, + values); return Mustache.to_html(template, params); }; diff -r 526f91f5253e -r 353a78021ebc src/js/widgets/createAnnotationWidget.js --- a/src/js/widgets/createAnnotationWidget.js Wed Mar 21 16:43:25 2012 +0100 +++ b/src/js/widgets/createAnnotationWidget.js Thu Mar 22 18:42:31 2012 +0100 @@ -212,9 +212,9 @@ /* test if the browser supports the placeholder attribute */ if (!IriSP.null_or_undefined(jqTextfield.get(0).placeholder)) { - jqTextfield.attr("placeholder", "Type your annotation here."); + jqTextfield.attr("placeholder", IriSP.i18n.getMessage('type_here')); } else { - jqTextfield.val("Type your annotation here."); + jqTextfield.val(IriSP.i18n.getMessage('type_here')); jqTextfield.one("click", IriSP.wrap(this, function() { jqTextfield.val(""); })); } diff -r 526f91f5253e -r 353a78021ebc src/js/widgets/playerWidget.js --- a/src/js/widgets/playerWidget.js Wed Mar 21 16:43:25 2012 +0100 +++ b/src/js/widgets/playerWidget.js Thu Mar 22 18:42:31 2012 +0100 @@ -85,10 +85,10 @@ if ( status == true ){ /* the background sprite is changed by adding/removing the correct classes */ - this.selector.find(".Ldt-CtrlPlay").attr("title", "Play"); + this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('play')); this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PauseState").addClass("Ldt-CtrlPlay-PlayState"); } else { - this.selector.find(".Ldt-CtrlPlay").attr("title", "Pause"); + this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('pause')); this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PlayState").addClass("Ldt-CtrlPlay-PauseState"); } @@ -118,10 +118,10 @@ var status = this._Popcorn.media.muted; if ( status == true ){ - this.selector.find(".Ldt-CtrlSound").attr("title", "Unmute"); + this.selector.find(".Ldt-CtrlSound").attr("title", IriSP.i18n.getMessage('unmute')); this.selector.find(".Ldt-CtrlSound").removeClass("Ldt-CtrlSound-MuteState").addClass("Ldt-CtrlSound-SoundState"); } else { - this.selector.find(".Ldt-CtrlSound").attr("title", "Mute"); + this.selector.find(".Ldt-CtrlSound").attr("title", IriSP.i18n.getMessage('mute')); this.selector.find(".Ldt-CtrlSound").removeClass("Ldt-CtrlSound-SoundState").addClass("Ldt-CtrlSound-MuteState"); } diff -r 526f91f5253e -r 353a78021ebc src/templates/annotationWidget.html --- a/src/templates/annotationWidget.html Wed Mar 21 16:43:25 2012 +0100 +++ b/src/templates/annotationWidget.html Thu Mar 22 18:42:31 2012 +0100 @@ -5,9 +5,9 @@
- - - + + +
diff -r 526f91f5253e -r 353a78021ebc src/templates/createAnnotationWidget.html --- a/src/templates/createAnnotationWidget.html Wed Mar 21 16:43:25 2012 +0100 +++ b/src/templates/createAnnotationWidget.html Thu Mar 22 18:42:31 2012 +0100 @@ -11,7 +11,7 @@
{{#show_from_field}} - + {{/show_from_field}}
@@ -22,10 +22,10 @@
- + {{#keywords.length}}
- +
    {{#keywords}}
  • @@ -36,7 +36,7 @@ {{#polemic_mode}} {{#polemics.length}}
    - +
      {{#polemics}}
    • @@ -48,17 +48,17 @@