anu-verzum 1.5.0 → 1.6.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.
- package/README.md +1 -0
- package/dist/core/components/Component.js +1 -1
- package/dist/core/components/Intl.js +13 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,16 @@ const IntlProvider = ({
|
|
|
49
49
|
return undefined;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
+
const interpolateValues = (text, values) => {
|
|
53
|
+
let result = text;
|
|
54
|
+
Object.keys(values).forEach(key => {
|
|
55
|
+
const variablePattern = `{${key}}`;
|
|
56
|
+
if (result.indexOf(variablePattern) > -1) {
|
|
57
|
+
result = result.replace(new RegExp(`\\{${key}\\}`, 'g'), String(values[key]));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
52
62
|
const FormattedMessage = ({
|
|
53
63
|
id,
|
|
54
64
|
values,
|
|
@@ -58,7 +68,7 @@ const FormattedMessage = ({
|
|
|
58
68
|
messages
|
|
59
69
|
}
|
|
60
70
|
}) => {
|
|
61
|
-
let textValue
|
|
71
|
+
let textValue;
|
|
62
72
|
try {
|
|
63
73
|
if (messages && messages[id]) {
|
|
64
74
|
textValue = messages[id];
|
|
@@ -71,12 +81,7 @@ const FormattedMessage = ({
|
|
|
71
81
|
throw new Error('No text or fallback value to return.');
|
|
72
82
|
} else {
|
|
73
83
|
if (values && typeof values === 'object' && values !== null) {
|
|
74
|
-
|
|
75
|
-
const variablePattern = `{${key}}`;
|
|
76
|
-
if (textValue.indexOf(variablePattern) > -1) {
|
|
77
|
-
textValue = textValue.replace(variablePattern, String(values[key]));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
84
|
+
textValue = interpolateValues(textValue, values);
|
|
80
85
|
}
|
|
81
86
|
return (0, _elements.createElement)(_elements.TEXT_ELEMENT, {
|
|
82
87
|
nodeValue: textValue
|
|
@@ -104,12 +109,7 @@ const formatMessage = (id, values, defaultMessage) => {
|
|
|
104
109
|
console.error(err);
|
|
105
110
|
}
|
|
106
111
|
if (values && typeof values === 'object' && values !== null) {
|
|
107
|
-
|
|
108
|
-
const variablePattern = `{${key}}`;
|
|
109
|
-
if (textValue.indexOf(variablePattern) > -1) {
|
|
110
|
-
textValue = textValue.replace(variablePattern, String(values[key]));
|
|
111
|
-
}
|
|
112
|
-
});
|
|
112
|
+
textValue = interpolateValues(textValue, values);
|
|
113
113
|
}
|
|
114
114
|
return textValue;
|
|
115
115
|
};
|
package/package.json
CHANGED