@umbraco-cms/backoffice 14.0.0-2a03783e → 14.0.0-2f667994
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cms/apps/app/app.element.d.ts +11 -1
- package/dist-cms/apps/app/app.element.js +25 -1
- package/dist-cms/apps/backoffice/backoffice.element.d.ts +0 -1
- package/dist-cms/apps/backoffice/backoffice.element.js +3 -4
- package/dist-cms/assets/lang/da-dk.d.ts +3 -0
- package/dist-cms/assets/lang/da-dk.js +2989 -0
- package/dist-cms/assets/lang/da-dk.ts +3246 -0
- package/dist-cms/assets/lang/en-us.d.ts +3 -0
- package/dist-cms/assets/lang/en-us.js +2966 -0
- package/dist-cms/assets/lang/en-us.ts +3219 -0
- package/dist-cms/custom-elements.json +72 -0
- package/dist-cms/external/backend-api/index.js +1 -1
- package/dist-cms/external/tinymce/index.js +22 -22
- package/dist-cms/libs/controller-api/controller-host-element.mixin.d.ts +9 -3
- package/dist-cms/libs/element-api/element.mixin.d.ts +9 -2
- package/dist-cms/libs/element-api/element.mixin.js +21 -0
- package/dist-cms/libs/extension-api/types.d.ts +8 -0
- package/dist-cms/libs/localization-api/index.d.ts +3 -0
- package/dist-cms/libs/localization-api/index.js +3 -0
- package/dist-cms/libs/localization-api/localize.controller.d.ts +47 -0
- package/dist-cms/libs/localization-api/localize.controller.js +125 -0
- package/dist-cms/libs/localization-api/manager.d.ts +18 -0
- package/dist-cms/libs/localization-api/manager.js +40 -0
- package/dist-cms/libs/localization-api/registry/translation.registry.d.ts +12 -0
- package/dist-cms/libs/localization-api/registry/translation.registry.js +58 -0
- package/dist-cms/libs/observable-api/observer.controller.d.ts +2 -2
- package/dist-cms/libs/observable-api/observer.d.ts +7 -1
- package/dist-cms/packages/core/extension-registry/models/index.d.ts +3 -1
- package/dist-cms/packages/core/extension-registry/models/index.js +1 -0
- package/dist-cms/packages/core/extension-registry/models/translations.model.d.ts +41 -0
- package/dist-cms/packages/core/extension-registry/models/translations.model.js +1 -0
- package/dist-cms/packages/core/index.d.ts +1 -0
- package/dist-cms/packages/core/index.js +3 -0
- package/dist-cms/packages/core/localization/index.d.ts +1 -0
- package/dist-cms/packages/core/localization/index.js +1 -0
- package/dist-cms/packages/core/localization/localize.element.d.ts +34 -0
- package/dist-cms/packages/core/localization/localize.element.js +64 -0
- package/dist-cms/packages/core/localization/manifests.d.ts +2 -0
- package/dist-cms/packages/core/localization/manifests.js +23 -0
- package/dist-cms/packages/umbraco-news/umbraco-news-dashboard.element.js +1 -1
- package/dist-cms/packages/users/current-user/modals/current-user/current-user-modal.element.js +10 -6
- package/dist-cms/packages/users/current-user/user-profile-apps/user-profile-app-profile.element.js +7 -5
- package/dist-cms/packages/users/users/repository/user.repository.js +5 -1
- package/dist-cms/packages/users/users/workspace/user-workspace-editor.element.d.ts +1 -0
- package/dist-cms/packages/users/users/workspace/user-workspace-editor.element.js +51 -6
- package/dist-cms/packages/users/users/workspace/user-workspace.context.d.ts +1 -1
- package/dist-cms/packages/users/users/workspace/user-workspace.context.js +17 -0
- package/dist-cms/shared/auth/auth.context.d.ts +1 -0
- package/dist-cms/shared/auth/auth.context.js +1 -2
- package/dist-cms/shared/auth/auth.interface.d.ts +4 -0
- package/dist-cms/shared/utils/media-helper.service.js +1 -0
- package/dist-cms/tsconfig.build.json +15 -0
- package/dist-cms/tsconfig.build.tsbuildinfo +1 -0
- package/dist-cms/umbraco-package-schema.json +83 -3
- package/dist-cms/vscode-html-custom-data.json +28 -4
- package/package.json +5 -4
- package/dist-cms/tsconfig.tsbuildinfo +0 -1
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { UmbLocalizeController } from '../localization-api/index.js';
|
|
2
|
+
import type { HTMLElementConstructor } from '../extension-api/types.js';
|
|
3
|
+
import type { UmbControllerAlias } from './controller-alias.type.js';
|
|
4
|
+
import type { UmbControllerHost } from './controller-host.interface.js';
|
|
4
5
|
import type { UmbController } from './controller.interface.js';
|
|
5
6
|
export declare class UmbControllerHostElement extends HTMLElement implements UmbControllerHost {
|
|
7
|
+
/**
|
|
8
|
+
* Use the UmbLocalizeController to localize your element.
|
|
9
|
+
* @see UmbLocalizeController
|
|
10
|
+
*/
|
|
11
|
+
localize: UmbLocalizeController;
|
|
6
12
|
hasController(controller: UmbController): boolean;
|
|
7
13
|
getControllers(filterMethod: (ctrl: UmbController) => boolean): UmbController[];
|
|
8
14
|
addController(controller: UmbController): void;
|
|
@@ -2,11 +2,18 @@ import type { Observable } from '../../external/rxjs/index.js';
|
|
|
2
2
|
import type { HTMLElementConstructor } from '../extension-api/index.js';
|
|
3
3
|
import type { UmbControllerHostElement } from '../controller-api/index.js';
|
|
4
4
|
import { UmbContextToken, UmbContextCallback, UmbContextConsumerController, UmbContextProviderController } from '../context-api/index.js';
|
|
5
|
-
import { UmbObserverController } from '../observable-api/index.js';
|
|
5
|
+
import { ObserverCallback, UmbObserverController } from '../observable-api/index.js';
|
|
6
6
|
export declare class UmbElement extends UmbControllerHostElement {
|
|
7
|
+
/**
|
|
8
|
+
* @description Observe a RxJS source of choice.
|
|
9
|
+
* @param {Observable<T>} source RxJS source
|
|
10
|
+
* @param {method} callback Callback method called when data is changed.
|
|
11
|
+
* @return {UmbObserverController} Reference to a Observer Controller instance
|
|
12
|
+
* @memberof UmbElementMixin
|
|
13
|
+
*/
|
|
7
14
|
observe<T>(source: Observable<T> | {
|
|
8
15
|
asObservable: () => Observable<T>;
|
|
9
|
-
}, callback:
|
|
16
|
+
}, callback: ObserverCallback<T>, unique?: string): UmbObserverController<T>;
|
|
10
17
|
provideContext<R = unknown>(alias: string | UmbContextToken<R>, instance: R): UmbContextProviderController<R>;
|
|
11
18
|
consumeContext<R = unknown>(alias: string | UmbContextToken<R>, callback: UmbContextCallback<R>): UmbContextConsumerController<R>;
|
|
12
19
|
}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
import { UmbControllerHostElementMixin } from '../controller-api/index.js';
|
|
2
8
|
import { UmbContextConsumerController, UmbContextProviderController, } from '../context-api/index.js';
|
|
3
9
|
import { UmbObserverController } from '../observable-api/index.js';
|
|
10
|
+
import { UmbLocalizeController } from '../localization-api/index.js';
|
|
11
|
+
import { property } from '../../external/lit/index.js';
|
|
4
12
|
export const UmbElementMixin = (superClass) => {
|
|
5
13
|
class UmbElementMixinClass extends UmbControllerHostElementMixin(superClass) {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
// Make `dir` and `lang` reactive properties so they react to language changes:
|
|
17
|
+
this.dir = '';
|
|
18
|
+
this.lang = '';
|
|
19
|
+
this.localize = new UmbLocalizeController(this);
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* @description Observe a RxJS source of choice.
|
|
8
23
|
* @param {Observable<T>} source RxJS source
|
|
@@ -34,5 +49,11 @@ export const UmbElementMixin = (superClass) => {
|
|
|
34
49
|
return new UmbContextConsumerController(this, alias, callback);
|
|
35
50
|
}
|
|
36
51
|
}
|
|
52
|
+
__decorate([
|
|
53
|
+
property()
|
|
54
|
+
], UmbElementMixinClass.prototype, "dir", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
property()
|
|
57
|
+
], UmbElementMixinClass.prototype, "lang", void 0);
|
|
37
58
|
return UmbElementMixinClass;
|
|
38
59
|
};
|
|
@@ -78,6 +78,14 @@ export interface ManifestClass<ClassType = unknown> extends ManifestWithLoader<{
|
|
|
78
78
|
export interface ManifestClassWithClassConstructor<T = unknown> extends ManifestClass<T> {
|
|
79
79
|
class: ClassConstructor<T>;
|
|
80
80
|
}
|
|
81
|
+
export interface ManifestWithLoaderIncludingDefaultExport<T = unknown> extends ManifestWithLoader<{
|
|
82
|
+
default: T;
|
|
83
|
+
} | Omit<object, 'default'>> {
|
|
84
|
+
/**
|
|
85
|
+
* The file location of the javascript file to load
|
|
86
|
+
*/
|
|
87
|
+
js?: string;
|
|
88
|
+
}
|
|
81
89
|
export interface ManifestElement<ElementType extends HTMLElement = HTMLElement> extends ManifestWithLoader<{
|
|
82
90
|
default: ClassConstructor<ElementType>;
|
|
83
91
|
} | Omit<object, 'default'>> {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DefaultTranslationSet, FunctionParams, TranslationSet } from './manager.js';
|
|
2
|
+
import { UmbController, UmbControllerHost } from '../controller-api/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The UmbLocalizeController enables localization for your element.
|
|
5
|
+
*
|
|
6
|
+
* @see UmbLocalizeElement
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { UmbLocalizeController } from './index.js';
|
|
10
|
+
*
|
|
11
|
+
* \@customElement('my-element')
|
|
12
|
+
* export class MyElement extends LitElement {
|
|
13
|
+
* private localize = new UmbLocalizeController(this);
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`<p>${this.localize.term('general_close')}</p>`;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class UmbLocalizeController<TranslationType extends TranslationSet = DefaultTranslationSet> implements UmbController {
|
|
22
|
+
#private;
|
|
23
|
+
controllerAlias: symbol;
|
|
24
|
+
constructor(host: UmbControllerHost);
|
|
25
|
+
hostConnected(): void;
|
|
26
|
+
hostDisconnected(): void;
|
|
27
|
+
destroy(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to
|
|
30
|
+
* lowercase.
|
|
31
|
+
*/
|
|
32
|
+
dir(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Gets the host element's language as determined by the `lang` attribute. The return value is transformed to
|
|
35
|
+
* lowercase.
|
|
36
|
+
*/
|
|
37
|
+
lang(): string;
|
|
38
|
+
private getTranslationData;
|
|
39
|
+
/** Outputs a translated term. */
|
|
40
|
+
term<K extends keyof TranslationType>(key: K, ...args: FunctionParams<TranslationType[K]>): string;
|
|
41
|
+
/** Outputs a localized date in the specified format. */
|
|
42
|
+
date(dateToFormat: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
43
|
+
/** Outputs a localized number in the specified format. */
|
|
44
|
+
number(numberToFormat: number | string, options?: Intl.NumberFormatOptions): string;
|
|
45
|
+
/** Outputs a localized time in relative format. */
|
|
46
|
+
relativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This module is a modified copy of the original Shoelace localize package: https://github.com/shoelace-style/localize
|
|
3
|
+
|
|
4
|
+
The original license is included below.
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2020 A Beautiful Site, LLC
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
13
|
+
*/
|
|
14
|
+
import { connectedElements, documentDirection, documentLanguage, fallback, translations, } from './manager.js';
|
|
15
|
+
const LocalizeControllerAlias = Symbol();
|
|
16
|
+
/**
|
|
17
|
+
* The UmbLocalizeController enables localization for your element.
|
|
18
|
+
*
|
|
19
|
+
* @see UmbLocalizeElement
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { UmbLocalizeController } from './index.js';
|
|
23
|
+
*
|
|
24
|
+
* \@customElement('my-element')
|
|
25
|
+
* export class MyElement extends LitElement {
|
|
26
|
+
* private localize = new UmbLocalizeController(this);
|
|
27
|
+
*
|
|
28
|
+
* render() {
|
|
29
|
+
* return html`<p>${this.localize.term('general_close')}</p>`;
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class UmbLocalizeController {
|
|
35
|
+
#host;
|
|
36
|
+
#hostEl;
|
|
37
|
+
constructor(host) {
|
|
38
|
+
this.controllerAlias = LocalizeControllerAlias;
|
|
39
|
+
this.#host = host;
|
|
40
|
+
this.#hostEl = host.getHostElement();
|
|
41
|
+
this.#host.addController(this);
|
|
42
|
+
}
|
|
43
|
+
hostConnected() {
|
|
44
|
+
if (connectedElements.has(this.#hostEl)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
connectedElements.add(this.#hostEl);
|
|
48
|
+
}
|
|
49
|
+
hostDisconnected() {
|
|
50
|
+
connectedElements.delete(this.#hostEl);
|
|
51
|
+
}
|
|
52
|
+
destroy() {
|
|
53
|
+
// We do not need to call delete here, as hostDisconnected is called when controller is removed.
|
|
54
|
+
//connectedElements.delete(this.host);
|
|
55
|
+
this.#host.removeController(this);
|
|
56
|
+
this.#hostEl = undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to
|
|
60
|
+
* lowercase.
|
|
61
|
+
*/
|
|
62
|
+
dir() {
|
|
63
|
+
return `${this.#hostEl.dir || documentDirection}`.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the host element's language as determined by the `lang` attribute. The return value is transformed to
|
|
67
|
+
* lowercase.
|
|
68
|
+
*/
|
|
69
|
+
lang() {
|
|
70
|
+
return `${this.#hostEl.lang || documentLanguage}`.toLowerCase();
|
|
71
|
+
}
|
|
72
|
+
getTranslationData(lang) {
|
|
73
|
+
const locale = new Intl.Locale(lang);
|
|
74
|
+
const language = locale?.language.toLowerCase();
|
|
75
|
+
const region = locale?.region?.toLowerCase() ?? '';
|
|
76
|
+
const primary = translations.get(`${language}-${region}`);
|
|
77
|
+
const secondary = translations.get(language);
|
|
78
|
+
return { locale, language, region, primary, secondary };
|
|
79
|
+
}
|
|
80
|
+
/** Outputs a translated term. */
|
|
81
|
+
term(key, ...args) {
|
|
82
|
+
const { primary, secondary } = this.getTranslationData(this.lang());
|
|
83
|
+
let term;
|
|
84
|
+
// Look for a matching term using regionCode, code, then the fallback
|
|
85
|
+
if (primary && primary[key]) {
|
|
86
|
+
term = primary[key];
|
|
87
|
+
}
|
|
88
|
+
else if (secondary && secondary[key]) {
|
|
89
|
+
term = secondary[key];
|
|
90
|
+
}
|
|
91
|
+
else if (fallback && fallback[key]) {
|
|
92
|
+
term = fallback[key];
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return String(key);
|
|
96
|
+
}
|
|
97
|
+
if (typeof term === 'function') {
|
|
98
|
+
return term(...args);
|
|
99
|
+
}
|
|
100
|
+
if (typeof term === 'string') {
|
|
101
|
+
if (args.length > 0) {
|
|
102
|
+
// Replace placeholders of format "%index%" and "{index}" with provided values
|
|
103
|
+
term = term.replace(/(%(\d+)%|\{(\d+)\})/g, (match, _p1, p2, p3) => {
|
|
104
|
+
const index = p2 || p3;
|
|
105
|
+
return String(args[index] || match);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return term;
|
|
110
|
+
}
|
|
111
|
+
/** Outputs a localized date in the specified format. */
|
|
112
|
+
date(dateToFormat, options) {
|
|
113
|
+
dateToFormat = new Date(dateToFormat);
|
|
114
|
+
return new Intl.DateTimeFormat(this.lang(), options).format(dateToFormat);
|
|
115
|
+
}
|
|
116
|
+
/** Outputs a localized number in the specified format. */
|
|
117
|
+
number(numberToFormat, options) {
|
|
118
|
+
numberToFormat = Number(numberToFormat);
|
|
119
|
+
return isNaN(numberToFormat) ? '' : new Intl.NumberFormat(this.lang(), options).format(numberToFormat);
|
|
120
|
+
}
|
|
121
|
+
/** Outputs a localized time in relative format. */
|
|
122
|
+
relativeTime(value, unit, options) {
|
|
123
|
+
return new Intl.RelativeTimeFormat(this.lang(), options).format(value, unit);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { UmbTranslationEntry } from '../../packages/core/extension-registry/index.js';
|
|
2
|
+
export type FunctionParams<T> = T extends (...args: infer U) => string ? U : [];
|
|
3
|
+
export interface TranslationSet {
|
|
4
|
+
$code: string;
|
|
5
|
+
$dir: 'ltr' | 'rtl';
|
|
6
|
+
}
|
|
7
|
+
export interface DefaultTranslationSet extends TranslationSet {
|
|
8
|
+
[key: string]: UmbTranslationEntry;
|
|
9
|
+
}
|
|
10
|
+
export declare const connectedElements: Set<HTMLElement>;
|
|
11
|
+
export declare const translations: Map<string, TranslationSet>;
|
|
12
|
+
export declare let documentDirection: string;
|
|
13
|
+
export declare let documentLanguage: string;
|
|
14
|
+
export declare let fallback: TranslationSet;
|
|
15
|
+
/** Registers one or more translations */
|
|
16
|
+
export declare function registerTranslation(...translation: TranslationSet[]): void;
|
|
17
|
+
/** Updates all localized elements that are currently connected */
|
|
18
|
+
export declare function update(): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const connectedElements = new Set();
|
|
2
|
+
const documentElementObserver = new MutationObserver(update);
|
|
3
|
+
export const translations = new Map();
|
|
4
|
+
export let documentDirection = document.documentElement.dir || 'ltr';
|
|
5
|
+
export let documentLanguage = document.documentElement.lang || navigator.language;
|
|
6
|
+
export let fallback;
|
|
7
|
+
// Watch for changes on <html lang>
|
|
8
|
+
documentElementObserver.observe(document.documentElement, {
|
|
9
|
+
attributes: true,
|
|
10
|
+
attributeFilter: ['dir', 'lang'],
|
|
11
|
+
});
|
|
12
|
+
/** Registers one or more translations */
|
|
13
|
+
export function registerTranslation(...translation) {
|
|
14
|
+
translation.map((t) => {
|
|
15
|
+
const code = t.$code.toLowerCase();
|
|
16
|
+
if (translations.has(code)) {
|
|
17
|
+
// Merge translations that share the same language code
|
|
18
|
+
translations.set(code, { ...translations.get(code), ...t });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
translations.set(code, t);
|
|
22
|
+
}
|
|
23
|
+
// The first translation that's registered is the fallback
|
|
24
|
+
if (!fallback) {
|
|
25
|
+
fallback = t;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
update();
|
|
29
|
+
}
|
|
30
|
+
/** Updates all localized elements that are currently connected */
|
|
31
|
+
export function update() {
|
|
32
|
+
documentDirection = document.documentElement.dir || 'ltr';
|
|
33
|
+
documentLanguage = document.documentElement.lang || navigator.language;
|
|
34
|
+
[...connectedElements.keys()].map((el) => {
|
|
35
|
+
if (typeof el.requestUpdate === 'function') {
|
|
36
|
+
// TODO: We might want to implement a specific Umbraco method for informing about this. and then make the default UmbLitElement call requestUpdate..? Cause then others can implement their own solution?
|
|
37
|
+
el.requestUpdate();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UmbBackofficeExtensionRegistry, UmbTranslationEntry } from '../../../packages/core/extension-registry/index.js';
|
|
2
|
+
export type UmbTranslationsFlatDictionary = Record<string, UmbTranslationEntry>;
|
|
3
|
+
export declare class UmbTranslationRegistry {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(extensionRegistry: UmbBackofficeExtensionRegistry);
|
|
6
|
+
/**
|
|
7
|
+
* Load a language from the extension registry.
|
|
8
|
+
* @param locale The locale to load.
|
|
9
|
+
*/
|
|
10
|
+
loadLanguage(locale: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const umbTranslationRegistry: UmbTranslationRegistry;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { registerTranslation } from '../manager.js';
|
|
2
|
+
import { hasDefaultExport, loadExtension } from '../../extension-api/index.js';
|
|
3
|
+
import { umbExtensionsRegistry, } from '../../../packages/core/extension-registry/index.js';
|
|
4
|
+
import { Subject, combineLatest, map, distinctUntilChanged } from '../../../external/rxjs/index.js';
|
|
5
|
+
export class UmbTranslationRegistry {
|
|
6
|
+
#currentLanguage = new Subject();
|
|
7
|
+
#currentLanguageUnique = this.#currentLanguage.pipe(map((x) => x.toLowerCase()), distinctUntilChanged());
|
|
8
|
+
constructor(extensionRegistry) {
|
|
9
|
+
combineLatest([this.#currentLanguageUnique, extensionRegistry.extensionsOfType('translations')]).subscribe(async ([userCulture, extensions]) => {
|
|
10
|
+
const locale = new Intl.Locale(userCulture);
|
|
11
|
+
const translations = await Promise.all(extensions
|
|
12
|
+
.filter((x) => x.meta.culture.toLowerCase() === locale.baseName.toLowerCase() ||
|
|
13
|
+
x.meta.culture.toLowerCase() === locale.language.toLowerCase())
|
|
14
|
+
.map(async (extension) => {
|
|
15
|
+
const innerDictionary = {};
|
|
16
|
+
// If extension contains a dictionary, add it to the inner dictionary.
|
|
17
|
+
if (extension.meta.translations) {
|
|
18
|
+
for (const [dictionaryName, dictionary] of Object.entries(extension.meta.translations)) {
|
|
19
|
+
this.#addOrUpdateDictionary(innerDictionary, dictionaryName, dictionary);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// If extension contains a js file, load it and add the default dictionary to the inner dictionary.
|
|
23
|
+
const loadedExtension = await loadExtension(extension);
|
|
24
|
+
if (loadedExtension && hasDefaultExport(loadedExtension)) {
|
|
25
|
+
for (const [dictionaryName, dictionary] of Object.entries(loadedExtension.default)) {
|
|
26
|
+
this.#addOrUpdateDictionary(innerDictionary, dictionaryName, dictionary);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Notify subscribers that the inner dictionary has changed.
|
|
30
|
+
return {
|
|
31
|
+
$code: userCulture,
|
|
32
|
+
$dir: extension.meta.direction ?? 'ltr',
|
|
33
|
+
...innerDictionary,
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
if (translations.length) {
|
|
37
|
+
registerTranslation(...translations);
|
|
38
|
+
// Set the document language
|
|
39
|
+
document.documentElement.lang = locale.baseName;
|
|
40
|
+
// Set the document direction to the direction of the primary language
|
|
41
|
+
document.documentElement.dir = translations[0].$dir ?? 'ltr';
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Load a language from the extension registry.
|
|
47
|
+
* @param locale The locale to load.
|
|
48
|
+
*/
|
|
49
|
+
loadLanguage(locale) {
|
|
50
|
+
this.#currentLanguage.next(locale);
|
|
51
|
+
}
|
|
52
|
+
#addOrUpdateDictionary(innerDictionary, dictionaryName, dictionary) {
|
|
53
|
+
for (const [key, value] of Object.entries(dictionary)) {
|
|
54
|
+
innerDictionary[`${dictionaryName}_${key}`] = value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export const umbTranslationRegistry = new UmbTranslationRegistry(umbExtensionsRegistry);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { UmbObserver } from './observer.js';
|
|
1
|
+
import { ObserverCallback, UmbObserver } from './observer.js';
|
|
2
2
|
import { Observable } from '../../external/rxjs/index.js';
|
|
3
3
|
import { UmbController, UmbControllerAlias, UmbControllerHost } from '../controller-api/index.js';
|
|
4
4
|
export declare class UmbObserverController<T = unknown> extends UmbObserver<T> implements UmbController {
|
|
5
5
|
_alias?: UmbControllerAlias;
|
|
6
6
|
get controllerAlias(): UmbControllerAlias;
|
|
7
|
-
constructor(host: UmbControllerHost, source: Observable<T>, callback:
|
|
7
|
+
constructor(host: UmbControllerHost, source: Observable<T>, callback: ObserverCallback<T>, alias?: UmbControllerAlias);
|
|
8
8
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Observable } from '../../external/rxjs/index.js';
|
|
2
|
+
export type ObserverCallbackStack<T> = {
|
|
3
|
+
next: (_value: T) => void;
|
|
4
|
+
error?: (_value: unknown) => void;
|
|
5
|
+
complete?: () => void;
|
|
6
|
+
};
|
|
7
|
+
export type ObserverCallback<T> = ((_value: T) => void) | ObserverCallbackStack<T>;
|
|
2
8
|
export declare class UmbObserver<T> {
|
|
3
9
|
#private;
|
|
4
|
-
constructor(source: Observable<T>, callback:
|
|
10
|
+
constructor(source: Observable<T>, callback: ObserverCallback<T>);
|
|
5
11
|
asPromise(): Promise<T>;
|
|
6
12
|
hostConnected(): void;
|
|
7
13
|
hostDisconnected(): void;
|
|
@@ -20,6 +20,7 @@ import type { ManifestSectionView } from './section-view.model.js';
|
|
|
20
20
|
import type { ManifestStore, ManifestTreeStore, ManifestItemStore } from './store.model.js';
|
|
21
21
|
import type { ManifestTheme } from './theme.model.js';
|
|
22
22
|
import type { ManifestTinyMcePlugin } from './tinymce-plugin.model.js';
|
|
23
|
+
import type { ManifestTranslations } from './translations.model.js';
|
|
23
24
|
import type { ManifestTree } from './tree.model.js';
|
|
24
25
|
import type { ManifestTreeItem } from './tree-item.model.js';
|
|
25
26
|
import type { ManifestUserProfileApp } from './user-profile-app.model.js';
|
|
@@ -50,6 +51,7 @@ export * from './section.model.js';
|
|
|
50
51
|
export * from './store.model.js';
|
|
51
52
|
export * from './theme.model.js';
|
|
52
53
|
export * from './tinymce-plugin.model.js';
|
|
54
|
+
export * from './translations.model.js';
|
|
53
55
|
export * from './tree-item.model.js';
|
|
54
56
|
export * from './tree.model.js';
|
|
55
57
|
export * from './user-profile-app.model.js';
|
|
@@ -57,4 +59,4 @@ export * from './workspace-action.model.js';
|
|
|
57
59
|
export * from './workspace-view-collection.model.js';
|
|
58
60
|
export * from './workspace-editor-view.model.js';
|
|
59
61
|
export * from './workspace.model.js';
|
|
60
|
-
export type ManifestTypes = ManifestBundle | ManifestCollectionView | ManifestDashboard | ManifestDashboardCollection | ManifestEntityAction | ManifestEntityBulkAction | ManifestEntryPoint | ManifestExternalLoginProvider | ManifestGlobalContext | ManifestHeaderApp | ManifestHeaderAppButtonKind | ManifestHealthCheck | ManifestItemStore | ManifestMenu | ManifestMenuItem | ManifestMenuItemTreeKind | ManifestModal | ManifestPackageView | ManifestPropertyAction | ManifestPropertyEditorSchema | ManifestPropertyEditorUi | ManifestRepository | ManifestSection | ManifestSectionSidebarApp | ManifestSectionSidebarAppMenuKind | ManifestSectionView | ManifestStore | ManifestTheme | ManifestTinyMcePlugin | ManifestTree | ManifestTreeItem | ManifestTreeStore | ManifestUserProfileApp | ManifestWorkspace | ManifestWorkspaceAction | ManifestWorkspaceEditorView | ManifestWorkspaceViewCollection | ManifestBase;
|
|
62
|
+
export type ManifestTypes = ManifestBundle | ManifestCollectionView | ManifestDashboard | ManifestDashboardCollection | ManifestEntityAction | ManifestEntityBulkAction | ManifestEntryPoint | ManifestExternalLoginProvider | ManifestGlobalContext | ManifestHeaderApp | ManifestHeaderAppButtonKind | ManifestHealthCheck | ManifestItemStore | ManifestMenu | ManifestMenuItem | ManifestMenuItemTreeKind | ManifestModal | ManifestPackageView | ManifestPropertyAction | ManifestPropertyEditorSchema | ManifestPropertyEditorUi | ManifestRepository | ManifestSection | ManifestSectionSidebarApp | ManifestSectionSidebarAppMenuKind | ManifestSectionView | ManifestStore | ManifestTheme | ManifestTinyMcePlugin | ManifestTranslations | ManifestTree | ManifestTreeItem | ManifestTreeStore | ManifestUserProfileApp | ManifestWorkspace | ManifestWorkspaceAction | ManifestWorkspaceEditorView | ManifestWorkspaceViewCollection | ManifestBase;
|
|
@@ -20,6 +20,7 @@ export * from './section.model.js';
|
|
|
20
20
|
export * from './store.model.js';
|
|
21
21
|
export * from './theme.model.js';
|
|
22
22
|
export * from './tinymce-plugin.model.js';
|
|
23
|
+
export * from './translations.model.js';
|
|
23
24
|
export * from './tree-item.model.js';
|
|
24
25
|
export * from './tree.model.js';
|
|
25
26
|
export * from './user-profile-app.model.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ManifestWithLoaderIncludingDefaultExport } from '../../../../libs/extension-api/index.js';
|
|
2
|
+
export type UmbTranslationEntry = string | ((...args: any[]) => string);
|
|
3
|
+
export type UmbTranslationsDictionary = Record<string, Record<string, UmbTranslationEntry>>;
|
|
4
|
+
export interface ManifestTranslations extends ManifestWithLoaderIncludingDefaultExport<UmbTranslationsDictionary> {
|
|
5
|
+
type: 'translations';
|
|
6
|
+
meta: MetaTranslations;
|
|
7
|
+
}
|
|
8
|
+
export interface MetaTranslations {
|
|
9
|
+
/**
|
|
10
|
+
* @summary The culture of the translations.
|
|
11
|
+
* @description
|
|
12
|
+
* The culture is a combination of a language and a country. The language is represented by an ISO 639-1 code and the country is represented by an ISO 3166-1 alpha-2 code.
|
|
13
|
+
* The language and country are separated by a dash.
|
|
14
|
+
* The value is used to describe the language of the translations according to the extension system
|
|
15
|
+
* and it will be set as the `lang` attribute on the `<html>` element.
|
|
16
|
+
* @see https://en.wikipedia.org/wiki/Language_localisation#Language_tags_and_codes
|
|
17
|
+
* @examples ["en-us", "en-gb", "da-dk"]
|
|
18
|
+
*/
|
|
19
|
+
culture: string;
|
|
20
|
+
/**
|
|
21
|
+
* @summary The direction of the translations (left-to-right or right-to-left).
|
|
22
|
+
* @description
|
|
23
|
+
* The value is used to describe the direction of the translations according to the extension system
|
|
24
|
+
* and it will be set as the `dir` attribute on the `<html>` element. It defaults to `ltr`.
|
|
25
|
+
* @see https://en.wikipedia.org/wiki/Right-to-left
|
|
26
|
+
* @examples ["ltr"]
|
|
27
|
+
* @default "ltr"
|
|
28
|
+
*/
|
|
29
|
+
direction?: 'ltr' | 'rtl';
|
|
30
|
+
/**
|
|
31
|
+
* The translations.
|
|
32
|
+
* @example
|
|
33
|
+
* {
|
|
34
|
+
* "general": {
|
|
35
|
+
* "cancel": "Cancel",
|
|
36
|
+
* "close": "Close"
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
translations?: UmbTranslationsDictionary;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UmbBackofficeNotificationContainerElement, UmbBackofficeModalContainerElement } from './components/index.js';
|
|
2
2
|
import { manifests as debugManifests } from './debug/manifests.js';
|
|
3
|
+
import { manifests as localizationManifests } from './localization/manifests.js';
|
|
3
4
|
import { manifests as propertyActionManifests } from './property-action/manifests.js';
|
|
4
5
|
import { manifests as propertyEditorManifests } from './property-editor/manifests.js';
|
|
5
6
|
import { manifests as tinyMcePluginManifests } from './property-editor/uis/tiny-mce/plugins/manifests.js';
|
|
@@ -10,6 +11,7 @@ import { UmbNotificationContext, UMB_NOTIFICATION_CONTEXT_TOKEN } from './notifi
|
|
|
10
11
|
import { UmbModalManagerContext, UMB_MODAL_MANAGER_CONTEXT_TOKEN } from './modal/index.js';
|
|
11
12
|
import { UmbContextProviderController } from '../../libs/context-api/index.js';
|
|
12
13
|
import { UmbClassExtensionsInitializer, } from './extension-registry/index.js';
|
|
14
|
+
export * from './localization/index.js';
|
|
13
15
|
export * from './action/index.js';
|
|
14
16
|
export * from './collection/index.js';
|
|
15
17
|
export * from './components/index.js';
|
|
@@ -34,6 +36,7 @@ export * from './variant/index.js';
|
|
|
34
36
|
export * from './workspace/index.js';
|
|
35
37
|
const manifests = [
|
|
36
38
|
...debugManifests,
|
|
39
|
+
...localizationManifests,
|
|
37
40
|
...propertyActionManifests,
|
|
38
41
|
...propertyEditorManifests,
|
|
39
42
|
...tinyMcePluginManifests,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './localize.element.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './localize.element.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { UmbLitElement } from '../../../shared/lit-element/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* This element allows you to localize a string with optional interpolation values.
|
|
4
|
+
* @element umb-localize
|
|
5
|
+
* @slot - The fallback value if the key is not found.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UmbLocalizeElement extends UmbLitElement {
|
|
8
|
+
/**
|
|
9
|
+
* The key to localize. The key is case sensitive.
|
|
10
|
+
* @attr
|
|
11
|
+
* @example key="general_ok"
|
|
12
|
+
*/
|
|
13
|
+
key: string;
|
|
14
|
+
/**
|
|
15
|
+
* The values to forward to the localization function (must be JSON compatible).
|
|
16
|
+
* @attr
|
|
17
|
+
* @example args="[1,2,3]"
|
|
18
|
+
* @type {any[] | undefined}
|
|
19
|
+
*/
|
|
20
|
+
args?: unknown[];
|
|
21
|
+
/**
|
|
22
|
+
* If true, the key will be rendered instead of the localized value if the key is not found.
|
|
23
|
+
* @attr
|
|
24
|
+
*/
|
|
25
|
+
debug: boolean;
|
|
26
|
+
protected get text(): string;
|
|
27
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
28
|
+
static styles: import("@lit/reactive-element/css-tag").CSSResult[];
|
|
29
|
+
}
|
|
30
|
+
declare global {
|
|
31
|
+
interface HTMLElementTagNameMap {
|
|
32
|
+
'umb-localize': UmbLocalizeElement;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, customElement, html, property, state } from '../../../external/lit/index.js';
|
|
8
|
+
import { UmbLitElement } from '../../../shared/lit-element/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* This element allows you to localize a string with optional interpolation values.
|
|
11
|
+
* @element umb-localize
|
|
12
|
+
* @slot - The fallback value if the key is not found.
|
|
13
|
+
*/
|
|
14
|
+
export let UmbLocalizeElement = class UmbLocalizeElement extends UmbLitElement {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
/**
|
|
18
|
+
* If true, the key will be rendered instead of the localized value if the key is not found.
|
|
19
|
+
* @attr
|
|
20
|
+
*/
|
|
21
|
+
this.debug = false;
|
|
22
|
+
}
|
|
23
|
+
get text() {
|
|
24
|
+
const localizedValue = this.localize.term(this.key, ...(this.args ?? []));
|
|
25
|
+
// If the value is the same as the key, it means the key was not found.
|
|
26
|
+
if (localizedValue === this.key) {
|
|
27
|
+
this.getHostElement().setAttribute('data-localize-missing', this.key);
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
this.getHostElement().removeAttribute('data-localize-missing');
|
|
31
|
+
return localizedValue;
|
|
32
|
+
}
|
|
33
|
+
render() {
|
|
34
|
+
return this.text
|
|
35
|
+
? html `${this.text}`
|
|
36
|
+
: this.debug
|
|
37
|
+
? html `<span style="color:red">${this.key}</span>`
|
|
38
|
+
: html `<slot></slot>`;
|
|
39
|
+
}
|
|
40
|
+
static { this.styles = [
|
|
41
|
+
css `
|
|
42
|
+
:host {
|
|
43
|
+
display: contents;
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
]; }
|
|
47
|
+
};
|
|
48
|
+
__decorate([
|
|
49
|
+
property()
|
|
50
|
+
], UmbLocalizeElement.prototype, "key", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
property({
|
|
53
|
+
type: Array,
|
|
54
|
+
})
|
|
55
|
+
], UmbLocalizeElement.prototype, "args", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
property()
|
|
58
|
+
], UmbLocalizeElement.prototype, "debug", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
state()
|
|
61
|
+
], UmbLocalizeElement.prototype, "text", null);
|
|
62
|
+
UmbLocalizeElement = __decorate([
|
|
63
|
+
customElement('umb-localize')
|
|
64
|
+
], UmbLocalizeElement);
|