FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go-tour


Description:
tour: Internationaliztion of the user interface

Translators do not need to muck about in tour.js or the
non-text parts or index.html. They only need to edit lang.js.

Please review this at http://codereview.appspot.com/6639062/

Affected files:
A static/lang.js
M static/tour.js


Index: static/lang.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/static/lang.js
@@ -0,0 +1,32 @@
+/* Copyright 2012 The Go Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file.
+ */
+
+// Put translations for the tour user interface here.
+// Missing translations will be passed through as English. Thus
+// the correct translation table for English is the empty hash:
+
+var tr = {}
+
+// Currently known strings that should be translated (and examples in
French)
+//
+//var tr = {
+// "off": "non",
+// "on": "oui",
+// "Syntax-Highlighting": "Coloration-syntaxique",
+// "Line-Numbers": "Numéros de ligne",
+// "Reset Slide": "Réinitialiser",
+// "Format Source Code": "Format du code",
+// "Kill Program": "Terminer le programme",
+// "Run": "Executer",
+// "Table of Contents": "La table des matières",
+// "Previous": "précédent",
+// "Next": "suivante",
+// "Waiting for remote server...": "En attente de serveur distant ...",
+// "Error communicating with remote server.": "Erreur de communication
avec le serveur distant.",
+//}
+
+function L(en) {
+ return tr[en] ? tr[en] : en;
+}
Index: static/tour.js
===================================================================
--- a/static/tour.js
+++ b/static/tour.js
@@ -17,7 +17,7 @@
}

var $tocdiv = $('<div id="toc" />').insertBefore('#slides').hide();
- $tocdiv.append($('<h2>Table of Contents</h2>'));
+ $tocdiv.append($('<h2>'+L('Table of Contents')+'</h2>'));
var $toc = $('<ol />').appendTo($tocdiv);
$("#tocbtn").click(toggleToc);

@@ -34,7 +34,7 @@
$nav.append($("<a>◀</a>").click(function() {
show(i-1);
return false;
- }).attr("href", "#"+(i)).attr("title", "Previous"));
+ }).attr("href", "#"+(i)).attr("title", L("Previous")));
} else {
$nav.append($("<span>◀</span>"));
}
@@ -42,7 +42,7 @@
$nav.append($("<a>▶</a>").click(function() {
show(i+1);
return false;
- }).attr("href", "#"+(i+2)).attr("title", "Next"));
+ }).attr("href", "#"+(i+2)).attr("title", L("Next")));
} else {
$nav.append($("<span>▶</span>"));
}
@@ -111,10 +111,10 @@
$('#togglesyntax').click(function() {
if (editor.getOption('theme') === 'default') {
editor.setOption('theme', 'plain');
- $('#togglesyntax').text('Syntax-Highlighting: off');
+ $('#togglesyntax').text(L('Syntax-Highlighting')+': '+L('off'));
} else {
editor.setOption('theme', 'default');
- $('#togglesyntax').text('Syntax-Highlighting: on');
+ $('#togglesyntax').text(L('Syntax-Highlighting')+': '+L('on'));
}
setcookie('theme', editor.getOption('theme'), 14);
$('.controls').removeClass('expanded');
@@ -124,10 +124,10 @@
$('#togglelineno').click(function() {
if (editor.getOption('lineNumbers')) {
editor.setOption('lineNumbers', false);
- $('#togglelineno').text('Line-Numbers: off');
+ $('#togglelineno').text(L('Line-Numbers')+': '+L('off'));
} else {
editor.setOption('lineNumbers', true);
- $('#togglelineno').text('Line-Numbers: on');
+ $('#togglelineno').text(L('Line-Numbers')+': '+L('on'));
}
setcookie('lineno', editor.getOption('lineNumbers'), 14);
$('.controls').removeClass('expanded');
@@ -136,11 +136,22 @@

if (getcookie('lineno') != ""+editor.getOption('lineNumbers')) {
$('#togglelineno').trigger('click');
+ } else {
+ $('#togglelineno').text(L('Line-Numbers')+': '+L('on'));
}

if (getcookie('theme') != ""+editor.getOption('theme')) {
$('#togglesyntax').trigger('click');
+ } else {
+ $('#togglesyntax').text(L('Syntax-Highlighting')+': '+L('on'));
}
+
+ // set these according to lang.js
+ $('#run').text(L('Run'));
+ $('#reset').text(L('Reset Slide'));
+ $('#format').text(L('Format Source Code'));
+ $('#kill').text(L('Kill Program'));
+ $('#tocbtn').attr("title", L("Table of Contents"));
}

function toggleToc() {
@@ -257,11 +268,13 @@


var seq = 0;
+var errcomm = 'Error communicating with remote server.';
+var waiting = 'Waiting for remote server...';

function run() {
seq++;
var cur = seq;
- $output.html('<div class="loading">Waiting for remote server...</div>');
+ $output.html('<div class="loading">'+L(waiting)+'</div>');
$.ajax("/compile", {
data: {"body": editor.getValue()},
type: "POST",
@@ -285,7 +298,7 @@
},
error: function() {
$output.empty();
- $('<pre class="error" />').text("Error communicating with remote
server.").appendTo($output);
+ $('<pre class="error" />').text(L(errcomm)).appendTo($output);
}
});
}
@@ -293,7 +306,7 @@
function format() {
seq++;
var cur = seq;
- $output.html('<div class="loading">Waiting for remote server...</div>');
+ $output.html('<div class="loading">'+L(waiting)+'</div>');
$.ajax("/fmt", {
data: {"body": editor.getValue()},
type: "POST",
@@ -311,7 +324,7 @@
}
},
error: function() {
- $('<pre class="error" />').text("Error communicating with remote
server.").appendTo($output);
+ $('<pre class="error" />').text(L(errcomm)).appendTo($output);
}
});
}

Search Discussions

  • Adg at Oct 11, 2012 at 12:09 am
    Thanks, but there are some things I don't like about this change:

    a) adds another js file to load; please put the translation map in
    tour.js
    b) the keys for the lang map should not be the english sentences, but
    rather short keywords that describe the various strings. then there
    should be a default english mapping.


    https://codereview.appspot.com/6639062/
  • Jeff Allen at Oct 11, 2012 at 6:43 am
    Translations should not be mixed with code. But a good compromise would
    be to put it in index.html. Your other suggestion loses the default to
    english whichis too bad.

    https://codereview.appspot.com/6639062/
  • Adg at Oct 11, 2012 at 6:58 am

    On 2012/10/11 06:43:38, jeff.allen wrote:
    Translations should not be mixed with code. But a good compromise
    would be to
    put it in index.html. Your other suggestion loses the default to
    english whichis
    too bad.
    I'm not even clear how the translations will be swapped in, so it makes
    no difference whether it's in lang.js or tour.js right now.

    https://codereview.appspot.com/6639062/
  • Jeff Allen at Oct 16, 2012 at 9:39 pm
    Hello golang-dev@googlegroups.com, adg@golang.org (cc:
    golang-dev@googlegroups.com),

    Please take another look.


    http://codereview.appspot.com/6639062/
  • Adg at Oct 19, 2012 at 1:45 am
    This is better. Thanks.


    https://codereview.appspot.com/6639062/diff/14001/static/index.html
    File static/index.html (right):

    https://codereview.appspot.com/6639062/diff/14001/static/index.html#newcode20
    static/index.html:20: // Put your translation of the user interface
    here.
    // Localized user interface.

    https://codereview.appspot.com/6639062/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 10, '12 at 11:03p
activeOct 19, '12 at 1:45a
posts6
users2
websitegolang.org

2 users in discussion

Jeff Allen: 3 posts Adg: 3 posts

People

Translate

site design / logo © 2022 Grokbase