Skip to content

Commit

Permalink
Fixing i18n.getMessage for chrome 19 (dev), now placeholders must be …
Browse files Browse the repository at this point in the history
…strings.
  • Loading branch information
cezarsa committed Feb 26, 2012
1 parent e171494 commit ac86022
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,38 @@ var Util = {
LocaleTable.instance = new LocaleTable();

chrome.i18n.originalGetMessage = chrome.i18n.getMessage;
chrome.i18n.safeGetMessage = function() {
try {
return chrome.i18n.originalGetMessage.apply(chrome.i18n, arguments);
} catch(e) {
console.warn(e, e.stack);
}
return arguments[0];
}
chrome.i18n.getMessage = function(message, params) {
if(params) {
if(typeof params === "string" || params instanceof String) {
params = params.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
} else {
if(params.forEach && params.splice) {
for(var i = 0, len = params.length; i < len; ++i) {
var p = params[i];
if(typeof p === "string" || p instanceof String) {
params[i] = p.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
var p = String(params[i]);
p = p.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
params[i] = p;
}
} else {
params = String(params);
params = params.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
}
var newDefaultLocale = OptionsBackend.get('default_locale');
if(!LocaleTable.instance.ready || newDefaultLocale === 'auto') {
return chrome.i18n.originalGetMessage(message, params);
return chrome.i18n.safeGetMessage(message, params);
}
var localeObj = LocaleTable.instance.locales[newDefaultLocale];
if(!localeObj) {
return chrome.i18n.originalGetMessage(message, params);
return chrome.i18n.safeGetMessage(message, params);
}
var messageData = localeObj[message];
if(!messageData) {
return chrome.i18n.originalGetMessage(message, params);
return chrome.i18n.safeGetMessage(message, params);
}
var messageStr = messageData.message;
if(messageData.parsedPlaceholders) {
Expand Down
1 change: 1 addition & 0 deletions lib/timelines/unified_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ $.extend(UnifiedTweetsTimeline.prototype, TweetsTimeline.prototype, {
callback(resultTweetsList, _this.timelineId);
} catch(e) {
/* ignoring, popup dead? */
console.warn(e, e.stack);
}
};
var eachFunction = function (tweets, timelineId, timelineObj) {
Expand Down

0 comments on commit ac86022

Please sign in to comment.