Skip to content

Commit

Permalink
i18next-vue example
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed May 13, 2022
1 parent 23a2198 commit 888b988
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 0 deletions.
23 changes: 23 additions & 0 deletions example/i18next-vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
24 changes: 24 additions & 0 deletions example/i18next-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vue-starter-project

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run serve
```

### Compiles and minifies for production
```
npm run build
```

### Lints and fixes files
```
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
5 changes: 5 additions & 0 deletions example/i18next-vue/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
46 changes: 46 additions & 0 deletions example/i18next-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.22.5",
"i18next": "21.8.2",
"i18next-browser-languagedetector": "6.1.4",
"i18next-http-backend": "1.4.0",
"i18next-vue": "2.0.0-beta.0",
"vue": "^3.2.33"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.15",
"@vue/cli-plugin-eslint": "~4.5.15",
"@vue/cli-service": "~4.5.15",
"@vue/compiler-sfc": "^3.2.33",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^8.7.1"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Binary file added example/i18next-vue/public/favicon.ico
Binary file not shown.
17 changes: 17 additions & 0 deletions example/i18next-vue/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
5 changes: 5 additions & 0 deletions example/i18next-vue/public/locales/de/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"welcome": "Willkommen zu Deiner Vue.js App",
"descr": "<1/> Eine Anleitung und Rezepte für das Konfigurieren / Anpassen dieses Projekts findest du in der <0>vue-cli Dokumentation</0>.",
"end": "habe Spass!"
}
5 changes: 5 additions & 0 deletions example/i18next-vue/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"welcome": "Welcome to Your Vue.js App",
"descr": "<1/> For a guide and recipes on how to configure / customize this project, check out the <0>vue-cli documentation</0>.",
"end": "have fun!"
}
32 changes: 32 additions & 0 deletions example/i18next-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<img alt="Vue logo" src="./assets/logo.png">
<TranslationShowCase />
</template>

<script>
import TranslationShowCase from './components/TranslationShowCase.vue'
export default {
name: 'App',
components: {
TranslationShowCase
},
// used in combination with Suspense.
// useful when translations are not in-memory...
// async setup() {
// await i18nextPromise;
// return {};
// }
}
</script>

<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
24 changes: 24 additions & 0 deletions example/i18next-vue/src/Suspenser.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<Suspense>
<template #default>
<App />
</template>
<template #fallback>
<span>Loading...</span>
</template>
</Suspense>
</template>

<script>
import App from './App.vue'
export default {
name: 'SuspenserComponent',
components: {
App
}
}
</script>

<style>
</style>
Binary file added example/i18next-vue/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions example/i18next-vue/src/components/TranslationShowCase.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div class="hello">
<h1>{{ $t("welcome") }}</h1>
<!--<p>
<TransComponent i18nKey="descr">
<a href="https://cli.vuejs.org" target="_blank" rel="noopener" /><i>👋</i>
</TransComponent>
</p>
<div>
<div>
<span v-t="{key:'end'}" /> <i v-t="'end'" />
</div>
</div>
<hr />-->
<div>
<div>
<a v-if="$i18next.resolvedLanguage !== 'de'" v-on:click="$i18next.changeLanguage('de')">
DE
</a>
<strong v-if="$i18next.resolvedLanguage === 'de'">
DE
</strong>
&nbsp;|&nbsp;
<a v-if="$i18next.resolvedLanguage !== 'en'" v-on:click="$i18next.changeLanguage('en')">
EN
</a>
<strong v-if="$i18next.resolvedLanguage === 'en'">
EN
</strong>
</div>
</div>
</div>
</template>

<script>
export default {
name: 'TranslationShowCase'
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
18 changes: 18 additions & 0 deletions example/i18next-vue/src/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import I18NextVue from 'i18next-vue';
import i18next from 'i18next'
import i18nextHttpBackend from 'i18next-http-backend'
import LanguageDetector from 'i18next-browser-languagedetector'

export default function (app) {
i18next
.use(LanguageDetector)
.use(i18nextHttpBackend)
.init({
debug: true,
fallbackLng: 'en',
backend: {
loadPath: './locales/{{lng}}/{{ns}}.json'
}
});
app.use(I18NextVue, { i18next });
}
7 changes: 7 additions & 0 deletions example/i18next-vue/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createApp } from 'vue'
import init from './i18n'
import App from './Suspenser.vue'

const app = createApp(App)
init(app)
app.mount('#app')

0 comments on commit 888b988

Please sign in to comment.