Skip to content

Commit

Permalink
docs: Various README changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkuegler committed Jul 27, 2023
1 parent 937fea4 commit bedb665
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This library is a simple wrapper for [i18next](https://www.i18next.com), simplif
There is also a [Vue 2 version of this package](https://github.com/i18next/i18next-vue/tree/vue-2).

## Upgrade
In the [documentation](https://i18next.github.io/i18next-vue/), you can find information on how to [upgrade from `@panter/vue-i18next`](https://i18next.github.io/i18next-vue/migration.html) or [from `i18next-vue` v2.x](https://i18next.github.io/i18next-vue/migration-v3.html).
In the [documentation](https://i18next.github.io/i18next-vue/), you can find information on how to [upgrade from `@panter/vue-i18next`](https://i18next.github.io/i18next-vue/migration.html) or [from `i18next-vue` 2.x or 1.x](https://i18next.github.io/i18next-vue/migration-v3.html).

## Installation

Expand All @@ -32,11 +32,11 @@ createApp(App).use(I18NextVue, { i18next }).mount('#app');

## Usage

Use the `$t` translation function, which works analogously to the `t` function found in [i18next](https://www.i18next.com/overview/api#t).
Use the `$t` translation function, which works like (and uses) the versatile `t` function from [i18next](https://www.i18next.com/overview/api#t).

There is [a full tutorial](https://dev.to/adrai/how-to-properly-internationalize-a-vue-application-using-i18next-1doj) for setting up i18next-vue. You can check out the [live demo version](https://codesandbox.io/p/sandbox/i18next-vue-v3-y3p49l?file=%2Fsrc%2Fcomponents%2FTranslationShowCase.vue%3A2%2C22) version of it, too.

To learn about more options, check out the [full documentation](https://i18next.github.io/i18next-vue/). This also outlines the migration path from @panter/vue-i18next.
To learn about more options, check out the [full documentation](https://i18next.github.io/i18next-vue/).

### Simple example

Expand Down Expand Up @@ -67,8 +67,10 @@ You can use
</template>
```

Using the composition API you can access the i18next instance and `t()` as well.
But you can also just use $t in the template, without using `useTranslation()`.
`$t()` works both in Options API and Composition API components.

Using the [`useTranslation()` composition function](https://i18next.github.io/i18next-vue/guide/composition-api.html) you can access the i18next instance and `t()` in the `setup` part, and e.g. get a `t()` functions for a specific namespace.

```vue
<script setup>
import { computed } from "vue";
Expand All @@ -87,18 +89,21 @@ const term = computed(() => t("insurance"));

### Translation component

Given the i18next translations
i18next-vue provides a [`<i18next>` translation component](https://i18next.github.io/i18next-vue/guide/component-interpolation.html), so you can use markup (including Vue components) in translations.

In this example `{faq-link}` will be replaced by the `faq-link` slot, i.e. by the router link. You can move `{faq-link}` around in the translation, so it makes sense for the target language.

```js
i18next.init({
// ...
resources: {
en: {
translation: {
"message": "Open the {faq-link} page."
"faq": "FAQ"
"faq": "Frequently Asked Questions"
}
},
de: {
fr: {
// ...
}
}
Expand Down

0 comments on commit bedb665

Please sign in to comment.