Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/common.js

Issue 4871895371481088: Convert region code to uppercase when generating translation file URL on Safari (Closed)
Patch Set: Corrected wrong assumptions in comment Created April 10, 2014, 10:33 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/common.js
===================================================================
--- a/safari/ext/common.js
+++ b/safari/ext/common.js
@@ -85,17 +85,18 @@
var candidates = [];
var defaultLocale = "en_US";
- var bits, i;
- for (i = (bits = navigator.language.split("-")).length; i > 0; i--)
- {
- var locale = bits.slice(0, i).join("_");
- candidates.push(locale);
+ // e.g. "ja-jp-mac" -> "ja", "jp", note that the part after the second
+ // dash is dropped, since we only support language and region
+ var [language, region] = navigator.language.split("-");
- if (locale == defaultLocale)
- return candidates;
- }
+ if (region)
+ candidates.push(language + "_" + region.toUpperCase());
- candidates.push(defaultLocale);
+ candidates.push(language);
+
+ if (candidates.indexOf(defaultLocale) == -1)
+ candidates.push(defaultLocale);
+
return candidates;
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld