Skip to content

Commit

Permalink
feat: page title localization
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiresviana committed May 4, 2022
1 parent c3bd118 commit 8a43413
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
28 changes: 22 additions & 6 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -29,7 +45,6 @@ const router = new Router({
return next({ path: "/files" });
}

document.title = "Login - " + name;
next();
},
},
Expand Down Expand Up @@ -63,7 +78,7 @@ const router = new Router({
children: [
{
path: "/settings/profile",
name: "Profile Settings",
name: "ProfileSettings",
component: ProfileSettings,
},
{
Expand All @@ -73,7 +88,7 @@ const router = new Router({
},
{
path: "/settings/global",
name: "Global Settings",
name: "GlobalSettings",
component: GlobalSettings,
meta: {
requiresAdmin: true,
Expand Down Expand Up @@ -108,7 +123,7 @@ const router = new Router({
},
{
path: "/404",
name: "Not Found",
name: "NotFound",
component: Errors,
props: {
errorCode: 404,
Expand All @@ -117,7 +132,7 @@ const router = new Router({
},
{
path: "/500",
name: "Internal Server Error",
name: "InternalServerError",
component: Errors,
props: {
errorCode: 500,
Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/views/Files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +51,6 @@ export default {
},
computed: {
...mapState(["req", "reload", "loading", "show"]),
name: () => name,
currentView() {
if (this.req.type == undefined) {
return null;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/Share.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8a43413

Please sign in to comment.