From 90fb99db71e44c2854b02d1403f8664ced4ac2a6 Mon Sep 17 00:00:00 2001
From: FireMasterK <20838718+FireMasterK@users.noreply.github.com>
Date: Wed, 25 Aug 2021 21:57:30 +0530
Subject: [PATCH] Add support for i18n in more places.
---
src/App.vue | 13 +++++++++++++
src/components/Navigation.vue | 6 +++---
src/components/Player.vue | 2 +-
src/components/Preferences.vue | 27 ++++++++++++++++++++++++---
src/components/TrendingPage.vue | 2 +-
src/components/WatchVideo.vue | 6 +++---
src/locales/en.json | 7 +++++++
src/main.js | 6 +++---
8 files changed, 55 insertions(+), 14 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 66a70eb1..8f026b62 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -58,6 +58,19 @@ export default {
window.db = e.target.result;
};
} else console.log("This browser doesn't support IndexedDB");
+
+ const App = this;
+
+ (async function() {
+ const locale = App.getPreferenceString("hl", "en");
+ if (window.i18n.global.locale.value !== locale) {
+ if (!window.i18n.global.availableLocales.includes(locale)) {
+ const messages = await import("@/locales/" + locale + ".json").then(module => module.default);
+ window.i18n.global.setLocaleMessage(locale, messages);
+ }
+ window.i18n.global.locale.value = locale;
+ }
+ })();
},
};
diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue
index 7e0a7edb..686f2a28 100644
--- a/src/components/Navigation.vue
+++ b/src/components/Navigation.vue
@@ -32,16 +32,16 @@
Preferences
- Login
+
- Register
+
History
- Feed
+
diff --git a/src/components/Player.vue b/src/components/Player.vue
index e92cec74..40af2be2 100644
--- a/src/components/Player.vue
+++ b/src/components/Player.vue
@@ -307,7 +307,7 @@ export default {
this.player = undefined;
}
if (this.hotkeys) this.hotkeys.unbind();
- this.$refs.container.querySelectorAll("div").forEach(node => node.remove());
+ if (this.$refs.container) this.$refs.container.querySelectorAll("div").forEach(node => node.remove());
},
};
diff --git a/src/components/Preferences.vue b/src/components/Preferences.vue
index c15b1da1..501550c5 100644
--- a/src/components/Preferences.vue
+++ b/src/components/Preferences.vue
@@ -3,7 +3,7 @@
- Preferences
+
@@ -92,6 +92,12 @@
Store Watch History
+
+ Language Selection
+
+
Instances List
@@ -152,10 +158,15 @@ export default {
showComments: true,
minimizeDescription: false,
watchHistory: false,
+ selectedLanguage: "en",
+ languages: [
+ { code: "en", name: "English" },
+ { code: "fr", name: "French" },
+ ],
};
},
activated() {
- document.title = "Preferences - Piped";
+ document.title = this.$t("titles.preferences") + " - Piped";
},
mounted() {
if (Object.keys(this.$route.query).length > 0) this.$router.replace({ query: {} });
@@ -179,6 +190,13 @@ export default {
cdn: split[3].trim(),
});
}
+ if (this.instances.filter(instance => instance.apiurl == this.apiUrl()).length > 0)
+ this.instances.push({
+ name: "Custom Instance",
+ apiurl: this.apiUrl(),
+ locations: "Unknown",
+ cdn: "Unknown",
+ });
});
});
@@ -229,6 +247,7 @@ export default {
this.showComments = this.getPreferenceBoolean("comments", true);
this.minimizeDescription = this.getPreferenceBoolean("minimizeDescription", false);
this.watchHistory = this.getPreferenceBoolean("watchHistory", false);
+ this.selectedLanguage = this.getPreferenceString("hl", "en");
}
},
methods: {
@@ -238,7 +257,8 @@ export default {
if (
this.getPreferenceString("theme", "dark") !== this.selectedTheme ||
- this.getPreferenceBoolean("watchHistory", false) != this.watchHistory
+ this.getPreferenceBoolean("watchHistory", false) != this.watchHistory ||
+ this.getPreferenceString("hl", "en") !== this.selectedLanguage
)
shouldReload = true;
@@ -265,6 +285,7 @@ export default {
localStorage.setItem("comments", this.showComments);
localStorage.setItem("minimizeDescription", this.minimizeDescription);
localStorage.setItem("watchHistory", this.watchHistory);
+ localStorage.setItem("hl", this.selectedLanguage);
if (shouldReload) window.location.reload();
}
diff --git a/src/components/TrendingPage.vue b/src/components/TrendingPage.vue
index 6f667c73..5f0b939e 100644
--- a/src/components/TrendingPage.vue
+++ b/src/components/TrendingPage.vue
@@ -1,5 +1,5 @@
- {{ $t("titles.trending") }}
+
diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue
index 0fd059a5..9155c549 100644
--- a/src/components/WatchVideo.vue
+++ b/src/components/WatchVideo.vue
@@ -42,7 +42,7 @@
class="uk-margin-small-left uk-button uk-button-small"
style="background: #222"
>
- Watch on
+ {{ $t("player.watch_on") }}
- Watch on LBRY
+ {{ $t("player.watch_on") }} LBRY
@@ -68,7 +68,7 @@
style="background: #222"
type="button"
>
- {{ subscribed ? "Unsubscribe" : "Subscribe" }}
+ {{ subscribed ? $t("actions.unsubscribe") : $t("actions.subscribe") }}
diff --git a/src/locales/en.json b/src/locales/en.json
index 5fc95822..d4718044 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -5,5 +5,12 @@
"register": "Register",
"feed": "Feed",
"preferences": "Preferences"
+ },
+ "player": {
+ "watch_on": "Watch on"
+ },
+ "actions": {
+ "subscribe": "Subscribe",
+ "unsubscribe": "Unsubscribe"
}
}
diff --git a/src/main.js b/src/main.js
index b092e785..13775325 100644
--- a/src/main.js
+++ b/src/main.js
@@ -107,7 +107,7 @@ 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).toLowerCase()) {
@@ -124,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;
@@ -133,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);