-
Notifications
You must be signed in to change notification settings - Fork 208
/
UiCore.ts
72 lines (60 loc) · 2.32 KB
/
UiCore.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
/** @module Utilities */
import { I18N, TranslationOptions } from "@bentley/imodeljs-i18n";
import { UiError, getClassName, UiAbstract } from "@bentley/ui-abstract";
/** Import color themes and Sass classes barrel file */
import "./colorthemes.scss";
import "./classes.scss";
/**
* Entry point for static initialization required by various
* components used in the package.
* @public
*/
export class UiCore {
private static _i18n?: I18N;
/**
* Called by IModelApp to initialize the UiCore
* @param i18n The internationalization service created by the IModelApp.
*/
public static async initialize(i18n: I18N): Promise<void> {
UiCore._i18n = i18n;
await UiCore._i18n.registerNamespace(UiCore.i18nNamespace).readFinished;
await UiAbstract.initialize(i18n);
}
/** Unregisters the UiCore internationalization service namespace */
public static terminate() {
if (UiCore._i18n)
UiCore._i18n.unregisterNamespace(UiCore.i18nNamespace);
UiCore._i18n = undefined;
UiAbstract.terminate();
}
/** The internationalization service created by the IModelApp. */
public static get i18n(): I18N {
if (!UiCore._i18n)
throw new UiError(UiCore.loggerCategory(this), "UiCore not initialized");
return UiCore._i18n;
}
/** The internationalization service namespace. */
public static get i18nNamespace(): string {
return "UiCore";
}
/** Calls i18n.translateWithNamespace with the "UiCore" namespace. Do NOT include the namespace in the key.
* @internal
*/
public static translate(key: string | string[], options?: TranslationOptions): string {
return UiCore.i18n.translateWithNamespace(UiCore.i18nNamespace, key, options);
}
/** @internal */
public static get packageName(): string {
return "ui-core";
}
/** @internal */
public static loggerCategory(obj: any): string {
const className = getClassName(obj);
const category = UiCore.packageName + (className ? `.${className}` : "");
return category;
}
}