Skip to content

Commit

Permalink
style: Use Prettier for formatting
Browse files Browse the repository at this point in the history
Also applying it to the whole code base.
  • Loading branch information
kkuegler committed Jul 27, 2023
1 parent bedb665 commit 06b912f
Show file tree
Hide file tree
Showing 19 changed files with 6,477 additions and 6,378 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: [kkuegler,friedow]
github: [kkuegler, friedow]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up nodejs v18
uses: actions/setup-node@v3
with:
node-version: '18'
node-version: "18"

- name: Install dependencies
run: npm install
Expand All @@ -23,3 +23,6 @@ jobs:

- name: Execute tests
run: npm run test-ci

- name: Check formatting
run: npx prettier . --check
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Set up nodejs v16
uses: actions/setup-node@v3
with:
node-version: '15'
node-version: "15"

- name: Install dependencies
run: npm install

- name: Publish package to npm
uses: JS-DevTools/npm-publish@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist/
/docs/
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"useTabs": true,
"printWidth": 100
}
80 changes: 44 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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` 2.x or 1.x](https://i18next.github.io/i18next-vue/migration-v3.html).

## Installation
Expand Down Expand Up @@ -41,35 +42,41 @@ To learn about more options, check out the [full documentation](https://i18next.
### Simple example

Given the i18next translations

```js
i18next.init({
// ...
resources: {
en: { // language
translation: { // the default namespace
"insurance": "Insurance"
}
},
de: { // language
translation: { // the default namespace
"insurance": "Versicherung"
}
}
}
})
// ...
resources: {
en: {
// language
translation: {
// the default namespace
insurance: "Insurance",
},
},
de: {
// language
translation: {
// the default namespace
insurance: "Versicherung",
},
},
},
});
```

You can use

```vue
<template>
<h1>A test in {{ $i18next.language }}</h1>
<p>{{ $t('insurance') }}</p>
<h1>A test in {{ $i18next.language }}</h1>
<p>{{ $t("insurance") }}</p>
</template>
```

`$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.
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>
Expand All @@ -80,10 +87,10 @@ const term = computed(() => t("insurance"));
</script>
<template>
<h1>A test in {{ i18next.language }}</h1>
<p>inline: {{ t("insurance") }}</p>
<p>inline with $t: {{ $t("insurance") }}</p>
<p>computed: {{ term }}</p>
<h1>A test in {{ i18next.language }}</h1>
<p>inline: {{ t("insurance") }}</p>
<p>inline with $t: {{ $t("insurance") }}</p>
<p>computed: {{ term }}</p>
</template>
```

Expand Down Expand Up @@ -112,13 +119,13 @@ i18next.init({

```vue
<template>
<i18next :translation="$t('message')">
<template #faq-link>
<router-link :to="FAQ_ROUTE">
{{ $t('faq') }}
</router-link>
</template>
</i18next>
<i18next :translation="$t('message')">
<template #faq-link>
<router-link :to="FAQ_ROUTE">
{{ $t("faq") }}
</router-link>
</template>
</i18next>
</template>
```

Expand All @@ -130,7 +137,6 @@ Custom slot values may be useful when the default braces (`{` and `}`) are wrong
Use custom values for recognizing start and end of the insertion points of the `<i18next>`/`TranslationComponent`
inside the localization term:


```js
// main.js
i18next.init({
Expand All @@ -154,20 +160,22 @@ app.use(I18NextVue, {
slotEnd: '</slot>',
});
```

```vue
<!-- Component.vue -->
<template>
<i18next :translation="$t('message')">
<template #faq-link>
<router-link :to="FAQ_ROUTE">
{{ $t('faq') }}
</router-link>
</template>
</i18next>
<i18next :translation="$t('message')">
<template #faq-link>
<router-link :to="FAQ_ROUTE">
{{ $t("faq") }}
</router-link>
</template>
</i18next>
</template>
```

## Contributing

### Requirements

- node.js >= v18
Loading

0 comments on commit 06b912f

Please sign in to comment.