diff --git a/common/translations/index.tsx b/common/translations/index.tsx index d2d865e0..450e4238 100644 --- a/common/translations/index.tsx +++ b/common/translations/index.tsx @@ -67,13 +67,21 @@ export function translateRaw(key: string, variables?: { [name: string]: string } const translatedString = (repository[language] && repository[language][key]) || repository[fallbackLanguage][key] || key; - if (!!variables) { - // Find each variable and replace it in the translated string - let str = translatedString; - Object.keys(variables).forEach(v => { - const re = new RegExp(v.replace('$', '\\$'), 'g'); - str = str.replace(re, variables[v]); + /** @desc In RegExp, $foo is two "words", but __foo is only one "word." + * Replace all occurences of '$' with '__' in the entire string and each variable, + * then iterate over each variable, replacing the '__variable' in the + * translation key with the variable's value. + */ + if (variables) { + let str = translatedString.replace(/\$/g, '__'); + + Object.keys(variables).forEach(variable => { + const singleWordVariable = variable.replace(/\$/g, '__'); + const re = new RegExp(`\\b${singleWordVariable}\\b`, 'g'); + + str = str.replace(re, variables[variable]); }); + return str; }