[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [flashproxy/master] Walk over an array of language codes, not just a single code.



commit 8e6479d33cf85df7ed284f2a5fee404c7797e40f
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sat May 4 12:34:10 2013 -0700

    Walk over an array of language codes, not just a single code.
    
    My idea is that we can get this information from the Accept-Language
    header if not present in the "lang" parameter.
---
 proxy/flashproxy.js |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js
index 7455321..c3e6305 100644
--- a/proxy/flashproxy.js
+++ b/proxy/flashproxy.js
@@ -369,10 +369,17 @@ function get_param_byte_count(query, param, default_val) {
         return parse_byte_count(spec);
 }
 
-/* Return the user's preferred IETF language tag, or undefined if there is no
-   language preference. */
-function get_lang() {
-    return get_param_string(query, "lang");
+/* Return an array of the user's preferred IETF language tags, in descending order
+   of priority. Return an empty array in case of no preference. */
+function get_langs() {
+    var param, result;
+
+    result = [];
+    param = get_param_string(query, "lang");
+    if (param !== undefined)
+        result.push(param);
+
+    return result;
 }
 
 /* Parse an address in the form "host:port". Returns an Object with
@@ -871,10 +878,15 @@ var LOCALIZATIONS = {
 };
 var DEFAULT_LOCALIZATION = { filename: "badge.png", text: "Internet Freedom" };
 /* Return an object with "filename" and "text" keys appropriate for the given
-   language code. Returns a default value if there is no localization for the
-   code. */
-function get_badge_localization(code) {
-    return LOCALIZATIONS[code] || DEFAULT_LOCALIZATION;
+   array of language codes. Returns a default value if there is no localization
+   for any of the codes. */
+function get_badge_localization(langs) {
+    for (var i = 0; i < langs.length; i++) {
+        var localization = LOCALIZATIONS[langs[i]];
+        if (localization !== undefined)
+            return localization;
+    }
+    return DEFAULT_LOCALIZATION;
 }
 
 /* The usual embedded HTML badge. The "elem" member is a DOM element that can be
@@ -895,7 +907,7 @@ function Badge() {
     a.setAttribute("target", "_blank");
     td.appendChild(a);
     img = document.createElement("img");
-    var localization = get_badge_localization(get_lang());
+    var localization = get_badge_localization(get_langs());
     img.setAttribute("src", localization.filename);
     img.setAttribute("alt", localization.text);
     a.appendChild(img);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits