function translateValue(
obj,
translationMap,
{
key,
currentValueLang,
translatedValueLang
} = {}
) {
if (!(translationMap instanceof Map))
throw new Error("`translationMap` should be an instance of Map");
if (key == null) throw new Error("`key` is not provided");
if (currentValueLang == null)
throw new Error("`currentValueLang` is not provided");
const copy = { ...obj };
const currentValueKey = `${key}:${currentValueLang}`;
const translatedValueKey =
translatedValueLang == null ? key : `${key}:${translatedValueLang}`;
const value = obj[key];
if (value === undefined) return obj;
const translatedValue = translationMap.get(value);
delete copy[key];
return {
...copy,
[translatedValueKey]: translatedValue,
[currentValueKey]: value
};
}