[tmp] vue i18n error

This commit is contained in:
Philipp Dormann 2021-03-26 18:36:52 +01:00
parent 88996f81d8
commit 7b0bc22a71
5 changed files with 93 additions and 84 deletions

View File

@ -9,7 +9,7 @@
<p
v-if="state.org_name !== ''"
class="mx-auto leading-relaxed text-base text-center"
>Organization: {{ state.org_name }}</p>
>{{ $t('organization') }}: {{ state.org_name }}</p>
<p v-else class="mx-auto leading-relaxed text-base text-center">Bürgerlauf</p>
<div class="mt-4">
<label for="first_name" class="block font-medium">
@ -247,6 +247,8 @@ import isEmail from 'validator/es/lib/isEmail';
import isMobilePhone from 'validator/es/lib/isMobilePhone';
import isPostalCode from 'validator/es/lib/isPostalCode';
import { useToast } from "vue-toastification";
import { router } from '../router';
import { i18n } from '../language';
const props = defineProps({
token: String
@ -274,6 +276,9 @@ const state = reactive({
&& userdetails.value.lastname && (provide_address.value === false || provide_address.value === true && (userdetails.value.address.street.trim() && userdetails.value.address.city.trim() && isPostalCode(userdetails.value.address.zipcode, "DE"))))
})
const toast = useToast();
const $t = this.$t.bind(this)
console.log($t);
// console.log(i18n('you_have_been_registered'));
function login() {
userdetails = userdetails.value;
if (userdetails.phone === "" || isMobilePhone(userdetails.phone)) {
@ -305,9 +310,10 @@ function login() {
axios.post(url, postdata)
.then(({ data }) => {
const token = btoa(data.token);
location.replace("../profile/" + token)
// location.replace("../profile/" + token)
router.push("../profile/" + token);
//
toast.success("You have been registered!");
toast.success($t('you_have_been_registered'));
})
.catch((error) => {
console.log(error);

14
src/language.js Normal file
View File

@ -0,0 +1,14 @@
import * as keys_en from './locales/en.json';
import * as keys_de from './locales/de.json';
import { createI18n } from 'vue-i18n';
const messages = {
en: keys_en,
de: keys_de
};
const browserlocale = ((navigator.languages && navigator.languages[0]) || '').substr(0, 2);
export const i18n = createI18n({
locale: browserlocale,
fallbackLocale: 'en',
messages
});

View File

@ -37,5 +37,7 @@
"this_is_not_a_valid_international_phone_number": "This is not a valid international phone number",
"tos": "Terms of Service",
"view_my_data": "View my data",
"vorname": "Firstname"
"vorname": "Firstname",
"organization": "Organization",
"you_have_been_registered": "You have been registered!"
}

View File

@ -1,49 +1,10 @@
import { createApp } from 'vue';
import { createWebHistory, createRouter } from 'vue-router';
import App from './App.vue';
import { createI18n } from 'vue-i18n';
import Toast from 'vue-toastification';
import 'windi.css';
import 'toastify-js/src/toastify.css';
import 'vue-toastification/dist/index.css';
import * as keys_en from './locales/en.json';
import * as keys_de from './locales/de.json';
import { router } from './router';
import { i18n } from './language';
const messages = {
en: keys_en,
de: keys_de
};
const browserlocale = ((navigator.languages && navigator.languages[0]) || '').substr(0, 2);
const i18n = createI18n({
locale: browserlocale,
fallbackLocale: 'en',
messages
});
// ---------------
const EnvError = import('./components/EnvError.vue');
const Home = import('./components/Home.vue');
const Imprint = import('./components/Imprint.vue');
const Privacy = import('./components/Privacy.vue');
const Register = () => import('./components/Register.vue');
const Profile = () => import('./components/Profile.vue');
//
let routes = [ { path: '/:pathMatch(.*)*', component: EnvError } ];
if (typeof config !== 'undefined') {
if (config.baseurl && config.documentserver_key) {
routes = [
{ path: '/', component: Home },
{ path: '/imprint', component: Imprint },
{ path: '/privacy', component: Privacy },
{ path: '/register', component: Register },
{ path: '/register/:token', component: Register, props: true },
{ path: '/profile/:token', component: Profile, props: true }
];
}
}
const router = createRouter({
history: createWebHistory(),
routes
});
// ---------------
createApp(App).use(Toast).use(i18n).use(router).mount('#app');

26
src/router.js Normal file
View File

@ -0,0 +1,26 @@
import { createWebHistory, createRouter } from 'vue-router';
// ------------
const EnvError = import('./components/EnvError.vue');
const Home = import('./components/Home.vue');
const Imprint = import('./components/Imprint.vue');
const Privacy = import('./components/Privacy.vue');
const Register = () => import('./components/Register.vue');
const Profile = () => import('./components/Profile.vue');
//
let routes = [ { path: '/:pathMatch(.*)*', component: EnvError } ];
if (typeof config !== 'undefined') {
if (config.baseurl && config.documentserver_key) {
routes = [
{ path: '/', component: Home },
{ path: '/imprint', component: Imprint },
{ path: '/privacy', component: Privacy },
{ path: '/register', component: Register },
{ path: '/register/:token', component: Register, props: true },
{ path: '/profile/:token', component: Profile, props: true }
];
}
}
export const router = createRouter({
history: createWebHistory(),
routes
});