feat: page title localization

This commit is contained in:
Ramires Viana 2022-05-04 13:16:16 +00:00
parent c3bd1188aa
commit 8a43413f88
3 changed files with 24 additions and 10 deletions

View File

@ -13,9 +13,25 @@ import Shares from "@/views/settings/Shares";
import Errors from "@/views/Errors";
import store from "@/store";
import { baseURL, name } from "@/utils/constants";
import i18n from "@/i18n";
Vue.use(Router);
const titles = {
Login: "sidebar.login",
Share: "buttons.share",
Files: "files.files",
Settings: "sidebar.settings",
ProfileSettings: "settings.profileSettings",
Shares: "settings.shareManagement",
GlobalSettings: "settings.globalSettings",
Users: "settings.users",
User: "settings.user",
Forbidden: "errors.forbidden",
NotFound: "errors.notFound",
InternalServerError: "errors.internal",
};
const router = new Router({
base: baseURL,
mode: "history",
@ -29,7 +45,6 @@ const router = new Router({
return next({ path: "/files" });
}
document.title = "Login - " + name;
next();
},
},
@ -63,7 +78,7 @@ const router = new Router({
children: [
{
path: "/settings/profile",
name: "Profile Settings",
name: "ProfileSettings",
component: ProfileSettings,
},
{
@ -73,7 +88,7 @@ const router = new Router({
},
{
path: "/settings/global",
name: "Global Settings",
name: "GlobalSettings",
component: GlobalSettings,
meta: {
requiresAdmin: true,
@ -108,7 +123,7 @@ const router = new Router({
},
{
path: "/404",
name: "Not Found",
name: "NotFound",
component: Errors,
props: {
errorCode: 404,
@ -117,7 +132,7 @@ const router = new Router({
},
{
path: "/500",
name: "Internal Server Error",
name: "InternalServerError",
component: Errors,
props: {
errorCode: 500,
@ -140,7 +155,8 @@ const router = new Router({
});
router.beforeEach((to, from, next) => {
document.title = to.name + " - " + name;
const title = i18n.t(titles[to.name]);
document.title = title + " - " + name;
if (to.matched.some((record) => record.meta.requiresAuth)) {
if (!store.getters.isLogged) {

View File

@ -28,7 +28,6 @@ import Breadcrumbs from "@/components/Breadcrumbs";
import Errors from "@/views/Errors";
import Preview from "@/views/files/Preview";
import Listing from "@/views/files/Listing";
import { name } from "@/utils/constants";
function clean(path) {
return path.endsWith("/") ? path.slice(0, -1) : path;
@ -52,7 +51,6 @@ export default {
},
computed: {
...mapState(["req", "reload", "loading", "show"]),
name: () => name,
currentView() {
if (this.req.type == undefined) {
return null;
@ -118,7 +116,7 @@ export default {
}
this.$store.commit("updateRequest", res);
document.title = `${res.name} - ${this.$route.name} - ${this.name}`;
document.title = `${res.name} - ${document.title}`;
} catch (e) {
this.error = e;
} finally {

View File

@ -280,7 +280,7 @@ export default {
this.token = file.token || "";
this.updateRequest(file);
document.title = `${file.name} - ${this.$route.name}`;
document.title = `${file.name} - ${document.title}`;
} catch (e) {
this.error = e;
} finally {