Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / webconsole / utils / l10n.js
blob5c647f84e691435c1dfee0a1bb9c36033cb9f4db
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
8 const helper = new LocalizationHelper(
9 "devtools/client/locales/webconsole.properties"
12 const l10n = {
13 /**
14 * Generates a formatted timestamp string for displaying in console messages.
16 * @param integer [milliseconds]
17 * Optional, allows you to specify the timestamp in milliseconds since
18 * the UNIX epoch.
19 * @return string
20 * The timestamp formatted for display.
22 timestampString(milliseconds) {
23 const d = new Date(milliseconds ? milliseconds : null);
24 const hours = d.getHours();
25 const minutes = d.getMinutes();
26 const seconds = d.getSeconds();
27 milliseconds = d.getMilliseconds();
28 const parameters = [hours, minutes, seconds, milliseconds];
29 return l10n.getFormatStr("timestampFormat", parameters);
32 /**
33 * Retrieve a localized string.
35 * @param string name
36 * The string name you want from the Web Console string bundle.
37 * @return string
38 * The localized string.
40 getStr(name) {
41 try {
42 return helper.getStr(name);
43 } catch (ex) {
44 console.error("Failed to get string: " + name);
45 throw ex;
49 /**
50 * Retrieve a localized string formatted with values coming from the given
51 * array.
53 * @param string name
54 * The string name you want from the Web Console string bundle.
55 * @param array array
56 * The array of values you want in the formatted string.
57 * @return string
58 * The formatted local string.
60 getFormatStr(name, array) {
61 try {
62 return helper.getFormatStr(name, ...array);
63 } catch (ex) {
64 console.error("Failed to format string: " + name);
65 throw ex;
70 module.exports = l10n;