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

Unified Diff: lib/notification.js

Issue 11165026: Show notifications on startup (Closed)
Patch Set: Created July 19, 2013, 1:41 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/skin/overlay.css ('k') | lib/ui.js » ('j') | lib/ui.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/notification.js
===================================================================
--- a/lib/notification.js
+++ b/lib/notification.js
@@ -24,6 +24,7 @@
let {TimeLine} = require("timeline");
let {Prefs} = require("prefs");
let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
+let {Utils} = require("utils");
let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE;
let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
@@ -41,6 +42,19 @@
Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata));
}
+function localize(translations, locale)
+{
+ if (locale in translations)
+ return translations[locale];
+
+ let languagePart = locale.substring(0, locale.indexOf("-"));
+ if (languagePart && languagePart in translations)
+ return translations[languagePart];
+
+ let defaultLocale = "en";
Wladimir Palant 2013/07/19 15:17:52 Actually, our default locale is always en-US - and
Felix Dahlke 2013/07/19 17:07:01 Done.
+ return translations[defaultLocale];
+}
+
/**
* The object providing actual downloading functionality.
* @type Downloader
@@ -175,6 +189,26 @@
}
return notificationToShow;
+ },
+
+ /**
+ * Localizes the texts of the supplied notification.
+ * @param {Object} notification notification to translate
+ * @param {String} locale the target locale (optional, defaults to the
+ * application locale)
+ * @return {Object} the translated texts
+ */
+ getLocalizedTexts: function(notification, locale)
+ {
+ locale = locale || Utils.appLocale;
+ let textKeys = ["title", "message"];
+ let localizedTexts = [];
+ for each (let key in textKeys)
+ {
+ if (key in notification)
+ localizedTexts[key] = localize(notification[key], locale);
+ }
+ return localizedTexts;
}
};
Notification.init();
« no previous file with comments | « chrome/skin/overlay.css ('k') | lib/ui.js » ('j') | lib/ui.js » ('J')

Powered by Google App Engine
This is Rietveld