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

Delta Between Two Patch Sets: ext/common.js

Issue 29345232: Issue 4084 - Do not use @@bidi_dir directly in adblockplusui (Closed)
Left Patch Set: Also adapt the mock implementation Created May 30, 2016, 1:58 p.m.
Right Patch Set: Fix rebase artifacts Created Aug. 29, 2017, 11:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | messageResponder.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 candidates.push(language + "-" + region); 92 candidates.push(language + "-" + region);
93 93
94 candidates.push(language); 94 candidates.push(language);
95 95
96 if (candidates.indexOf(defaultLocale) == -1) 96 if (candidates.indexOf(defaultLocale) == -1)
97 candidates.push(defaultLocale); 97 candidates.push(defaultLocale);
98 98
99 return candidates; 99 return candidates;
100 }; 100 };
101 101
102 let initCatalog = function(uiLocale)
103 {
104 let bidiDir = /^(ar|fa|he|ug|ur)(-|$)/.test(uiLocale) ? "rtl" : "ltr";
105 let catalog = Object.create(null);
106
107 catalog["@@ui_locale"] = [uiLocale.replace(/-/g, "_"), []];
108 catalog["@@bidi_dir"] = [bidiDir, []];
109
110 return catalog;
111 };
112
113 let selectedLocale = window.navigator.language; 102 let selectedLocale = window.navigator.language;
114 let match = /[?&]locale=([\w-]+)/.exec(window.location.search); 103 let match = /[?&]locale=([\w-]+)/.exec(window.location.search);
115 if (match) 104 if (match)
116 selectedLocale = match[1]; 105 selectedLocale = match[1];
117 106
118 let locales = getLocaleCandidates(selectedLocale); 107 let locales = getLocaleCandidates(selectedLocale);
119 let catalog = initCatalog(locales[0]); 108 let catalog = Object.create(null);
120 let catalogFile = window.location.pathname.replace(/.*\//, "") 109 let catalogFile = window.location.pathname.replace(/.*\//, "")
121 .replace(/\..*/, "") + ".json"; 110 .replace(/\..*/, "") + ".json";
122 111
123 let replacePlaceholder = function(text, placeholder, content) 112 let replacePlaceholder = function(text, placeholder, content)
124 { 113 {
125 return text.split("$" + placeholder + "$").join(content || ""); 114 return text.split("$" + placeholder + "$").join(content || "");
126 }; 115 };
127 116
128 let parseMessage = function(rawMessage) 117 let parseMessage = function(rawMessage)
129 { 118 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 152
164 let rawCatalog = JSON.parse(xhr.responseText); 153 let rawCatalog = JSON.parse(xhr.responseText);
165 for (let msgId in rawCatalog) 154 for (let msgId in rawCatalog)
166 { 155 {
167 if (!(msgId in catalog)) 156 if (!(msgId in catalog))
168 catalog[msgId] = parseMessage(rawCatalog[msgId]); 157 catalog[msgId] = parseMessage(rawCatalog[msgId]);
169 } 158 }
170 }; 159 };
171 160
172 window.ext.i18n = { 161 window.ext.i18n = {
162 locale: locales[0],
173 getMessage(msgId, substitutions) 163 getMessage(msgId, substitutions)
174 { 164 {
175 while (true) 165 while (true)
176 { 166 {
177 let message = catalog[msgId]; 167 let message = catalog[msgId];
178 if (message) 168 if (message)
179 { 169 {
180 let text = message[0]; 170 let text = message[0];
181 let placeholders = message[1]; 171 let placeholders = message[1];
182 172
183 if (!(substitutions instanceof Array)) 173 if (!(substitutions instanceof Array))
184 substitutions = [substitutions]; 174 substitutions = [substitutions];
185 175
186 for (let i = 0; i < placeholders.length; i++) 176 for (let i = 0; i < placeholders.length; i++)
187 text = replacePlaceholder(text, placeholders[i], substitutions[i]); 177 text = replacePlaceholder(text, placeholders[i], substitutions[i]);
188 178
189 return text; 179 return text;
190 } 180 }
191 181
192 if (locales.length == 0) 182 if (locales.length == 0)
193 return ""; 183 return "";
194 184
195 let locale = locales.shift(); 185 let locale = locales.shift();
196 readCatalog(locale, "common.json"); 186 readCatalog(locale, "common.json");
197 readCatalog(locale, catalogFile); 187 readCatalog(locale, catalogFile);
198 } 188 }
199 } 189 }
200 }; 190 };
201 }()); 191 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld