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

Delta Between Two Patch Sets: ext/common.js

Issue 29574648: Issue 5860 - options page is broken in test enviroment (Closed)
Left Patch Set: Created Oct. 12, 2017, 3:52 p.m.
Right Patch Set: Addressed Sebastian's comments Created Oct. 12, 2017, 8:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 }; 79 };
80 80
81 /* I18n */ 81 /* I18n */
82 82
83 let getLocaleCandidates = function(selectedLocale) 83 let getLocaleCandidates = function(selectedLocale)
84 { 84 {
85 let candidates = []; 85 let candidates = [];
86 let defaultLocale = "en_US"; 86 let defaultLocale = "en_US";
87 87
88 // e.g. "ja_jp_mac" -> "ja_JP", note that the part after the second 88 // e.g. "ja-jp-mac" -> "ja_JP", note that the part after the second
89 // dash is dropped, since we only support language and region 89 // dash is dropped, since we only support language and region
90 let parts = selectedLocale.split("_"); 90 let parts = selectedLocale.split("-");
Sebastian Noack 2017/10/12 18:10:33 This seems wrong. window.navigator.language still
saroyanm 2017/10/12 20:26:38 Noted, done.
91 let language = parts[0]; 91 let language = parts[0];
92 let region = (parts[1] || "").toUpperCase(); 92 let region = (parts[1] || "").toUpperCase();
93 93
94 if (region) 94 if (region)
95 candidates.push(language + "_" + region); 95 candidates.push(language + "_" + region);
96 96
97 candidates.push(language); 97 candidates.push(language);
98 98
99 if (candidates.indexOf(defaultLocale) == -1) 99 if (candidates.indexOf(defaultLocale) == -1)
100 candidates.push(defaultLocale); 100 candidates.push(defaultLocale);
101 101
102 return candidates; 102 return candidates;
103 }; 103 };
104 104
105 let selectedLocale = window.navigator.language; 105 let selectedLocale = window.navigator.language;
106 let match = /[?&]locale=([\w_]+)/.exec(window.location.search); 106 let match = /[?&]locale=([\w-]+)/.exec(window.location.search);
Sebastian Noack 2017/10/12 18:10:33 No need to change the semantics for the ?locale ge
saroyanm 2017/10/12 20:26:38 Right, done.
107 if (match) 107 if (match)
108 selectedLocale = match[1]; 108 selectedLocale = match[1];
109 109
110 let locales = getLocaleCandidates(selectedLocale); 110 let locales = getLocaleCandidates(selectedLocale);
111 let catalog = Object.create(null); 111 let catalog = Object.create(null);
112 let catalogFile = window.location.pathname.replace(/.*\//, "") 112 let catalogFile = window.location.pathname.replace(/.*\//, "")
113 .replace(/\..*/, "") + ".json"; 113 .replace(/\..*/, "") + ".json";
114 114
115 let replacePlaceholder = function(text, placeholder, content) 115 let replacePlaceholder = function(text, placeholder, content)
116 { 116 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 for (let msgId in rawCatalog) 157 for (let msgId in rawCatalog)
158 { 158 {
159 if (!(msgId in catalog)) 159 if (!(msgId in catalog))
160 catalog[msgId] = parseMessage(rawCatalog[msgId]); 160 catalog[msgId] = parseMessage(rawCatalog[msgId]);
161 } 161 }
162 }; 162 };
163 163
164 chrome.i18n = { 164 chrome.i18n = {
165 getUILanguage() 165 getUILanguage()
166 { 166 {
167 return locales[0]; 167 return locales[0].replace(/_/g, "-");
Sebastian Noack 2017/10/12 18:10:33 It seems the replacement here, has been redundant
saroyanm 2017/10/12 20:26:38 Well spotted, done.
168 }, 168 },
169 getMessage(msgId, substitutions) 169 getMessage(msgId, substitutions)
170 { 170 {
171 while (true) 171 while (true)
172 { 172 {
173 let message = catalog[msgId]; 173 let message = catalog[msgId];
174 if (message) 174 if (message)
175 { 175 {
176 let text = message[0]; 176 let text = message[0];
177 let placeholders = message[1]; 177 let placeholders = message[1];
(...skipping 10 matching lines...) Expand all
188 if (locales.length == 0) 188 if (locales.length == 0)
189 return ""; 189 return "";
190 190
191 let locale = locales.shift(); 191 let locale = locales.shift();
192 readCatalog(locale, "common.json"); 192 readCatalog(locale, "common.json");
193 readCatalog(locale, catalogFile); 193 readCatalog(locale, catalogFile);
194 } 194 }
195 } 195 }
196 }; 196 };
197 }()); 197 }());
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld