File tree Expand file tree Collapse file tree 12 files changed +146
-59
lines changed Expand file tree Collapse file tree 12 files changed +146
-59
lines changed Original file line number Diff line number Diff line change 1
1
---
2
+ import { useTranslations } from " ../i18n/utils.ts" ;
2
3
import " ../styles/global.css" ;
3
4
4
- var options = {
5
- Home: " Home" ,
6
- About: " About Me" ,
7
- Projects: " Projects"
8
- };
5
+ const tr = useTranslations (Astro .params .lang as never );
9
6
---
10
7
11
- <script >
12
- console.log(Astro.currentLocale);
13
- </script >
14
-
15
8
<header >
16
9
<div class =" nav-left" >
17
10
<a rel =" author" href =" https://github.com/retrozinndev" >
@@ -21,13 +14,13 @@ var options = {
21
14
<nav class =" navbar" >
22
15
<ul class =" links" >
23
16
<li class =" link" >
24
- <a href =" /#top" target =" _self" >{ options . Home } </a >
17
+ <a href =" /#top" target =" _self" >{ tr ( " nav.home " ) } </a >
25
18
</li >
26
19
<li class =" link" >
27
- <a href =" /#chars" target =" _self" >{ options . About } </a >
20
+ <a href =" /#chars" target =" _self" >{ tr ( " nav.about " ) } </a >
28
21
</li >
29
22
<li class =" link" >
30
- <a href =" /projects" target =" _self" >{ options . Projects } </a >
23
+ <a href =" /projects" target =" _self" >{ tr ( " nav.projects " ) } </a >
31
24
</li >
32
25
</ul >
33
26
</nav >
Original file line number Diff line number Diff line change
1
+ /// <reference path="../.astro/types.d.ts" />
1
2
/// <reference types="astro/client" />
Original file line number Diff line number Diff line change
1
+ export const en = {
2
+
3
+ nav : {
4
+ home : "Home" ,
5
+ about : "About" ,
6
+ projects : "Projects"
7
+ } ,
8
+
9
+ about : {
10
+ title : "Hi, I'm" ,
11
+ description : `I'm a self-taught programmer and tech enthusiast who's learning software
12
+ development stuff! I absolutely love making open-source projects! I like: coding,
13
+ learning about Linux and making games and apps in my free time!` ,
14
+ socials_title : "You can find me in:" ,
15
+ projects : "Get in touch with my projects"
16
+ } ,
17
+
18
+ not_found : {
19
+ title : "404 - Not found!" ,
20
+ description : `Looks like I haven't developed this yet!
21
+ Feel free to suggest me anything, talk to me on any of` ,
22
+ social_link : "my socials!"
23
+ }
24
+ } as const ;
Original file line number Diff line number Diff line change
1
+ export const pt = {
2
+
3
+ nav : {
4
+ home : "Início" ,
5
+ about : "Sobre mim" ,
6
+ projects : "Projetos"
7
+ } ,
8
+
9
+ about : {
10
+ title : "Olá, sou o" ,
11
+ description : `Sou um programador autodidata e entusiasta de tecnologia que está amando o
12
+ mundo da programação! Eu gosto muito de fazer projetos open-source! Eu curto: programar,
13
+ aprender sobre GNU/Linux, fazer jogos e aplicativos no meu tempo livre!` ,
14
+ socials_title : "Você pode me encontrar em:" ,
15
+ projects : "Veja os meus projetos"
16
+ } ,
17
+
18
+ not_found : {
19
+ title : "404 - Não encontrado!" ,
20
+ description : `Parece que eu ainda não desenvolvi essa página!
21
+ Feel free to suggest me anything, talk to me on any of` ,
22
+ social_link : "minhas redes sociais!"
23
+ }
24
+ } as const ;
Original file line number Diff line number Diff line change
1
+
2
+ import { languages } from "./ui" ;
3
+
4
+ export const getStaticPaths = ( ) =>
5
+ languages . map ( lang => ( { params : { lang } } ) ) ;
Original file line number Diff line number Diff line change
1
+
2
+ import { en } from "./en.ts" ;
3
+ import { pt } from "./pt.ts" ;
4
+
5
+ export let i18n : object = {
6
+ en : {
7
+ ...en
8
+ } ,
9
+ pt : {
10
+ ...pt
11
+ }
12
+ } ;
13
+
14
+ export const languages : Array < string > = Object . keys ( i18n ) ;
15
+ export const defaultLang = "en" as keyof typeof i18n ;
16
+
17
+ console . log ( languages ) ;
Original file line number Diff line number Diff line change
1
+
2
+ import { i18n , defaultLang } from "./ui.ts" ;
3
+
4
+ export function getLanguageFromURL ( url : URL ) : string {
5
+ var splittedURL = url . pathname . split ( "/" ) ;
6
+ var currentIntl = splittedURL [ 1 ] ; // Gets the second URL part
7
+ var domain = splittedURL [ 0 ] . replace ( "/" , "" ) ;
8
+
9
+ if ( currentIntl in i18n )
10
+ return currentIntl as keyof typeof i18n ;
11
+
12
+ return currentIntl as string ;
13
+ }
14
+
15
+ export function useTranslations ( lang : keyof typeof i18n ) : Function {
16
+ return function tr ( key : string ) : string {
17
+ const keys = key . split ( "." ) ;
18
+ let translation = i18n [ lang ] , defaultTranslation = i18n [ defaultLang ] ;
19
+
20
+ keys . forEach ( key => {
21
+ translation = translation [ key ] ;
22
+ defaultTranslation = defaultTranslation [ key ] ;
23
+ } ) ;
24
+
25
+ return translation || defaultTranslation || "Couldn't find key to translate." ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 1
1
---
2
+
2
3
import " ../styles/global.css" ;
3
4
import NavBar from " ../components/NavBar.astro" ;
4
- import PageLayout from " ../layouts/PageLayout.astro" ;
5
5
---
6
6
7
+ <!DOCTYPE html >
8
+ <html lang =" en" >
9
+ <head >
10
+ <meta charset =" UTF-8" >
11
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" >
12
+ <title >retrozinndev - Not Found!</title >
13
+ <link rel =" icon" href =" https://github.com/retrozinndev.png" />
14
+ </head >
7
15
<NavBar />
8
- <PageLayout title = " retrozinndev | Not Found " icon = " https://github.com/retrozinndev.png " lang = " en-US " >
16
+ <body >
9
17
<div class =" center" >
10
18
<div class =" not-found" >
11
- <h1 >404!</h1 >
19
+ <h1 > 404! </h1 >
12
20
<p >
13
- Looks like I didn 't developed this yet!<br >
21
+ Looks like I haven 't developed this yet!<br >
14
22
Feel free to suggest me anything, talk to me on any of <a href =" /#socials" >my socials!</a >
15
23
</p >
16
24
</div >
17
25
</div >
18
- </PageLayout >
26
+ <body >
27
+
28
+ </body >
29
+ </html >
19
30
20
31
<style >
21
32
.not-found h1 {
Original file line number Diff line number Diff line change 1
1
---
2
+ import { getStaticPaths } from " ../../i18n/route.ts" ;
3
+ import { useTranslations } from " ../../i18n/utils.ts" ;
2
4
import SocialLinks from ' ../../components/SocialLinks.astro' ;
3
5
import PageLayout from ' ../../layouts/PageLayout.astro' ;
4
6
import " ../../styles/about_page.css" ;
7
+
8
+ export { getStaticPaths };
9
+ const tr = useTranslations (Astro .params .lang as never );
5
10
---
6
11
7
12
<PageLayout title ={ " retrozinndev" + " | " + " Home" } icon =" https://github.com/retrozinndev.png" lang =" en-US" >
8
13
<body >
9
14
<div class =" container" >
10
15
<div class =" about-section title" >
11
- <h1 >Hi, I'm <span class =" highlight" >João!</span ></h1 >
16
+ <h1 >{ tr ( " about.title " ) } <span class =" highlight" >João!</span > </h1 >
12
17
</div >
13
18
<div class =" about" id =" about" >
14
- I'm a self-taught programmer and tech enthusiast that's learning software development stuff! <br >
15
- I absolutely love making open-source projects! <br >
16
- I like: coding, learning about Linux and making games and apps in my free time! <br >
19
+ { tr (" about.description" ) }
17
20
</div >
18
- <a href =" /projects" ><h3 class =" projects" id =" projects" >Get in touch with my projects ↗ </h3 ></a >
21
+ <a href =" /projects" ><h3 class =" projects" id =" projects" >{ tr ( " about. projects" ) } ↗ </h3 ></a >
19
22
<div class =" socials ul" id =" socials" >
20
- <h2 >You can find me in: </h2 >
23
+ <h2 >{ tr ( " about.socials_title " ) } </h2 >
21
24
<SocialLinks />
22
25
</div >
23
26
</div >
You can’t perform that action at this time.
0 commit comments