Skip to content

Commit 6f46418

Browse files
committed
Add locale questions
1 parent 44f662c commit 6f46418

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ List of 300 VueJS Interview Questions
218218
|209| [How do you handle Pluralization?](#how-do-you-handle-pluralization)|
219219
|210| [How to implement DateTime localization?](#how-to-implement-date-time-localization)|
220220
|211| [How do you implement Number localization?](#how-do-you-implement-number-localization)|
221+
|212| [How do you perform locale changing](#how-do-you-perform-locale-changin)|
221222

222223
1. ### What is VueJS?
223224
**Vue.js** is an open-source, progressive Javascript framework for building user interfaces that aim to be incrementally adoptable. The core library of VueJS is focused on the `view layer` only, and is easy to pick up and integrate with other libraries or existing projects.
@@ -3816,5 +3817,41 @@ List of 300 VueJS Interview Questions
38163817
<p>50</p>
38173818
</div>
38183819
```
3820+
212. ### How do you perform locale changing?
3821+
All child components of a root instance are localized using the locale property of the VueI18n class. You can change the value of the locale property of the VueI18n instance as below.
3822+
```javascript
3823+
const i18n = new VueI18n({
3824+
locale: 'de', // set locale
3825+
...
3826+
})
3827+
3828+
// create root Vue instance
3829+
new Vue({
3830+
i18n,
3831+
...
3832+
}).$mount('#app')
3833+
3834+
// change other locale
3835+
i18n.locale = 'en'
3836+
```
3837+
You can also use component's VueI18n instance referenced as the $i18n property which will be used to change the locale.
3838+
```javascript
3839+
<template>
3840+
<div class="locale-changer">
3841+
<select v-model="$i18n.locale">
3842+
<option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</option>
3843+
</select>
3844+
</div>
3845+
</template>
3846+
3847+
<script>
3848+
export default {
3849+
name: 'locale-changer',
3850+
data () {
3851+
return { langs: ['de', 'en'] }
3852+
}
3853+
}
3854+
</script>
3855+
```
38193856
38203857

0 commit comments

Comments
 (0)