[tor-commits] [flashproxy/master] Added localization and a dictionary for different languages.

dcf at torproject.org dcf at torproject.org
Sat May 4 20:03:53 UTC 2013


commit 6ca6eb442656051712d221c8f49e2c62917bbba6
Author: Peter Bourgelais <Sketch307 at gmail.com>
Date:   Fri Apr 5 16:59:32 2013 -0400

    Added localization and a dictionary for different languages.
---
 proxy/flashproxy.js |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
index 3011aa3..719fba5 100644
--- a/proxy/flashproxy.js
+++ b/proxy/flashproxy.js
@@ -42,6 +42,15 @@
  * What rate to limit all proxy traffic combined to. The special value "off"
  * disables the limit. The default is DEFAULT_RATE_LIMIT. There is a
  * sanity-check minimum of "10K".
+ *
+ * lang=<LANGUAGE>
+ * What language in which to display the Flashproxy badge.  
+ * We use the IETF BCP 47 standard for language tags.
+ * See http://www.w3.org/International/articles/language-tags/ for a
+ * description of the standard and 
+ * http://www.iana.org/assignments/language-subtag-registry
+ * for the full list of possible values.
+ *
  */
 
 /* WebSocket links.
@@ -72,6 +81,18 @@ var DEFAULT_RATE_LIMIT = undefined;
 var MIN_RATE_LIMIT = 10 * 1024;
 var RATE_LIMIT_HISTORY = 5.0;
 
+/* Set default language for flashproxy badge, and define alt strings for the 
+   different languages
+ */
+var DEFAULT_LANGUAGE = "en";
+
+/* List of supported languages for the flashproxy badge with alt text. */
+var LANGUAGES = {
+	"en": { filename: "badge-en.png", alt: "Internet Freedom"},
+	"de": { filename: "badge-de.png", alt: "Internetfreiheit"},
+	"ru": { filename: "badge-ru.png", alt: "Свобода Интернета"}
+};
+
 /* Name of cookie that controls opt-in/opt-out. */
 var OPT_IN_COOKIE = "flashproxy-allow";
 
@@ -855,13 +876,23 @@ function escape_html(s) {
     return s.replace(/&<>'"/, function(x) { return HTML_ESCAPES[x] });
 }
 
+function get_badge_filename_and_alt() {
+    //Check to see that a language argument was provided
+    var lang_code=get_param_string(query,"lang",DEFAULT_LANGUAGE);
+    
+    //If there's no localization for that language, default to English.
+    if(LANGUAGES[lang_code] === undefined) 
+    	return { filename: "badge.png", alt: "Internet Freedom" };
+    else return LANGUAGES[lang_code];
+}
+
 /* The usual embedded HTML badge. The "elem" member is a DOM element that can be
    included elsewhere. */
 function Badge() {
     /* Number of proxy pairs currently connected. */
     this.num_proxy_pairs = 0;
 
-    var table, tr, td, a, img;
+    var table, tr, td, a, img, img_info;
 
     table = document.createElement("table");
     tr = document.createElement("tr");
@@ -873,8 +904,11 @@ function Badge() {
     a.setAttribute("target", "_blank");
     td.appendChild(a);
     img = document.createElement("img");
-    img.setAttribute("src", "badge.png");
-    img.setAttribute("alt", "Internet freedom");
+
+    img_info=get_badge_filename_and_alt();
+    img.setAttribute("src", img_info.filename);
+    img.setAttribute("alt", img_info.alt);
+
     a.appendChild(img);
 
     this.elem = table;





More information about the tor-commits mailing list