Skip to content

Commit 56bf836

Browse files
authored
Update README.md
1 parent c603570 commit 56bf836

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ trans('Welcome, :name!', { name: 'Francisco' }) // Bem-vindo Francisco!
7777
trans('Welcome, :NAME!', { name: 'Francisco' }) // Bem-vindo FRANCISCO!
7878
```
7979

80+
### `wTrans(message: string, replacements: {})`
81+
82+
The `wTrans()` same as `trans()` but returns a reactive obj with translated value.
83+
84+
```jsx
85+
// lang/pt.json
86+
{
87+
"Welcome!": "Bem-vindo!",
88+
"Welcome, :name!": "Bem-vindo, :name!",
89+
}
90+
91+
import { wTrans } from 'laravel-vue-i18n';
92+
93+
setup() {
94+
return {
95+
welcomeLabel: wTrans('Welcome!'),
96+
welcomeFrancisco: wTrans('Welcome, :name!', { name: 'Francisco' })
97+
}
98+
}
99+
100+
<template>
101+
<div>{{ welcomeLabel }}</div> // <div>Bem-vindo!</div>
102+
<div>{{ welcomeFrancisco }}</div> // <div>Bem-vindo, Francisco!</div>
103+
</template>
104+
```
105+
80106
### `transChoice(message: string, count: number, replacements: {})`
81107

82108
The `transChoice()` method can translate a given message based on a count,
@@ -97,6 +123,35 @@ transChoice('{0} There are none|[1,19] There are some|[20,*] There are many', 19
97123
transChoice('{1} :count minute ago|[2,*] :count minutes ago', 10); // Há 10 minutos.
98124
```
99125

126+
127+
### `wTransChoice(message: string, count: number, replacements: {})`
128+
129+
The `wTransChoice()` same as `transChoice()` but returns a reactive obj with translated value.
130+
131+
132+
```jsx
133+
// lang/pt.json
134+
{
135+
"There is one apple|There are many apples": "Existe uma maça|Existe muitas maças",
136+
"{0} There are none|[1,19] There are some|[20,*] There are many": "Não tem|Tem algumas|Tem muitas",
137+
"{1} :count minute ago|[2,*] :count minutes ago": "{1} há :count minuto|[2,*] há :count minutos",
138+
}
139+
140+
import { wTransChoice } from 'laravel-vue-i18n';
141+
142+
setup() {
143+
return {
144+
oneAppleLabel: wTransChoice('There is one apple|There are many apples', 1),
145+
multipleApplesLabel: wTransChoice('{0} There are none|[1,19] There are some|[20,*] There are many', 19)
146+
}
147+
}
148+
149+
<template>
150+
<div>{{ oneAppleLabel }}</div> // <div>Existe uma maça</div>
151+
<div>{{ multipleApplesLabel }}</div> // <div>Tem algumas</div>
152+
</template>
153+
```
154+
100155
### `loadLanguageAsync(lang: string)`
101156

102157
The `loadLanguageAsync()` can be used to change the location during the runtime.

0 commit comments

Comments
 (0)