-
Notifications
You must be signed in to change notification settings - Fork 1
/
locale.mozcmd
51 lines (50 loc) · 1.47 KB
/
locale.mozcmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* 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/.
*
* Contributor(s):
* - LouCypher (original code)
*/
[
{
name: "locale",
description: "Change browser language.",
params: [
{
name: "langID",
type: "string",
defaultValue: null,
description: "Language ID. Enter `locale default` to use default locale."
}
],
returnType: "string",
exec: function(args, context) {
let prefname = "general.useragent.locale"; // See AMO warning below
/*
AMO warning from add-on validator:
---
Potentially unsafe preference branch referenced
Warning: Extensions should not alter preferences in this preference branch
---
I couldn't find another way to change browser locale without using preferences
*/
let prefs = Services.prefs;
let msgPrefix = "Browser language: '";
let msgSuffix = "'";
let lang = args.langID;
if (lang) {
switch (lang) {
case "default":
prefs.clearUserPref(prefname);
msgSuffix = "' (default)";
break;
default:
prefs.setCharPref(prefname, args.langID);
}
msgPrefix = "Browser language changed to '";
}
return msgPrefix + prefs.getCharPref(prefname) + msgSuffix;
}
}
]