1 | ;
|
2 | // *****************************************************************************
|
3 | // Copyright (C) 2021 TypeFox and others.
|
4 | //
|
5 | // This program and the accompanying materials are made available under the
|
6 | // terms of the Eclipse Public License v. 2.0 which is available at
|
7 | // http://www.eclipse.org/legal/epl-2.0.
|
8 | //
|
9 | // This Source Code may also be made available under the following Secondary
|
10 | // Licenses when the conditions for such availability set forth in the Eclipse
|
11 | // Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
12 | // with the GNU Classpath Exception which is available at
|
13 | // https://www.gnu.org/software/classpath/license.html.
|
14 | //
|
15 | // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
16 | // *****************************************************************************
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.Localization = exports.AsyncLocalizationProvider = exports.localizationPath = void 0;
|
19 | exports.localizationPath = '/services/i18n';
|
20 | exports.AsyncLocalizationProvider = Symbol('AsyncLocalizationProvider');
|
21 | var Localization;
|
22 | (function (Localization) {
|
23 | const formatRegexp = /{([^}]+)}/g;
|
24 | function format(message, args) {
|
25 | return message.replace(formatRegexp, (match, group) => { var _a; return ((_a = args[group]) !== null && _a !== void 0 ? _a : match); });
|
26 | }
|
27 | Localization.format = format;
|
28 | function localize(localization, key, defaultValue, ...args) {
|
29 | let value = defaultValue;
|
30 | if (localization) {
|
31 | const translation = localization.translations[key];
|
32 | if (translation) {
|
33 | value = normalize(translation);
|
34 | }
|
35 | }
|
36 | return format(value, args);
|
37 | }
|
38 | Localization.localize = localize;
|
39 | /**
|
40 | * This function normalizes values from VSCode's localizations, which often contain additional mnemonics (`&&`).
|
41 | * The normalization removes the mnemonics from the input string.
|
42 | *
|
43 | * @param value Localization value coming from VSCode
|
44 | * @returns A normalized localized value
|
45 | */
|
46 | function normalize(value) {
|
47 | return value.replace(/&&/g, '');
|
48 | }
|
49 | Localization.normalize = normalize;
|
50 | function transformKey(key) {
|
51 | let nlsKey = key;
|
52 | const keySlashIndex = key.lastIndexOf('/');
|
53 | if (keySlashIndex >= 0) {
|
54 | nlsKey = key.substring(keySlashIndex + 1);
|
55 | }
|
56 | return nlsKey;
|
57 | }
|
58 | Localization.transformKey = transformKey;
|
59 | })(Localization = exports.Localization || (exports.Localization = {}));
|
60 | //# sourceMappingURL=localization.js.map |
\ | No newline at end of file |