Skip to content

Commit e576899

Browse files
committed
Add support for locale-detection in new Gmail. Add test-cases.
This closes https://github.com/josteink/gmail.js/issues/7.
1 parent fbb0109 commit e576899

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/gmail.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ var Gmail = function(localJQuery) {
183183

184184
api.helper.get.locale_from_url_params = function(value) {
185185
// check if is URL
186-
if (value && value.indexOf && value.indexOf("https://") === 0) {
186+
if (value && value.indexOf && (value.indexOf("https://") === 0 || value.indexOf("http://") === 0)) {
187187
var urlParts = value.split("?");
188188
if (urlParts.length > 1) {
189189
var hash = urlParts[1];
@@ -225,7 +225,16 @@ var Gmail = function(localJQuery) {
225225
// has historically been observed as [7], [8] and [9]!
226226
var localeList = api.helper.get.array_sublist(globals[17], "ui");
227227
if (localeList !== null && localeList.length > 8) {
228-
var locale = api.helper.get.locale_from_globals_item(localeList);
228+
let locale = api.helper.get.locale_from_globals_item(localeList);
229+
locale = api.helper.filter_locale(locale);
230+
if (locale) {
231+
return locale;
232+
}
233+
}
234+
235+
// in new gmail, globals[12] may contain a link to an help-article, with a hl= language-code
236+
if (globals[12] !== null) {
237+
let locale = api.helper.get.locale_from_url_params(globals[12]);
229238
locale = api.helper.filter_locale(locale);
230239
if (locale) {
231240
return locale;

test/test.locale.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe("Locale URL-parsing", () => {
5151
testCase("https://account.google.com/user/stats?hl=en", "en");
5252
testCase("https://account.google.com/user/stats?firstParam=value&hl=en", "en");
5353
testCase("https://account.google.com/user/stats?foo=bar&hl=no&someMoreStuff", "no");
54+
testCase("http://www.google.com/support/a/cedpta.com/bin/topic.py?topic=10100&hl=en", "en");
55+
testCase("http://support.google.com/?ctx=%67mail&hl=no", "no");
5456
});
5557
});
5658

0 commit comments

Comments
 (0)