@commercetools-frontend/l10n 22.30.3 → 22.32.0
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.
|
@@ -50,7 +50,7 @@ var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
|
50
50
|
var omit__default = /*#__PURE__*/_interopDefault(omit);
|
|
51
51
|
|
|
52
52
|
// NOTE: This string will be replaced on build time with the package version.
|
|
53
|
-
var version = "22.
|
|
53
|
+
var version = "22.32.0";
|
|
54
54
|
|
|
55
55
|
// https://babeljs.io/blog/2017/09/11/zero-config-with-babel-macros
|
|
56
56
|
const supportedLocales = ["en", "de", "es", "fr-FR", "pt-BR", "zh-CN"];
|
|
@@ -94,17 +94,14 @@ const getDisplayName = Component => {
|
|
|
94
94
|
return Component.displayName || Component.name || 'Component';
|
|
95
95
|
};
|
|
96
96
|
const getPrimaryLocale = locale => locale.split('-')[0];
|
|
97
|
-
const formatLocalizedFallbackHint = (value, locale) => {
|
|
98
|
-
var _context;
|
|
99
|
-
return _concatInstanceProperty__default["default"](_context = "".concat(value, " (")).call(_context, locale.toUpperCase(), ")");
|
|
100
|
-
};
|
|
97
|
+
const formatLocalizedFallbackHint = (value, locale) => `${value} (${locale.toUpperCase()})`;
|
|
101
98
|
const findFallbackLocale = (localizedString, fallbackOrder) => {
|
|
102
|
-
var
|
|
103
|
-
return _findInstanceProperty__default["default"](
|
|
99
|
+
var _context;
|
|
100
|
+
return _findInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](fallbackOrder).call(fallbackOrder, _Object$keys__default["default"](localizedString))).call(_context, lang => Boolean(localizedString[lang]));
|
|
104
101
|
};
|
|
105
102
|
|
|
106
103
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
107
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
104
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
108
105
|
const initialState = {
|
|
109
106
|
isLoading: true,
|
|
110
107
|
// Keep it as an empty object, for backwards compatibility
|
|
@@ -181,7 +178,6 @@ function createL10NInjector(_ref) {
|
|
|
181
178
|
return function createHOC(mapPropsToLocale) {
|
|
182
179
|
const useL10n = createL10NHook(loadLocale);
|
|
183
180
|
return WrappedComponent => {
|
|
184
|
-
var _context;
|
|
185
181
|
const L10NComponent = props => {
|
|
186
182
|
const state = useL10n(mapPropsToLocale(props));
|
|
187
183
|
return jsxRuntime.jsx(WrappedComponent, _objectSpread$2(_objectSpread$2({}, props), {}, {
|
|
@@ -189,7 +185,7 @@ function createL10NInjector(_ref) {
|
|
|
189
185
|
[propKey]: state.data
|
|
190
186
|
}));
|
|
191
187
|
};
|
|
192
|
-
L10NComponent.displayName =
|
|
188
|
+
L10NComponent.displayName = `${displayName}(${getDisplayName(WrappedComponent)})`;
|
|
193
189
|
return L10NComponent;
|
|
194
190
|
};
|
|
195
191
|
};
|
|
@@ -50,7 +50,7 @@ var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
|
50
50
|
var omit__default = /*#__PURE__*/_interopDefault(omit);
|
|
51
51
|
|
|
52
52
|
// NOTE: This string will be replaced on build time with the package version.
|
|
53
|
-
var version = "22.
|
|
53
|
+
var version = "22.32.0";
|
|
54
54
|
|
|
55
55
|
// https://babeljs.io/blog/2017/09/11/zero-config-with-babel-macros
|
|
56
56
|
const supportedLocales = ["en", "de", "es", "fr-FR", "pt-BR", "zh-CN"];
|
|
@@ -94,17 +94,14 @@ const getDisplayName = Component => {
|
|
|
94
94
|
return Component.displayName || Component.name || 'Component';
|
|
95
95
|
};
|
|
96
96
|
const getPrimaryLocale = locale => locale.split('-')[0];
|
|
97
|
-
const formatLocalizedFallbackHint = (value, locale) => {
|
|
98
|
-
var _context;
|
|
99
|
-
return _concatInstanceProperty__default["default"](_context = "".concat(value, " (")).call(_context, locale.toUpperCase(), ")");
|
|
100
|
-
};
|
|
97
|
+
const formatLocalizedFallbackHint = (value, locale) => `${value} (${locale.toUpperCase()})`;
|
|
101
98
|
const findFallbackLocale = (localizedString, fallbackOrder) => {
|
|
102
|
-
var
|
|
103
|
-
return _findInstanceProperty__default["default"](
|
|
99
|
+
var _context;
|
|
100
|
+
return _findInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](fallbackOrder).call(fallbackOrder, _Object$keys__default["default"](localizedString))).call(_context, lang => Boolean(localizedString[lang]));
|
|
104
101
|
};
|
|
105
102
|
|
|
106
103
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
107
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
104
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
108
105
|
const initialState = {
|
|
109
106
|
isLoading: true,
|
|
110
107
|
// Keep it as an empty object, for backwards compatibility
|
|
@@ -181,7 +178,6 @@ function createL10NInjector(_ref) {
|
|
|
181
178
|
return function createHOC(mapPropsToLocale) {
|
|
182
179
|
const useL10n = createL10NHook(loadLocale);
|
|
183
180
|
return WrappedComponent => {
|
|
184
|
-
var _context;
|
|
185
181
|
const L10NComponent = props => {
|
|
186
182
|
const state = useL10n(mapPropsToLocale(props));
|
|
187
183
|
return jsxRuntime.jsx(WrappedComponent, _objectSpread$2(_objectSpread$2({}, props), {}, {
|
|
@@ -189,7 +185,7 @@ function createL10NInjector(_ref) {
|
|
|
189
185
|
[propKey]: state.data
|
|
190
186
|
}));
|
|
191
187
|
};
|
|
192
|
-
L10NComponent.displayName =
|
|
188
|
+
L10NComponent.displayName = `${displayName}(${getDisplayName(WrappedComponent)})`;
|
|
193
189
|
return L10NComponent;
|
|
194
190
|
};
|
|
195
191
|
};
|
|
@@ -24,7 +24,7 @@ import moment from 'moment-timezone';
|
|
|
24
24
|
import omit from 'lodash/omit';
|
|
25
25
|
|
|
26
26
|
// NOTE: This string will be replaced on build time with the package version.
|
|
27
|
-
var version = "22.
|
|
27
|
+
var version = "22.32.0";
|
|
28
28
|
|
|
29
29
|
// https://babeljs.io/blog/2017/09/11/zero-config-with-babel-macros
|
|
30
30
|
const supportedLocales = ["en", "de", "es", "fr-FR", "pt-BR", "zh-CN"];
|
|
@@ -68,17 +68,14 @@ const getDisplayName = Component => {
|
|
|
68
68
|
return Component.displayName || Component.name || 'Component';
|
|
69
69
|
};
|
|
70
70
|
const getPrimaryLocale = locale => locale.split('-')[0];
|
|
71
|
-
const formatLocalizedFallbackHint = (value, locale) => {
|
|
72
|
-
var _context;
|
|
73
|
-
return _concatInstanceProperty(_context = "".concat(value, " (")).call(_context, locale.toUpperCase(), ")");
|
|
74
|
-
};
|
|
71
|
+
const formatLocalizedFallbackHint = (value, locale) => `${value} (${locale.toUpperCase()})`;
|
|
75
72
|
const findFallbackLocale = (localizedString, fallbackOrder) => {
|
|
76
|
-
var
|
|
77
|
-
return _findInstanceProperty(
|
|
73
|
+
var _context;
|
|
74
|
+
return _findInstanceProperty(_context = _concatInstanceProperty(fallbackOrder).call(fallbackOrder, _Object$keys(localizedString))).call(_context, lang => Boolean(localizedString[lang]));
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
function ownKeys$2(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
81
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
78
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
82
79
|
const initialState = {
|
|
83
80
|
isLoading: true,
|
|
84
81
|
// Keep it as an empty object, for backwards compatibility
|
|
@@ -155,7 +152,6 @@ function createL10NInjector(_ref) {
|
|
|
155
152
|
return function createHOC(mapPropsToLocale) {
|
|
156
153
|
const useL10n = createL10NHook(loadLocale);
|
|
157
154
|
return WrappedComponent => {
|
|
158
|
-
var _context;
|
|
159
155
|
const L10NComponent = props => {
|
|
160
156
|
const state = useL10n(mapPropsToLocale(props));
|
|
161
157
|
return jsx(WrappedComponent, _objectSpread$2(_objectSpread$2({}, props), {}, {
|
|
@@ -163,7 +159,7 @@ function createL10NInjector(_ref) {
|
|
|
163
159
|
[propKey]: state.data
|
|
164
160
|
}));
|
|
165
161
|
};
|
|
166
|
-
L10NComponent.displayName =
|
|
162
|
+
L10NComponent.displayName = `${displayName}(${getDisplayName(WrappedComponent)})`;
|
|
167
163
|
return L10NComponent;
|
|
168
164
|
};
|
|
169
165
|
};
|
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
import { LocalizedString, LocalizedField, FieldNameTranformationMapping, FormatLocalizedStringOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms a list of `LocalizedField` into a `LocalizedString` object
|
|
4
|
+
* [{ locale: 'sv', value: 'Hej' }] -> { sv: 'Hej' }
|
|
5
|
+
*/
|
|
2
6
|
export declare const transformLocalizedFieldToLocalizedString: (localizedFields?: LocalizedField[]) => LocalizedString | null;
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a `LocalizedString` object into a list of `LocalizedField`
|
|
9
|
+
*
|
|
10
|
+
* { sv: 'Hej' } -> [{ locale: 'sv', value: 'Hej' }]
|
|
11
|
+
*/
|
|
3
12
|
export declare const transformLocalizedStringToLocalizedField: (localizedString?: LocalizedString) => LocalizedField[];
|
|
13
|
+
/**
|
|
14
|
+
* Given a list of localized field names to map, replace the fields in the
|
|
15
|
+
* format of `LocalizedField` to a `LocalizedString` object.
|
|
16
|
+
* The existing "localized" fields (the list version) will be removed.
|
|
17
|
+
*
|
|
18
|
+
* @param objectWithLocalizedFields
|
|
19
|
+
* the object with `LocalizedField` fields
|
|
20
|
+
* that need to be transformed into `LocalizedString`s
|
|
21
|
+
* @param fieldNames
|
|
22
|
+
* An array of objects with following shape:
|
|
23
|
+
* * `from`: the field to transform and to remove after
|
|
24
|
+
* * `to`: the target field to write the transformed shape
|
|
25
|
+
*/
|
|
4
26
|
export declare const applyTransformedLocalizedFields: <Input extends Record<string, unknown>, Output extends Record<string, unknown>>(objectWithLocalizedFields: Input, fieldNames: FieldNameTranformationMapping[]) => Output;
|
|
27
|
+
/**
|
|
28
|
+
* Given a list of localized string names to map, replace the fields in the
|
|
29
|
+
* format of `LocalizedString` to a `LocalizedField` object.
|
|
30
|
+
* The existing "localized" strings (the list version) will be removed.
|
|
31
|
+
*
|
|
32
|
+
* @param objectWithLocalizedStrings
|
|
33
|
+
* the object with `LocalizedString` fields
|
|
34
|
+
* that need to be transformed into `LocalizedField`s
|
|
35
|
+
* @param fieldNames
|
|
36
|
+
* An array of objects with following shape:
|
|
37
|
+
* * `from`: the field to transform and to remove after
|
|
38
|
+
* * `to`: the target field to write the transformed shape
|
|
39
|
+
*/
|
|
5
40
|
export declare const applyTransformedLocalizedStrings: <Input extends Record<string, unknown>, Output extends Record<string, unknown>>(objectWithLocalizedStrings: Input, fieldNames: FieldNameTranformationMapping[]) => Output;
|
|
41
|
+
/**
|
|
42
|
+
* Translates a localized string on an entity.
|
|
43
|
+
*
|
|
44
|
+
* The `localize` function receives a complete entity that can have several
|
|
45
|
+
* localized fields.
|
|
46
|
+
*
|
|
47
|
+
* Arguments
|
|
48
|
+
* - `obj`: that entity
|
|
49
|
+
* - `key`: the field within `obj` that might contain a localized strings
|
|
50
|
+
* - `locale`: the language key that should be the first choice to show
|
|
51
|
+
* - `fallbackOrder`: an array of language keys which will be tried in the
|
|
52
|
+
* provided order for any set value
|
|
53
|
+
* - `fallback`: the final fallback that should be displayed as a last resort.
|
|
54
|
+
* This fallback will also be shown in case the field does not exist on the
|
|
55
|
+
* provided object.
|
|
56
|
+
*
|
|
57
|
+
* Before `fallback` kicks in, the following is tried to display a meaningful value:
|
|
58
|
+
* - if `locale` is `<language>-<extlang>`, eg. `de-AT`, try if `de` is set
|
|
59
|
+
* - if not, iterate through all languages of project-settings
|
|
60
|
+
* (passed as `fallbackOrder`) and pick the first one with a value
|
|
61
|
+
* - if nothing is found, go through all the languages in provided localized
|
|
62
|
+
* string an pick the first with a value
|
|
63
|
+
* - if still no value is found display `fallback`
|
|
64
|
+
*
|
|
65
|
+
* NOTE: It is known that this might lead to strings displayed in different
|
|
66
|
+
* languages within the same page. This is an accepted downside.
|
|
67
|
+
*
|
|
68
|
+
* NOTE: A missing field is treated like a localied string with no translations:
|
|
69
|
+
* let a = formatLocalizedString({ name: { en: '', de: '' } }, { locale: 'en' })
|
|
70
|
+
* let b = formatLocalizedString({}, { locale: 'en' })
|
|
71
|
+
* let c = formatLocalizedString(undefined, { locale: 'en' })
|
|
72
|
+
* a === b && a === c -> true
|
|
73
|
+
*/
|
|
6
74
|
export declare const formatLocalizedString: <Input extends Record<string, unknown>>(entity: Input | null, { key, locale, fallbackOrder, fallback, }: FormatLocalizedStringOptions<Input>) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/l10n",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.32.0",
|
|
4
4
|
"description": "React bindings to load l10n data",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.22.15",
|
|
33
33
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
34
|
-
"@commercetools-frontend/sentry": "22.
|
|
34
|
+
"@commercetools-frontend/sentry": "22.32.0",
|
|
35
35
|
"@emotion/react": "^11.11.4",
|
|
36
36
|
"@types/lodash": "^4.14.198",
|
|
37
37
|
"@types/prop-types": "^15.7.5",
|