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

Side by Side Diff: lib/utils.js

Issue 29338190: Issue 3697 - Fall back to i18n.getUILanguage if @ui_locale isn't supported (Closed)
Patch Set: Add try-catch blocks. Address nits. Created May 29, 2016, 12:23 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/notificationHelper.js ('k') | safari/ext/common.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 26 matching lines...) Expand all
37 }; 37 };
38 document.addEventListener("DOMContentLoaded", onDOMContentLoaded); 38 document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
39 } 39 }
40 else 40 else
41 { 41 {
42 setTimeout(callback, 0); 42 setTimeout(callback, 0);
43 } 43 }
44 }, 44 },
45 get appLocale() 45 get appLocale()
46 { 46 {
47 var locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 47 var locale;
48 try
49 {
50 locale = ext.i18n.getMessage("@@ui_locale");
51 }
52 catch (exception)
53 {
54 // Edge does not yet (?) support @@ui_locale, throwing an exception here.
55 }
56 if (!locale)
57 locale = ext.i18n.getUILanguage();
Sebastian Noack 2017/08/23 12:26:44 It seems we can use chrome.i18n.getUILanguage() re
58 locale = locale.replace(/_/g, "-");
48 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true}); 59 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
49 return this.appLocale; 60 return this.appLocale;
50 }, 61 },
62 get readingDirection()
63 {
64 var direction;
65 try
66 {
67 direction = ext.i18n.getMessage("@@bidi_dir");
68 }
69 catch (exception)
70 {
71 // Edge does not yet (?) support @@bidi_dir, throwing an exception here.
72 }
73 if (!direction)
74 direction = /^(ar|fa|he|ug|ur)(_|$)/.test(this.appLocale) ? "rtl" : "ltr";
75 Object.defineProperty(this, "readingDirection", {value: direction, enumerabl e: true});
76 return this.readingDirection;
77 },
51 generateChecksum: function(lines) 78 generateChecksum: function(lines)
52 { 79 {
53 // We cannot calculate MD5 checksums yet :-( 80 // We cannot calculate MD5 checksums yet :-(
54 return null; 81 return null;
55 }, 82 },
56 checkLocalePrefixMatch: function(prefixes) 83 checkLocalePrefixMatch: function(prefixes)
57 { 84 {
58 if (!prefixes) 85 if (!prefixes)
59 return null; 86 return null;
60 87
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 { 136 {
110 var Prefs = require("prefs").Prefs; 137 var Prefs = require("prefs").Prefs;
111 var docLink = Prefs.documentation_link; 138 var docLink = Prefs.documentation_link;
112 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale ); 139 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale );
113 }, 140 },
114 141
115 yield: function() 142 yield: function()
116 { 143 {
117 } 144 }
118 }; 145 };
OLDNEW
« no previous file with comments | « lib/notificationHelper.js ('k') | safari/ext/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld