forked from mozilla/gecko-dev
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong. |
||
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"; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.