Skip to content

Commit

Permalink
Add a basic MozLoopService
Browse files Browse the repository at this point in the history
  • Loading branch information
Standard8 committed May 6, 2014
1 parent f7639cf commit 05eab0b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
58 changes: 58 additions & 0 deletions browser/components/loop/MozLoopService.jsm
@@ -0,0 +1,58 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { classes: Cc, interfaces: Ci, utils: Cu } = Components;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

this.EXPORTED_SYMBOLS = ["MozLoopService"];

// Internal helper methods and state
let MozLoopServiceInternal = {
get localizedStrings() {
var stringBundle =
Services.strings.createBundle('chrome://browser/locale/loop/loop.properties');

var map = {};
var enumerator = stringBundle.getSimpleEnumeration();
while (enumerator.hasMoreElements()) {
var string = enumerator.getNext().QueryInterface(Ci.nsIPropertyElement);
var key = string.key, property = 'textContent';
var i = key.lastIndexOf('.');
if (i >= 0) {
property = key.substring(i + 1);
key = key.substring(0, i);
}
if (!(key in map))
map[key] = {};
map[key][property] = string.value;
}

delete this.localizedStrings;

This comment has been minimized.

Copy link
@mhammond

mhammond May 6, 2014

This module should have "use strict;" - which IIUC, will cause these 2 lines to generate a warning about setting a property that has no setter.

return this.localizedStrings = map;
}
};


// Public API
this.MozLoopService = {
getStrings: function(key) {
try {
return JSON.stringify(MozLoopServiceInternal.localizedStrings[key]);
} catch (ex) {
Cu.reportError('Unable to retrive localized strings: ' + e);
return null;
}
},

get locale() {
try {
return Services.prefs.getComplexValue("general.useragent.locale",
Ci.nsISupportsString).data;
} catch (ex) {
return "en-US";
}
}
};
6 changes: 6 additions & 0 deletions browser/components/loop/moz.build
Expand Up @@ -5,3 +5,9 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

JAR_MANIFESTS += ['jar.mn']

JS_MODULES_PATH = 'modules/loop'

EXTRA_JS_MODULES += [
'MozLoopService.jsm',
]

0 comments on commit 05eab0b

Please sign in to comment.