@brightspace-ui/core 2.18.5 → 2.18.6
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/mixins/demo/localize-test.js +11 -13
- package/mixins/localize-mixin.js +5 -4
- package/mixins/localize-mixin.md +11 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html, LitElement } from 'lit';
|
|
2
|
-
import {
|
|
2
|
+
import { LocalizeDynamicMixin } from '../../mixins/localize-dynamic-mixin.js';
|
|
3
3
|
|
|
4
|
-
class LocalizeTest extends
|
|
4
|
+
class LocalizeTest extends LocalizeDynamicMixin(LitElement) {
|
|
5
5
|
|
|
6
6
|
static get properties() {
|
|
7
7
|
return {
|
|
@@ -11,7 +11,7 @@ class LocalizeTest extends LocalizeMixin(LitElement) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
static
|
|
14
|
+
static get localizeConfig() {
|
|
15
15
|
const langResources = {
|
|
16
16
|
'ar': { 'hello': 'مرحبا {name}' },
|
|
17
17
|
'de': { 'hello': 'Hallo {name}' },
|
|
@@ -29,17 +29,15 @@ class LocalizeTest extends LocalizeMixin(LitElement) {
|
|
|
29
29
|
'zh-cn': { 'hello': '你好 {name}' },
|
|
30
30
|
'zh-tw': { 'hello': '你好 {name}' }
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
32
|
+
return {
|
|
33
|
+
importFunc: async lang => {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
resolve(langResources[lang]);
|
|
37
|
+
}, 50);
|
|
38
|
+
});
|
|
39
39
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return null;
|
|
40
|
+
};
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
render() {
|
package/mixins/localize-mixin.js
CHANGED
|
@@ -163,12 +163,13 @@ export const LocalizeMixin = dedupeMixin(superclass => class extends superclass
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
static _getAllLocalizeResources(possibleLanguages, config = this.localizeConfig) {
|
|
166
|
-
let resourcesLoadedPromises;
|
|
166
|
+
let resourcesLoadedPromises = [];
|
|
167
167
|
const superCtor = Object.getPrototypeOf(this);
|
|
168
|
+
// get imported terms for each config, head up the chain to get them all
|
|
168
169
|
if ('_getAllLocalizeResources' in superCtor) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
resourcesLoadedPromises =
|
|
170
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
171
|
+
const superConfig = superCtor.hasOwnProperty('localizeConfig') && superCtor.localizeConfig.importFunc ? superCtor.localizeConfig : config;
|
|
172
|
+
resourcesLoadedPromises = superCtor._getAllLocalizeResources(possibleLanguages, superConfig);
|
|
172
173
|
}
|
|
173
174
|
// eslint-disable-next-line no-prototype-builtins
|
|
174
175
|
if (this.hasOwnProperty('getLocalizeResources') || this.hasOwnProperty('resources')) {
|
package/mixins/localize-mixin.md
CHANGED
|
@@ -103,6 +103,17 @@ static get localizeConfig() {
|
|
|
103
103
|
}
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
**Note:** If using `LocalizeCoreElement` or a mixin that utilizes `LocalizeCoreElement` as well as `LocalizeDynamicMixin` or a mixin that uses `LocalizeDynamicMixin`, `LocalizeDynamicMixin` **must** appear before `LocalizeCoreElement` in the chain. For example:
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
import { LocalizeCoreElement } from '@brightspace-ui/core/helpers/localize-core-element.js';
|
|
110
|
+
import { LocalizeDynamicMixin } from '@brightspace-ui/core/mixins/localize-dynamic-mixin.js';
|
|
111
|
+
|
|
112
|
+
class MyComponent extends LocalizeDynamicMixin(LocalizeCoreElement(LitElement)) {
|
|
113
|
+
...
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
106
117
|
## `localize()`
|
|
107
118
|
|
|
108
119
|
Once your localization resources are available, the `localize()` method is used to localize a piece of text in your `render()` method.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "2.18.
|
|
3
|
+
"version": "2.18.6",
|
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|