 Issue 11165026:
  Show notifications on startup  (Closed)
    
  
    Issue 11165026:
  Show notifications on startup  (Closed) 
  | 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(); |