feat: i18n: start page
This commit is contained in:
parent
3a4a65b428
commit
a828bb31e8
@ -25,6 +25,7 @@ export default {
|
|||||||
plugins: [
|
plugins: [
|
||||||
{ src: '~/plugins/engine', mode: 'client' },
|
{ src: '~/plugins/engine', mode: 'client' },
|
||||||
{ src: '~/plugins/formatter', mode: 'client' },
|
{ src: '~/plugins/formatter', mode: 'client' },
|
||||||
|
{ src: '~/plugins/i18n', mode: 'client' },
|
||||||
],
|
],
|
||||||
axios: { proxy: true },
|
axios: { proxy: true },
|
||||||
publicRuntimeConfig: {
|
publicRuntimeConfig: {
|
||||||
|
@ -1,37 +1,43 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="create-team">
|
<div class="create-team">
|
||||||
<div v-if="!showModal" class="create-team__button" @click="openModal">
|
<div v-if="!showModal" class="create-team__button" @click="openModal">
|
||||||
create team
|
{{ $t('create-team') }}
|
||||||
</div>
|
</div>
|
||||||
<template v-if="showModal">
|
<template v-if="showModal">
|
||||||
<div class="create-team__backdrop" />
|
<div class="create-team__backdrop" />
|
||||||
<div class="create-team__modal">
|
<div class="create-team__modal">
|
||||||
<template v-if="authcode">
|
<template v-if="authcode">
|
||||||
<div class="create-team__modal-success-message">
|
<div class="create-team__modal-success-message">
|
||||||
<p>Deine PIN lautet:</p>
|
<p>{{ $t('your-pin-is') }}</p>
|
||||||
<div class="create-team__modal-pin">
|
<div class="create-team__modal-pin">
|
||||||
{{ authcode}}
|
{{ authcode}}
|
||||||
</div>
|
</div>
|
||||||
<p>Schreibe sie Dir am besten gleich auf und logge dich anschließend damit ein.</p>
|
<p>{{ $t('remember-pin-and-log-in') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<PlayButton />
|
<PlayButton />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="create-team__modal-content">
|
<div class="create-team__modal-content">
|
||||||
<div class="create-team__modal-close" @click="closeModal" />
|
<div class="create-team__modal-close" @click="closeModal" />
|
||||||
<p>
|
<p>{{ $t('create-team-explain') }}</p>
|
||||||
Erstellt eine neues Team und einen ersten Useraccount für Dich
|
|
||||||
als Gamemaster.
|
|
||||||
</p>
|
|
||||||
<table class="create-team__modal-content-table">
|
<table class="create-team__modal-content-table">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Dein Name</td>
|
<td>{{ $t('your-name') }}</td>
|
||||||
<td><input v-model="name" size="16" /></td>
|
<td><input v-model="name" size="16" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Teamname</td>
|
<td>{{ $t('team-name') }}</td>
|
||||||
<td><input v-model="teamname" size="16" /></td>
|
<td><input v-model="teamname" size="16" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ $t('lang') }}</td>
|
||||||
|
<td>
|
||||||
|
<select v-model="lang">
|
||||||
|
<option value="de">de</option>
|
||||||
|
<option value="en">en</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
@ -39,7 +45,7 @@
|
|||||||
:disabled="name.length == 0 || teamname.length == 0"
|
:disabled="name.length == 0 || teamname.length == 0"
|
||||||
@click="createTeam"
|
@click="createTeam"
|
||||||
>
|
>
|
||||||
create team
|
{{ $t('create-team') }}
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@ -49,9 +55,31 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
beforeMount() {
|
||||||
|
this.$i18n.map({
|
||||||
|
'create-team': { de: 'Team erstellen', en: 'create team' },
|
||||||
|
'your-name': { de: 'Dein Name', en: 'your name' },
|
||||||
|
'team-name': { de: 'Teamname', en: 'team name' },
|
||||||
|
'create-team-explain': {
|
||||||
|
de: 'Erstellt eine neues Team und einen ersten Useraccount für Dich als Gamemaster.',
|
||||||
|
en: 'Creates a new team and a first user account for you as a gamemaster.',
|
||||||
|
},
|
||||||
|
'lang': { de: 'Sprache', en: 'language' },
|
||||||
|
'your-pin-is': { de: 'Deine PIN lautet:', en: 'your pin code is:' },
|
||||||
|
'remember-pin-and-log-in': {
|
||||||
|
de: 'Schreibe sie Dir am besten gleich auf und logge dich anschließend damit ein.',
|
||||||
|
en: 'Write it down now, then log in with your pin code.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
|
let lang = navigator.language ? navigator.language.substr(0, 2) : ''
|
||||||
|
if (lang != 'de' && lang != 'en') {
|
||||||
|
lang = 'en'
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
name: '',
|
name: '',
|
||||||
|
lang,
|
||||||
teamname: '',
|
teamname: '',
|
||||||
authcode: '',
|
authcode: '',
|
||||||
showModal: false,
|
showModal: false,
|
||||||
@ -67,7 +95,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async createTeam() {
|
async createTeam() {
|
||||||
this.showModal = false
|
this.showModal = false
|
||||||
const user = await this.$engine.createTeam(this.name, this.teamname)
|
const user = await this.$engine.createTeam(this.name, this.teamname, this.lang)
|
||||||
this.showModal = true
|
this.showModal = true
|
||||||
this.authcode = user.data.authcode
|
this.authcode = user.data.authcode
|
||||||
},
|
},
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
<div>
|
<div>
|
||||||
<div v-if="!$fetchState.pending" class="playbutton">
|
<div v-if="!$fetchState.pending" class="playbutton">
|
||||||
<template v-if="user && user.name">
|
<template v-if="user && user.name">
|
||||||
<div class="playbutton__greeting">Hi {{ user.name }}!</div>
|
<div class="playbutton__greeting">
|
||||||
<Button @click="$router.push('/play')">Play!</Button>
|
{{ $t('hi') }}
|
||||||
|
{{ user.name }}!
|
||||||
|
</div>
|
||||||
|
<Button @click="$router.push('/play')">{{ $t('play-button') }}</Button>
|
||||||
<div class="playbutton__logout" @click="logout">
|
<div class="playbutton__logout" @click="logout">
|
||||||
logout/switch session
|
{{ $t('logout') }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
@ -28,6 +31,13 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
beforeMount() {
|
||||||
|
this.$i18n.map({
|
||||||
|
'hi': { de: 'Hallo', en: 'Hi' },
|
||||||
|
'play-button': { de: 'Spielen!', en: 'Play!' },
|
||||||
|
'logout': { de: 'Ausloggen/Sitzung wechseln', en: 'logout/switch session' },
|
||||||
|
})
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
authCode: '',
|
authCode: '',
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<PlayButton class="startpage__buttonline" />
|
<PlayButton class="startpage__buttonline" />
|
||||||
<div class="startpage__video">
|
<div class="startpage__video">
|
||||||
<a href="https://www.sirlab.de/knowyt/know-your-teammates-kurzanleitung.mp4" target="_blank">
|
<a href="https://www.sirlab.de/knowyt/know-your-teammates-kurzanleitung.mp4" target="_blank">
|
||||||
🎬 Erklärvideo (3 min)
|
🎬 {{ $t('video-user') }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<CreateTeam v-if="!$store.state.engine.user" class="startpage__creategame" />
|
<CreateTeam v-if="!$store.state.engine.user" class="startpage__creategame" />
|
||||||
@ -14,6 +14,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
beforeMount() {
|
||||||
|
this.$i18n.map({
|
||||||
|
'video-user': { de: 'Erklärvideo (3min)', en: 'Video (3 mins)' },
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import '~/assets/css/components';
|
@import '~/assets/css/components';
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export default async function(name, teamname) {
|
export default async function(name, teamname, lang) {
|
||||||
return await this.callApi('/api/createGame', {
|
return await this.callApi('/api/createGame', {
|
||||||
name,
|
name,
|
||||||
teamname,
|
teamname,
|
||||||
|
lang,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
26
client/src/plugins/i18n.js
Normal file
26
client/src/plugins/i18n.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
let lang = 'DE'
|
||||||
|
let i18nMap = {}
|
||||||
|
let defaultLang = navigator.language ? navigator.language.substr(0, 2) : 'en'
|
||||||
|
|
||||||
|
export default (context, inject) => {
|
||||||
|
const translate = (key) => {
|
||||||
|
const t = i18nMap[key]
|
||||||
|
if (!t) {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
|
return t[lang] || t[defaultLang] || key
|
||||||
|
}
|
||||||
|
inject('t', translate)
|
||||||
|
inject('i18n', {
|
||||||
|
setLang: (_lang) => {
|
||||||
|
lang = _lang
|
||||||
|
},
|
||||||
|
map: (_map) => {
|
||||||
|
i18nMap = {
|
||||||
|
...i18nMap,
|
||||||
|
..._map,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -16,6 +16,9 @@ export const mutations = {
|
|||||||
},
|
},
|
||||||
setUser(state, user) {
|
setUser(state, user) {
|
||||||
state.user = user
|
state.user = user
|
||||||
|
if (user) {
|
||||||
|
this.$i18n.setLang(user.lang)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setGameInfo(state, gameinfo) {
|
setGameInfo(state, gameinfo) {
|
||||||
state.gameinfo = gameinfo
|
state.gameinfo = gameinfo
|
||||||
|
@ -1 +0,0 @@
|
|||||||
{"authcode":"","name":"Crabbe","role":"player","game":"e24444aa-8a18-48aa-a36d-8f84620726f8","created":1649841804}
|
|
Loading…
Reference in New Issue
Block a user