Repository: xiCO2k/laravel-vue-i18n (ts)

Issue:
Multiple occurrences of variable
I have a string with for example,

`Do you really want to block :name. After this :name won't be able to message you.`

First occurrence of :name is translated, second is not.

I used it in the following sentence:

`'Weet je zeker dat je :name wilt deblokkeren? :name kan dan weer berichten sturen.'`

Results in the following:

`Weet je zeker dat je adsasd wilt deblokkeren? :name kan dan weer berichten sturen.`

Thanks for the great plugin! 

Pull request:
fix: Allow multiple occurrences replacements
Fixes #91.

Patch:
diff --git a/src/index.ts b/src/index.ts
index 635032f..bba81e2 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -385,9 +385,9 @@ export class I18n {
       value = value.toString()
 
       message = message
-        .replace(`:${key}`, value)
-        .replace(`:${key.toUpperCase()}`, value.toUpperCase())
-        .replace(`:${capitalize(key)}`, capitalize(value))
+        .replace(new RegExp(`:${key}`, 'g'), value)
+        .replace(new RegExp(`:${key.toUpperCase()}`, 'g'), value.toUpperCase())
+        .replace(new RegExp(`:${capitalize(key)}`, 'g'), capitalize(value))
     })
 
     return message


Test patch:
diff --git a/test/fixtures/lang/pt.json b/test/fixtures/lang/pt.json
index 9c15cf0..4afd8fe 100644
--- a/test/fixtures/lang/pt.json
+++ b/test/fixtures/lang/pt.json
@@ -1,6 +1,7 @@
 {
     "Welcome!": "Bem-vindo!",
     "Welcome, :name!": "Bem-vindo, :name!",
+    "hi :name, hi :name": "olá :name, olá :name",
     "{1} :count minute ago|[2,*] :count minutes ago": "{1} há :count minuto|[2,*] há :count minutos",
     "foo.bar": "baz",
     "Start/end": "Início/Fim",
diff --git a/test/translate.test.ts b/test/translate.test.ts
index 80d8a46..8855399 100644
--- a/test/translate.test.ts
+++ b/test/translate.test.ts
@@ -61,6 +61,12 @@ it('translates key with values with $t mixin', async () => {
   expect(wrapper.html()).toBe('<h1>Bem-vindo, Francisco!</h1>')
 })
 
+it('replaces multiple occurrences with $t mixin', async () => {
+  const wrapper = await global.mountPlugin(`<h1>{{ $t('hi :name, hi :name', { name: 'Francisco' }) }}</h1>`);
+
+    expect(wrapper.html()).toBe('<h1>olá Francisco, olá Francisco</h1>')
+})
+
 it('translates key with values with "trans" helper', async () => {
   await global.mountPlugin();
 
@@ -68,6 +74,13 @@ it('translates key with values with "trans" helper', async () => {
     .toBe('Bem-vindo, Francisco!')
 })
 
+it('replaces multiple occurrences with "trans" helper', async () => {
+  await global.mountPlugin();
+
+  expect(trans('hi :name, hi :name', { name: 'Francisco' }))
+    .toBe('olá Francisco, olá Francisco')
+})
+
 it('loads a lang', async () => {
   const wrapper = await global.mountPlugin(`<h1>{{ $t('Welcome, :name!', { name: 'Francisco' }) }}</h1>`, 'en');
 
@@ -204,4 +217,4 @@ it('does not translate existing strings which contain delimiter symbols', async
 
   expect(trans('Start/end')).toBe('Início/Fim');
   expect(trans('Get started.')).toBe('Comece.');
-})
\ No newline at end of file
+})