Allow more than 2 variable substitutions in the translation function

This commit is contained in:
Alexander Tseung 2018-08-31 12:12:12 -07:00
parent 31089778ba
commit e5ca2aac6f
1 changed files with 4 additions and 4 deletions

View File

@ -20,10 +20,10 @@ const getMessage = (locale, key, substitutions) => {
let phrase = entry.message let phrase = entry.message
// perform substitutions // perform substitutions
if (substitutions && substitutions.length) { if (substitutions && substitutions.length) {
phrase = phrase.replace(/\$1/g, substitutions[0]) substitutions.forEach((substitution, index) => {
if (substitutions.length > 1) { const regex = new RegExp(`\\$${index + 1}`, 'g')
phrase = phrase.replace(/\$2/g, substitutions[1]) phrase = phrase.replace(regex, substitution)
} })
} }
return phrase return phrase
} }