commit f5e60771a902270a3330c51ea023dc10e2380e73 Author: David Fifield david@bamsoftware.com Date: Sun Jun 9 10:27:49 2013 -0700
Ignore language subtags in language tags.
With a tag like "ru-RU", first try matching the whole thing, then match only the first part. See #8828. --- ChangeLog | 3 +++ proxy/flashproxy-test.js | 24 ++++++++++++++++++++++++ proxy/flashproxy.js | 19 ++++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 9f47f12..01e12bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,9 @@ o The managed transport method name "flashproxy" is now recognized as a synonym for "websocket".
+ o The badge localization now understands language subtags such as + "ru-RU". Fixes bug 8828. + Changes in version 1.1 o Programs that use certificate pins now take a --disable-pin option that causes pins to be ignored. diff --git a/proxy/flashproxy-test.js b/proxy/flashproxy-test.js index aed5247..9615588 100755 --- a/proxy/flashproxy-test.js +++ b/proxy/flashproxy-test.js @@ -308,12 +308,36 @@ function test_get_param_addr() } }
+function test_lang_keys() +{ + var TESTS = [ + { code: "de", expected: ["de"] }, + { code: "de-at", expected: ["de-at", "de"] }, + ]; + for (var i = 0; i < TESTS.length; i++) { + var test = TESTS[i]; + var actual = lang_keys(test.code); + + var j, k; + k = 0; + for (j = 0; j < test.expected.length; j++) { + for (; k < actual.length; k++) { + if (test.expected[j] === actual[k]) + break; + } + if (k === actual.length) + fail(test.code, test.expected, actual) + } + } +} + test_build_url(); test_parse_cookie_string(); test_parse_query_string(); test_get_param_boolean(); test_parse_addr_spec(); test_get_param_addr(); +test_lang_keys();
if (num_failed == 0) quit(0); diff --git a/proxy/flashproxy.js b/proxy/flashproxy.js index 6170a67..0ecc4dd 100644 --- a/proxy/flashproxy.js +++ b/proxy/flashproxy.js @@ -888,14 +888,27 @@ var LOCALIZATIONS = { "ru": { filename: "badge-ru.png", text: "Свобода Интернета" } }; var DEFAULT_LOCALIZATION = { filename: "badge.png", text: "Internet Freedom" }; +/* Return an array of progressively less specific language tags, canonicalized + for lookup in LOCALIZATIONS. */ +function lang_keys(code) { + var result = [code]; + var m = code.match(/^(\w+)/); + if (m !== null) { + result.push(m[0]); + } + return result; +} /* Return an object with "filename" and "text" keys appropriate for the given 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; + var tags = lang_keys(langs[i]); + for (var j = 0; j < tags.length; j++) { + var localization = LOCALIZATIONS[tags[j]]; + if (localization !== undefined) + return localization; + } } return DEFAULT_LOCALIZATION; }