Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.5.14",
"@astrojs/check": "^0.5.10",
"typescript": "^5.4.3"
"astro": "^4.5.14",
"typescript": "^5.4.5"
}
}
}
8 changes: 4 additions & 4 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export const en = {
projects: "Get in touch with my projects"
},

not_found: {
404: {
title: "404 - Not found!",
description: {
l1: "Looks like I haven't developed this yet!",
l2: "Feel free to suggest me anything, talk to me on any of",
socials: "my socials!"
}
l2: "Feel free to suggest me anything, talk to me on any of"
},
socials: "my socials!"
},

footer: {
Expand Down
8 changes: 4 additions & 4 deletions src/i18n/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export const pt = {
projects: "Veja os meus projetos"
},

not_found: {
404: {
title: "404 - Não encontrado!",
description: {
l1: "Parece que eu ainda não desenvolvi essa página!",
l2: "Se quiser sugerir alguma ideia, me chame em qualquer uma das",
socials: "minhas redes sociais!"
}
l2: "Se quiser sugerir alguma ideia, me chame em qualquer uma das"
},
socials: "minhas redes sociais!"
},

footer: {
Expand Down
11 changes: 7 additions & 4 deletions src/i18n/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import { i18n, defaultLang } from "./ui.ts";
import { languages, i18n, defaultLang } from "./ui.ts";

export function getLanguageFromURL(url: URL): string {
var splittedURL = url.pathname.split("/");
var currentIntl = splittedURL[1]; // Gets the second URL part
var domain = splittedURL[0].replace("/", "");
var splittedURL: string[] = url.pathname.split("/");
var currentIntl: string = splittedURL[1]; // Gets the second URL part

if(currentIntl in i18n)
return currentIntl as keyof typeof i18n;
Expand All @@ -25,3 +24,7 @@ export function useTranslations(lang: keyof typeof i18n): Function {
return translation || defaultTranslation || "Couldn't find key to translate.";
}
}

export function getLanguages() {
return languages;
}
19 changes: 11 additions & 8 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
import { getLanguageFromURL, useTranslations } from "../i18n/utils";
import { getLanguages, getLanguageFromURL, useTranslations } from "../i18n/utils";
import "../styles/global.css";
import NavBar from "../components/NavBar.astro";

Astro.params.lang = getLanguageFromURL(Astro.url);
Astro.params.lang = "en";
const langs: string[] = getLanguages();

if(Astro.params.lang === undefined) {
Astro.params.lang = "en";
}
langs.forEach(intl => {
if(getLanguageFromURL(Astro.url) == intl) {
Astro.params.lang = intl;
}
});

const tr = useTranslations(Astro.params.lang as never);
---
Expand All @@ -24,10 +27,10 @@ const tr = useTranslations(Astro.params.lang as never);
<body>
<div class="center">
<div class="not-found">
<h1> { tr("not_found.title") } </h1>
<h1> { tr("404.title") } </h1>
<p>
{ tr("not_found.description.l1") } <br>
{ tr("not_found.description.l2") } <a href={ `/${Astro.params.lang}/#socials` }>{ tr("not_found.description.socials") }</a>
{ tr("404.description.l1") } <br>
{ tr("404.description.l2") } <a href={ `/${Astro.params.lang}/#socials` }>{ tr("404.socials") }</a>
</p>
</div>
</div>
Expand Down