Add translations on Me and Home page.
This commit is contained in:
parent
6a97e3cb85
commit
4f8b30ec32
12
src/main.js
12
src/main.js
|
@ -67,6 +67,7 @@ const pages = {
|
||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import translation_en from './translations/en.js'
|
import translation_en from './translations/en.js'
|
||||||
import translation_de from './translations/de.js'
|
import translation_de from './translations/de.js'
|
||||||
|
import formatDistance from 'date-fns/formatDistance';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ function onLoad() {
|
||||||
children: [
|
children: [
|
||||||
ListItem(makeElement({
|
ListItem(makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: "Me",
|
text: i18next.t("me_btn"),
|
||||||
onclick: _ => { changePage("ME"); }
|
onclick: _ => { changePage("ME"); }
|
||||||
}))
|
}))
|
||||||
]
|
]
|
||||||
|
@ -142,7 +143,7 @@ function onLoad() {
|
||||||
tag: "h3",
|
tag: "h3",
|
||||||
class: "uk-card-title",
|
class: "uk-card-title",
|
||||||
id: "pageTitle",
|
id: "pageTitle",
|
||||||
text: "Title"
|
text: ""
|
||||||
}),
|
}),
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "div",
|
tag: "div",
|
||||||
|
@ -174,7 +175,12 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
resources: {
|
resources: {
|
||||||
en: { translation: translation_en },
|
en: { translation: translation_en },
|
||||||
de: { translation: translation_de },
|
de: { translation: translation_de },
|
||||||
|
},
|
||||||
|
interpolation: {
|
||||||
|
format: function (value, format, _) {
|
||||||
|
if (format === 'until_date' && value instanceof Date) return formatDistance(new Date(), new Date(value));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).then(function (t) {
|
}).then(function (t) {
|
||||||
onLoad();
|
onLoad();
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { setErrorText, changePage } from "../pageUtils.js";
|
||||||
import { getAPIURL, getToken } from "../utils.js";
|
import { getAPIURL, getToken } from "../utils.js";
|
||||||
import { makeElement } from "../htmlUtils.js";
|
import { makeElement } from "../htmlUtils.js";
|
||||||
import { getSealStatus, lookupSelf, getMounts } from "../api.js";
|
import { getSealStatus, lookupSelf, getMounts } from "../api.js";
|
||||||
import formatDistance from 'date-fns/formatDistance';
|
import i18next from 'i18next';
|
||||||
|
|
||||||
export class HomePage extends Page {
|
export class HomePage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -35,14 +35,14 @@ export class HomePage extends Page {
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "span",
|
tag: "span",
|
||||||
text: `VaultURL: ${getAPIURL()}`
|
html: i18next.t("vaulturl_text", {"text": getAPIURL()})
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
makeElement({
|
makeElement({
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: "Password Generator",
|
text: i18next.t("password_generator_btn"),
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
changePage("PW_GEN");
|
changePage("PW_GEN");
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,9 @@ export class HomePage extends Page {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let selfTokenInfo = await lookupSelf();
|
let selfTokenInfo = await lookupSelf();
|
||||||
let expireTime = formatDistance(new Date(), new Date(selfTokenInfo.expire_time));
|
|
||||||
textList.appendChild(makeElement({
|
textList.appendChild(makeElement({
|
||||||
tag: "li",
|
tag: "li",
|
||||||
text: `Your token expires in ${expireTime}`
|
text: i18next.t("your_token_expires_in", {"date": new Date(selfTokenInfo.expire_time)})
|
||||||
}));
|
}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setErrorText(e.message);
|
setErrorText(e.message);
|
||||||
|
@ -128,6 +127,6 @@ export class HomePage extends Page {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get name() {
|
get name() {
|
||||||
return "Home";
|
return i18next.t("home_page_title");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,15 +4,14 @@ import { makeElement } from "../htmlUtils.js";
|
||||||
import { getToken } from "../utils.js";
|
import { getToken } from "../utils.js";
|
||||||
import { renewSelf } from "../api.js";
|
import { renewSelf } from "../api.js";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
|
import i18next from 'i18next';
|
||||||
|
|
||||||
|
|
||||||
export class MePage extends Page {
|
export class MePage extends Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
goBack() {
|
|
||||||
changePage("HOME");
|
|
||||||
}
|
|
||||||
async render() {
|
async render() {
|
||||||
setPageContent(makeElement({
|
setPageContent(makeElement({
|
||||||
tag: "ul",
|
tag: "ul",
|
||||||
|
@ -22,7 +21,7 @@ export class MePage extends Page {
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: "Log Out",
|
text: i18next.t("log_out_btn"),
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
changePage("HOME");
|
changePage("HOME");
|
||||||
|
@ -33,7 +32,7 @@ export class MePage extends Page {
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: "Copy Token",
|
text: i18next.t("copy_token_btn"),
|
||||||
attributes: {
|
attributes: {
|
||||||
"data-clipboard-text": getToken(),
|
"data-clipboard-text": getToken(),
|
||||||
},
|
},
|
||||||
|
@ -46,7 +45,7 @@ export class MePage extends Page {
|
||||||
tag: "li",
|
tag: "li",
|
||||||
children: makeElement({
|
children: makeElement({
|
||||||
tag: "a",
|
tag: "a",
|
||||||
text: "Renew Lease",
|
text: i18next.t("renew_lease_btn"),
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
renewSelf().then(() => {
|
renewSelf().then(() => {
|
||||||
changePage("HOME");
|
changePage("HOME");
|
||||||
|
@ -61,6 +60,6 @@ export class MePage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return "Me";
|
return i18next.t("me_page_title");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
// These are the buttons on the top bar.
|
||||||
"home_btn": "Startseite",
|
"home_btn": "Startseite",
|
||||||
"back_btn": "Zurück",
|
"back_btn": "Zurück",
|
||||||
"refresh_btn": "Neu laden"
|
"refresh_btn": "Neu laden"
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
// These are the buttons on the top bar.
|
||||||
"home_btn": "Home",
|
"home_btn": "Home",
|
||||||
"back_btn": "Back",
|
"back_btn": "Back",
|
||||||
"refresh_btn": "Refresh"
|
"refresh_btn": "Refresh",
|
||||||
|
"me_btn": "Me",
|
||||||
|
// These are the page titles
|
||||||
|
"me_page_title": "Me",
|
||||||
|
"home_page_title": "Home",
|
||||||
|
|
||||||
|
// These are all o the other translations
|
||||||
|
"log_out_btn": "Log Out",
|
||||||
|
"copy_token_btn": "Copy Token",
|
||||||
|
"renew_lease_btn": "Renew Token Lease",
|
||||||
|
|
||||||
|
"vaulturl_text": "Vault URL: {{text}}",
|
||||||
|
"password_generator_btn": "Password Generator",
|
||||||
|
"your_token_expires_in": "Your token expires in {{date, until_date}}"
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue