Add i18n translations. (#381)

* Initial prototype.

* Add support for i18n in more places.
This commit is contained in:
Kavin
2021-08-25 22:00:21 +05:30
committed by GitHub
parent 45f132e2b4
commit 4ae77badd8
12 changed files with 169 additions and 22 deletions

View File

@@ -42,6 +42,9 @@ import en from "javascript-time-ago/locale/en";
TimeAgo.addDefaultLocale(en);
import { createI18n } from "vue-i18n";
import enLocale from "@/locales/en.json";
const timeAgo = new TimeAgo("en-US");
import("./registerServiceWorker");
@@ -104,10 +107,10 @@ const mixin = {
getPreferenceBoolean(key, defaultVal) {
var value;
if (
(value = this.$route.query[key]) !== undefined ||
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
(localStorage && (value = localStorage.getItem(key)) !== null)
) {
switch (String(value)) {
switch (String(value).toLowerCase()) {
case "true":
case "1":
case "on":
@@ -121,7 +124,7 @@ const mixin = {
getPreferenceString(key, defaultVal) {
var value;
if (
(value = this.$route.query[key]) !== undefined ||
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
(localStorage && (value = localStorage.getItem(key)) !== null)
) {
return value;
@@ -130,7 +133,7 @@ const mixin = {
getPreferenceNumber(key, defaultVal) {
var value;
if (
(value = this.$route.query[key]) !== undefined ||
(value = new URLSearchParams(window.location.search).get(key)) !== null ||
(localStorage && (value = localStorage.getItem(key)) !== null)
) {
return Number(value);
@@ -202,7 +205,20 @@ const mixin = {
},
};
const i18n = createI18n({
globalInjection: true,
legacy: false,
locale: "en",
fallbackLocale: "en",
messages: {
en: enLocale,
},
});
window.i18n = i18n;
const app = createApp(App);
app.use(i18n);
app.use(router);
app.mixin(mixin);
app.component("font-awesome-icon", FontAwesomeIcon);