feat: i18n for the home page

This commit is contained in:
Adrien Marquès 2022-10-11 13:08:52 +02:00
parent f074720d0f
commit 0cebaf2e62
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
4 changed files with 58 additions and 27 deletions

View File

@ -19,12 +19,12 @@
<div class='separator'></div>
<section class='readme'>
<section class='readme' ref='test'>
<div class='header'>README.md</div>
<p ref='text1'>Hi, I am another freelance developer !</p>
<p ref='text2'>I made this website so you can <u>browse</u> some of my skills and projects.</p>
<p ref='text3'>After 50+ projects since I started IT back in 2010, I still work hard for making projects maintainable so they last and can evolve.</p>
<p ref='text4'>For now, my technologies of choice are : <u>Go</u> and <u>IoT</u> (Arduino, Raspberry).</p>
<p ref='text1'>{{ $t('home.line1') }}</p>
<p ref='text2'>{{ $t('home.line2-1') }} <u>{{ $t('home.line2-2') }}</u> {{$t('home.line2-3') }}</p>
<p ref='text3'>{{ $t('home.line3') }}</p>
<p ref='text4'>{{ $t('home.line4-1') }} <u>Go</u> {{ $t('home.line4-2') }} <u>IoT</u> {{ $t('home.line4-3') }}</p>
</section>
<div class='scroll-arrow' @click='scrollNext()'>
@ -66,6 +66,10 @@ export default class Home extends Vue {
// skip animation if already done less than 10min ago
if ( diff_sec < threshold ) {
(this.$refs.text2 as HTMLElement).style.display = 'block';
(this.$refs.text3 as HTMLElement).style.display = 'block';
(this.$refs.text4 as HTMLElement).style.display = 'block';
(this.$refs.text1 as HTMLElement).style.display = 'block';
return;
}
@ -74,24 +78,29 @@ export default class Home extends Vue {
const t3 = new TypeWriter( this.$refs.text3 as HTMLElement );
const t4 = new TypeWriter( this.$refs.text4 as HTMLElement );
t1.init(false);
t2.init();
t3.init();
t4.init();
// wait 1s, anim 1.5s
setTimeout( () => t1.animate(1500), 1000 );
// wait 3s, anim 2s
setTimeout( () => t2.animate(2000), 3000 );
// wait 6s, anim 4s
setTimeout( () => t3.animate(4000), 6000 );
// wait 10s, anim 3s
setTimeout( () => t4.animate(3000), 10000 );
// wait for i18n to change text
setTimeout(() => {
t1.init(false);
t2.init();
t3.init();
t4.init();
// wait 1s, anim 1.5s
setTimeout( () => t1.animate(1500), 1000 );
// wait 3s, anim 2s
setTimeout( () => t2.animate(2000), 3000 );
// wait 6s, anim 4s
setTimeout( () => t3.animate(4000), 6000 );
// wait 10s, anim 3s
setTimeout( () => t4.animate(3000), 10000 );
// local storage: store that we animated once
setTimeout( () => {
localStorage.setItem('typed', `${new Date().getTime()}`);
}, 13000 );
}, 100)
// local storage: store that we animated once
setTimeout( () => {
localStorage.setItem('typed', `${new Date().getTime()}`);
}, 13000 );
}
}
</script>
@ -189,6 +198,7 @@ export default class Home extends Vue {
width: auto;
max-width: 80rem;
height: auto;
min-height: 6rem;
margin: 0 5em;
margin-left: calc( 5em - #{$logo-size}/2 );
@ -216,6 +226,9 @@ export default class Home extends Vue {
}
p {
// typewriter animation changes it
display: none;
color: #fff;
margin: 1em;
line-height: 1.5em;

View File

@ -1,3 +1,13 @@
{
"home.title": "FREELANCE DEVELOPER"
"home.title": "FREELANCE DEVELOPER",
"home.line1": "Hi, I am another freelance developer !",
"home.line2-1": "I made this website so you can",
"home.line2-2": "browse",
"home.line2-3": "some of my skills and projects.",
"home.line3": "After 50+ projects since I started IT back in 2010, I still work hard for making projects maintainable so they last and can evolve.",
"home.line4-1": "For now, my technologies of choice are : ",
"home.line4-2": "and",
"home.line4-3": "(Arduino, Raspberry).",
"end": ""
}

View File

@ -1,3 +1,13 @@
{
"home.title": "DÉVELOPPEUR FREELANCE"
"home.title": "DÉVELOPPEUR FREELANCE",
"home.line1": "Hello, je suis un développeur freelance de plus !",
"home.line2-1": "J'ai mis en place ce site afin de pouvoir",
"home.line2-2": "parcourir",
"home.line2-3": "certaines de mes compétences et projets.",
"home.line3": "Avec 50+ projets depuis que j'ai démarré le dev en 2010, je suis toujours très attentif à rendre les projets maintenables afin qu'ils durent et puissent évoluer.",
"home.line4-1": "Pour le moment, les technologies qui m'intéressent sont : le",
"home.line4-2": "et l'",
"home.line4-3": "(Arduino, Raspberry).",
"end": ""
}

View File

@ -1,6 +1,5 @@
export class TypeWriter {
private target: HTMLElement;
private display: string|null = null;
private html: string|null = null;
constructor(target: HTMLElement) {
@ -10,7 +9,6 @@ export class TypeWriter {
/* initialize with copying and clearing the original text */
public init(hide: boolean = true) {
this.html = this.target.innerHTML;
this.display = this.target.style.display;
this.target.innerHTML = '';
if ( hide ) {
this.target.style.display = 'none';
@ -18,7 +16,7 @@ export class TypeWriter {
}
public animate(msDuration: number) {
if ( this.html == null || this.display == null ) {
if ( this.html == null ) {
console.warn('[typewriter] init must be called first ; doing it anyway');
this.init();
}
@ -26,7 +24,7 @@ export class TypeWriter {
const size = this.html!.length;
const msLetter = msDuration / size;
this.target.style.display = this.display!;
this.target.style.display = 'block';
for ( let i = 0, l = this.html!.length ; i < l ; i++ ) {
setTimeout(
() => {