@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
23 lines (19 loc) • 785 B
JavaScript
import useDictionary from "../hooks/useDictionary";
import DEFAULT_DICTIONARY from "../data/dictionary/en-GB.json";
export var pureTranslate = function pureTranslate(translations, key) {
var values = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var translation = translations[key] || DEFAULT_DICTIONARY[key];
if (!translation) {
return key;
}
return Object.keys(values).reduce(function (acc, placeholder) {
return acc.replace(new RegExp("__".concat(placeholder, "__"), "g"), String(values[placeholder]));
}, translation);
};
var Translate = function Translate(_ref) {
var tKey = _ref.tKey,
values = _ref.values;
var dictionary = useDictionary();
return pureTranslate(dictionary, tKey, values);
};
export default Translate;