orc-shared 1.2.0-dev.7 → 1.3.0-dev.2
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/components/AppFrame/About.js +5 -1
- package/dist/components/AppFrame/AppFrame.js +14 -4
- package/dist/components/AppFrame/MenuItem.js +1 -4
- package/dist/components/Culture.js +106 -0
- package/dist/components/I18n.js +5 -2
- package/dist/components/MaterialUI/Inputs/DatePicker.js +10 -37
- package/dist/components/MaterialUI/Inputs/InputBase.js +42 -4
- package/dist/components/MaterialUI/Inputs/InputBaseProps.js +4 -1
- package/dist/components/MaterialUI/Inputs/TimePicker.js +5 -2
- package/dist/components/MaterialUI/ScopeSelector/ScopeSelector.js +8 -2
- package/dist/components/Provision.js +3 -1
- package/dist/components/Routing/FullPage.js +6 -3
- package/dist/content/icons/archives.svg +3 -0
- package/dist/content/icons/lock.svg +3 -0
- package/dist/content/icons/unlock.svg +3 -0
- package/dist/content/iconsSheet.svg +9 -3
- package/dist/selectors/metadata.js +13 -3
- package/dist/selectors/scope.js +2 -1
- package/dist/utils/localizationHelper.js +11 -1
- package/dist/utils/setTranslation.js +27 -1
- package/dist/utils/setTranslationWithFallback.js +30 -1
- package/package.json +1 -1
- package/src/components/AppFrame/About.js +8 -1
- package/src/components/AppFrame/AppFrame.js +13 -2
- package/src/components/AppFrame/AppFrame.test.js +53 -0
- package/src/components/AppFrame/MenuItem.js +1 -12
- package/src/components/Culture.js +25 -0
- package/src/components/Culture.test.js +86 -0
- package/src/components/I18n.js +4 -2
- package/src/components/I18n.test.js +32 -3
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.test.js +7 -1
- package/src/components/MaterialUI/Inputs/DatePicker.js +5 -27
- package/src/components/MaterialUI/Inputs/DatePicker.test.js +6 -34
- package/src/components/MaterialUI/Inputs/InputBase.js +20 -2
- package/src/components/MaterialUI/Inputs/InputBase.test.js +68 -0
- package/src/components/MaterialUI/Inputs/InputBaseProps.js +2 -0
- package/src/components/MaterialUI/Inputs/InputBaseProps.test.js +2 -0
- package/src/components/MaterialUI/Inputs/TimePicker.js +6 -2
- package/src/components/MaterialUI/ScopeSelector/ScopeSelector.js +5 -1
- package/src/components/Provision.js +2 -0
- package/src/components/Routing/FullPage.js +12 -4
- package/src/components/Routing/FullPage.test.js +24 -0
- package/src/components/Scope/Scope.test.js +4 -0
- package/src/content/icons/archives.svg +3 -0
- package/src/content/icons/lock.svg +3 -0
- package/src/content/icons/unlock.svg +3 -0
- package/src/content/iconsSheet.svg +9 -3
- package/src/selectors/metadata.js +18 -7
- package/src/selectors/metadata.test.js +221 -283
- package/src/selectors/scope.js +1 -1
- package/src/translations/en-US.json +1 -1
- package/src/translations/fr-CA.json +1 -1
- package/src/utils/localizationHelper.js +12 -0
- package/src/utils/localizationHelper.test.js +64 -0
- package/src/utils/setTranslation.js +16 -1
- package/src/utils/setTranslation.test.js +24 -0
- package/src/utils/setTranslationWithFallback.js +18 -1
- package/src/utils/setTranslationWithFallback.test.js +108 -0
|
@@ -3,8 +3,23 @@ import { flatten } from "./flatten";
|
|
|
3
3
|
/* Replaces a locale string structure with the string for the given locale. */
|
|
4
4
|
const setTranslation = (locale, obj, ...field) => {
|
|
5
5
|
if (!obj || !obj.getIn(flatten([field]))) return obj;
|
|
6
|
+
let localeValue = obj.getIn(flatten([field, locale]));
|
|
7
|
+
if (!localeValue && locale.includes("-")) {
|
|
8
|
+
let fieldValue = obj.getIn(flatten([field]));
|
|
9
|
+
let fieldKeys = fieldValue.keys();
|
|
10
|
+
let language = locale.substring(0, locale.indexOf("-"));
|
|
11
|
+
|
|
12
|
+
for (let key of fieldKeys) {
|
|
13
|
+
if (key !== locale && key.startsWith(language)) {
|
|
14
|
+
localeValue = obj.getIn(flatten([field, key]));
|
|
15
|
+
if (localeValue) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
const value =
|
|
7
|
-
|
|
22
|
+
localeValue ||
|
|
8
23
|
obj
|
|
9
24
|
.getIn(flatten([field]))
|
|
10
25
|
.filter(i => i)
|
|
@@ -96,4 +96,28 @@ describe("setTranslation", () => {
|
|
|
96
96
|
hat: { name: "it-name" },
|
|
97
97
|
}),
|
|
98
98
|
));
|
|
99
|
+
|
|
100
|
+
it("returns first not empty match by language if language-culture not found", () =>
|
|
101
|
+
expect(
|
|
102
|
+
setTranslation,
|
|
103
|
+
"when called with",
|
|
104
|
+
[
|
|
105
|
+
"en-US",
|
|
106
|
+
Immutable.fromJS({
|
|
107
|
+
hat: {
|
|
108
|
+
name: {
|
|
109
|
+
"en-CA": "",
|
|
110
|
+
"fr-CA": "fr CA name",
|
|
111
|
+
"en-GB": "en GB name",
|
|
112
|
+
"it-IT": "it-name",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
["hat", "name"],
|
|
117
|
+
],
|
|
118
|
+
"to equal",
|
|
119
|
+
Immutable.fromJS({
|
|
120
|
+
hat: { name: "en GB name" },
|
|
121
|
+
}),
|
|
122
|
+
));
|
|
99
123
|
});
|
|
@@ -2,7 +2,24 @@ import { flatten } from "./flatten";
|
|
|
2
2
|
|
|
3
3
|
export const setTranslationWithFallbackValue = (locale, obj, fallbackValue, ...field) => {
|
|
4
4
|
if (!obj) return obj;
|
|
5
|
-
|
|
5
|
+
let localeValue = obj.getIn(flatten([field, locale]));
|
|
6
|
+
if (!localeValue && locale.includes("-")) {
|
|
7
|
+
let fieldValue = obj.getIn(flatten([field]));
|
|
8
|
+
if (fieldValue) {
|
|
9
|
+
let fieldKeys = fieldValue.keys();
|
|
10
|
+
let language = locale.substring(0, locale.indexOf("-"));
|
|
11
|
+
|
|
12
|
+
for (let key of fieldKeys) {
|
|
13
|
+
if (key !== locale && key.startsWith(language)) {
|
|
14
|
+
localeValue = obj.getIn(flatten([field, key]));
|
|
15
|
+
if (localeValue) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const value = localeValue || fallbackValue || "";
|
|
6
23
|
return obj.setIn(flatten([field]), value);
|
|
7
24
|
};
|
|
8
25
|
|
|
@@ -147,4 +147,112 @@ describe("setTranslationWithFallbackValue", () => {
|
|
|
147
147
|
"to equal",
|
|
148
148
|
null,
|
|
149
149
|
));
|
|
150
|
+
|
|
151
|
+
it("returns value matched by language-culture when exist", () =>
|
|
152
|
+
expect(
|
|
153
|
+
setTranslationWithFallbackValue,
|
|
154
|
+
"when called with",
|
|
155
|
+
[
|
|
156
|
+
"en-US",
|
|
157
|
+
Immutable.fromJS({
|
|
158
|
+
hat: { name: { "en-US": "en-US Name", "en-GB": "en-GB Name" } },
|
|
159
|
+
}),
|
|
160
|
+
"fallbakValue",
|
|
161
|
+
["hat", "name"],
|
|
162
|
+
],
|
|
163
|
+
"to equal",
|
|
164
|
+
Immutable.fromJS({
|
|
165
|
+
hat: { name: "en-US Name" },
|
|
166
|
+
}),
|
|
167
|
+
));
|
|
168
|
+
|
|
169
|
+
it("returns value matched by language when match by language-culture does not exist", () =>
|
|
170
|
+
expect(
|
|
171
|
+
setTranslationWithFallbackValue,
|
|
172
|
+
"when called with",
|
|
173
|
+
[
|
|
174
|
+
"en-US",
|
|
175
|
+
Immutable.fromJS({
|
|
176
|
+
hat: { name: { "en-GB": "en-GB Name" } },
|
|
177
|
+
}),
|
|
178
|
+
"fallbakValue",
|
|
179
|
+
["hat", "name"],
|
|
180
|
+
],
|
|
181
|
+
"to equal",
|
|
182
|
+
Immutable.fromJS({
|
|
183
|
+
hat: { name: "en-GB Name" },
|
|
184
|
+
}),
|
|
185
|
+
));
|
|
186
|
+
|
|
187
|
+
it("returns first not empty value matched by language when match by language-culture does not exist", () =>
|
|
188
|
+
expect(
|
|
189
|
+
setTranslationWithFallbackValue,
|
|
190
|
+
"when called with",
|
|
191
|
+
[
|
|
192
|
+
"en-US",
|
|
193
|
+
Immutable.fromJS({
|
|
194
|
+
hat: { name: { "en-GB": "", "en-CA": "en-CA Name" } },
|
|
195
|
+
}),
|
|
196
|
+
"fallbakValue",
|
|
197
|
+
["hat", "name"],
|
|
198
|
+
],
|
|
199
|
+
"to equal",
|
|
200
|
+
Immutable.fromJS({
|
|
201
|
+
hat: { name: "en-CA Name" },
|
|
202
|
+
}),
|
|
203
|
+
));
|
|
204
|
+
|
|
205
|
+
it("returns value fallback value when match by language-culture and language does not exist", () =>
|
|
206
|
+
expect(
|
|
207
|
+
setTranslationWithFallbackValue,
|
|
208
|
+
"when called with",
|
|
209
|
+
[
|
|
210
|
+
"en-GB",
|
|
211
|
+
Immutable.fromJS({
|
|
212
|
+
hat: { name: { "fr-CA": "fr-CA Name" } },
|
|
213
|
+
}),
|
|
214
|
+
"fallbakValue",
|
|
215
|
+
["hat", "name"],
|
|
216
|
+
],
|
|
217
|
+
"to equal",
|
|
218
|
+
Immutable.fromJS({
|
|
219
|
+
hat: { name: "fallbakValue" },
|
|
220
|
+
}),
|
|
221
|
+
));
|
|
222
|
+
|
|
223
|
+
it("returns fallbak Value when field value is empty ", () =>
|
|
224
|
+
expect(
|
|
225
|
+
setTranslationWithFallbackValue,
|
|
226
|
+
"when called with",
|
|
227
|
+
[
|
|
228
|
+
"en-GB",
|
|
229
|
+
Immutable.fromJS({
|
|
230
|
+
hat: { name: {} },
|
|
231
|
+
}),
|
|
232
|
+
"fallbakValue",
|
|
233
|
+
["hat", "name"],
|
|
234
|
+
],
|
|
235
|
+
"to equal",
|
|
236
|
+
Immutable.fromJS({
|
|
237
|
+
hat: { name: "fallbakValue" },
|
|
238
|
+
}),
|
|
239
|
+
));
|
|
240
|
+
|
|
241
|
+
it("returns fallbakValue when field is undefined ", () =>
|
|
242
|
+
expect(
|
|
243
|
+
setTranslationWithFallbackValue,
|
|
244
|
+
"when called with",
|
|
245
|
+
[
|
|
246
|
+
"en-GB",
|
|
247
|
+
Immutable.fromJS({
|
|
248
|
+
hat: { name: {} },
|
|
249
|
+
}),
|
|
250
|
+
"fallbakValue",
|
|
251
|
+
["hat", "name2"],
|
|
252
|
+
],
|
|
253
|
+
"to equal",
|
|
254
|
+
Immutable.fromJS({
|
|
255
|
+
hat: { name: {}, name2: "fallbakValue" },
|
|
256
|
+
}),
|
|
257
|
+
));
|
|
150
258
|
});
|