Skip to content
This repository was archived by the owner on May 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/index.html → examples/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>vue-i18next Example</title>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/i18next.js"></script>
<script src="../dist/vue-i18next.js"></script>
<script src="../../dist/vue-i18next.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style media="screen">
body {
Expand Down
92 changes: 92 additions & 0 deletions examples/http-backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable no-undef, new-cap */

i18next.use(i18nextHttpBackend).init({
debug: true,
lng: 'en',
fallbackLng: 'en',
backend: {
loadPath: './locales/{{lng}}/{{ns}}.json'
}
}, () => {
const i18n = new VueI18next(i18next);

Vue.component('app', {
template: `
<div>
<div>
<h3>Translation</h3>
<language-changer></language-changer>
<p>$t: {{ $t("message.hello") }}</p>
</div>
<div>
<h3>Interpolation</h3>
<i18next path="term" tag="label" for="tos">
<a href="#" target="_blank">{{ $t("tos") }}</a>
<strong>a</strong>
</i18next>
</div>
<div>
<h3>Prefix</h3>
<key-prefix></key-prefix>
</div>
<div>
<h3>Inline translations</h3>
<inline-translations></inline-translations>
</div>
<div>
<h3>Directive</h3>
<with-directive></with-directive>
</div>
</div>`,
});

Vue.component('language-changer', {
template: `
<div>
<a v-on:click="changeLanguage('de')">DE</a>
&nbsp;|&nbsp;
<a v-on:click="changeLanguage('en')">EN</a>
</div>`,
methods: {
changeLanguage(lang) {
this.$i18n.i18next.changeLanguage(lang);
},
},
});

Vue.component('key-prefix', {
i18nOptions: {
keyPrefix: 'message',
},
template: `
<div>
<p>{{$t('hello')}}</p>
</div>`,
});

Vue.component('inline-translations', {
i18nOptions: {
messages: {
en: {
welcome: 'Welcome!',
},
de: {
welcome: 'Guten Tag!',
},
},
},
template: `
<div>
{{$t('welcome')}}
</div>`,
});

Vue.component('with-directive', {
template: `
<div v-t="{path:'message.hello'}"></div>`,
});

new Vue({
i18n,
}).$mount('#app');
});
28 changes: 28 additions & 0 deletions examples/http-backend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue-i18next Example</title>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/i18next.js"></script>
<script src="../../dist/vue-i18next.js"></script>
<script src="https://cdn.jsdelivr.net/gh/i18next/i18next-http-backend/i18nextHttpBackend.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style media="screen">
body {
height: 100%;
}
#app {
max-width: 800px;
margin: 40px;
}

</style>
</head>
<body>
<div id="app">
<app />
</div>
<script src="app.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/http-backend/locales/de/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"message": {
"hello": "Hallo!! - DE"
},
"tos": "Nutzungsbedingungen",
"term": "Ich akzeptiere {{0}}. {{1}}",
"loadbundle": "Bundle Laden {{lang}}"
}
8 changes: 8 additions & 0 deletions examples/http-backend/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"message": {
"hello": "Hello!! - EN"
},
"tos": "Term of Service",
"term": "I accept {{1}} {{0}}.",
"loadbundle": "Load Bundle {{lang}}"
}
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = {
devServer: {
historyApiFallback: {
rewrites: [
{ from: /^\/$/, to: '/examples/index.html' },
{ from: 'app.js', to: '/examples/app.js' },
{ from: /^\/$/, to: '/examples/basic/index.html' },
{ from: 'app.js', to: '/examples/basic/app.js' },
],
},
noInfo: true,
Expand Down