@ohos-ports/enact-i18n 5.6.0-beta.1
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/$L/$L.d.ts +15 -0
- package/$L/$L.js +52 -0
- package/$L/package.json +3 -0
- package/$L/tests/$L-specs.js +41 -0
- package/CHANGELOG.md +993 -0
- package/I18nDecorator/I18n.js +314 -0
- package/I18nDecorator/I18nDecorator.d.ts +90 -0
- package/I18nDecorator/I18nDecorator.js +272 -0
- package/I18nDecorator/getI18nClasses.js +120 -0
- package/I18nDecorator/package.json +3 -0
- package/I18nDecorator/tests/I18nDecorator-specs.js +172 -0
- package/I18nDecorator/tests/useI18n-specs.js +296 -0
- package/I18nDecorator/tests/windowFocus-specs.js +76 -0
- package/I18nDecorator/useI18n.js +75 -0
- package/I18nDecorator/useI18nContext.js +34 -0
- package/I18nDecorator/windowFocus.js +38 -0
- package/README.md +65 -0
- package/Text/Text.d.ts +58 -0
- package/Text/Text.js +258 -0
- package/Text/package.json +3 -0
- package/locale/locale.js +124 -0
- package/locale/package.json +3 -0
- package/locale/tests/locale-specs.js +59 -0
- package/package.json +64 -0
- package/src/Loader.js +461 -0
- package/src/case.js +52 -0
- package/src/dates.js +18 -0
- package/src/glue.js +40 -0
- package/src/index.d.ts +162 -0
- package/src/index.js +14 -0
- package/src/packedbuffer.js +158 -0
- package/src/resBundle.js +90 -0
- package/src/wrapIlibCallback.js +39 -0
- package/src/zoneinfo.js +520 -0
- package/util/package.json +3 -0
- package/util/tests/util-specs.js +50 -0
- package/util/util.d.ts +26 -0
- package/util/util.js +106 -0
package/$L/$L.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Type definitions for i18n/$L
|
|
2
|
+
|
|
3
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
4
|
+
type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Maps a string or key/value object to a translated string for the current locale.
|
|
8
|
+
*/
|
|
9
|
+
export function toIString(str: string | object): IString;
|
|
10
|
+
/**
|
|
11
|
+
* Maps a string or key/value object to a translated string for the current locale.
|
|
12
|
+
*/
|
|
13
|
+
export function $L(str: string | object): string;
|
|
14
|
+
|
|
15
|
+
export default $L;
|
package/$L/$L.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.$L = $L;
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
exports.toIString = toIString;
|
|
9
|
+
require("../src/glue");
|
|
10
|
+
var _resBundle = require("../src/resBundle");
|
|
11
|
+
/**
|
|
12
|
+
* Provides functions to map to translated strings.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```
|
|
16
|
+
* import $L, {toIString} from '@enact/i18n/$L';
|
|
17
|
+
* $L('Close'); // => "Close" in the current locale
|
|
18
|
+
* toIString('Close'); // => an ilib IString representing "Close" in the current locale
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module i18n/$L
|
|
22
|
+
* @exports $L
|
|
23
|
+
* @exports $toIString
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Maps a string or key/value object to a translated string for the current locale.
|
|
28
|
+
*
|
|
29
|
+
* @function
|
|
30
|
+
* @memberof i18n/$L
|
|
31
|
+
* @param {String|Object} str Source string
|
|
32
|
+
*
|
|
33
|
+
* @returns {ilib.IString} The translated string
|
|
34
|
+
*/
|
|
35
|
+
function toIString(str) {
|
|
36
|
+
var rb = (0, _resBundle.getResBundle)();
|
|
37
|
+
return (0, _resBundle.getIStringFromBundle)(str, rb);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Maps a string or key/value object to a translated string for the current locale.
|
|
42
|
+
*
|
|
43
|
+
* @function
|
|
44
|
+
* @memberof i18n/$L
|
|
45
|
+
* @param {String|Object} str Source string
|
|
46
|
+
*
|
|
47
|
+
* @returns {String} The translated string
|
|
48
|
+
*/
|
|
49
|
+
function $L(str) {
|
|
50
|
+
return String(toIString(str));
|
|
51
|
+
}
|
|
52
|
+
var _default = exports["default"] = $L;
|
package/$L/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
5
|
+
var _I18nDecorator = require("../../I18nDecorator");
|
|
6
|
+
var _resBundle = require("../../src/resBundle");
|
|
7
|
+
var _$L = require("../$L");
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
describe('$L', function () {
|
|
10
|
+
test('should get the key string when there is no translated value', function () {
|
|
11
|
+
var expected = 'hello';
|
|
12
|
+
var Component = function Component(props) {
|
|
13
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
14
|
+
className: props.className,
|
|
15
|
+
children: (0, _$L.$L)(expected)
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var Wrapped = (0, _I18nDecorator.I18nDecorator)({
|
|
19
|
+
sync: true
|
|
20
|
+
}, Component);
|
|
21
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, {}));
|
|
22
|
+
var actual = _react.screen.getByText(expected);
|
|
23
|
+
expect(actual).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
test('should clear ResBundle with calling `clearResBundle`', function () {
|
|
26
|
+
var expected = null;
|
|
27
|
+
var Component = function Component(props) {
|
|
28
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
29
|
+
className: props.className,
|
|
30
|
+
children: (0, _$L.$L)('hello')
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
var Wrapped = (0, _I18nDecorator.I18nDecorator)({
|
|
34
|
+
sync: true
|
|
35
|
+
}, Component);
|
|
36
|
+
(0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, {}));
|
|
37
|
+
(0, _resBundle.clearResBundle)();
|
|
38
|
+
var actual = (0, _resBundle.getResBundle)();
|
|
39
|
+
expect(actual).toEqual(expected);
|
|
40
|
+
});
|
|
41
|
+
});
|