-
Notifications
You must be signed in to change notification settings - Fork 6
/
nls-replace.js
92 lines (87 loc) · 2.96 KB
/
nls-replace.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Modified to support localization.
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const globalScope = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : global;
let isPseudo = (typeof document !== 'undefined' && document.location && document.location.hash.indexOf('pseudo=true') >= 0);
function _format(message, args) {
let result;
if (args.length === 0) {
result = message;
}
else {
result = message.replace(/\{(\d+)\}/g, function (match, rest) {
const index = rest[0];
return typeof args[index] !== 'undefined' ? args[index] : match;
});
}
if (isPseudo) {
// FF3B and FF3D is the Unicode zenkaku representation for [ and ]
result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
}
return result;
}
/**
* @skipMangle
*/
export function localize(path, data, defaultMessage, ...args) {
const key = typeof data=== "object" ? data.key : data;
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
// let message = (data[path]||{})[key];
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
let message = (localeData[path] || {})[key];
if (!message) {
message = defaultMessage;
}
args = [];
for (let _i = 3; _i < arguments.length; _i++) {
args[_i - 3] = arguments[_i];
}
return _format(message, args);
}
/**
* @skipMangle
*/
export function localize2(path, data, defaultMessage, ...args) {
const key = typeof data=== "object" ? data.key : data;
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
// let message = (data[path]||{})[key];
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
let message = (localeData[path] || {})[key];
if (!message) {
message = defaultMessage;
}
args = [];
for (let _i = 3; _i < arguments.length; _i++) {
args[_i - 3] = arguments[_i];
}
const original = _format(message, args);
return {
value: original,
original
};
}
export function loadMessageBundle(file) {
return localize;
}
export function config(opt) {
return loadMessageBundle;
}
/**
* @skipMangle
*/
export function getConfiguredDefaultLocale() {
return (self.MonacoLocale || {}).language;
}
/**
* @skipMangle
*/
export function getNLSLanguage() {
return (self.MonacoLocale || {}).language;
}
export function getNLSMessages() {
return ((self.MonacoLocale || {}) || {}).data || {};
}