Skip to content

Commit 0a31ed4

Browse files
committed
Fix 404 error when user access untranslated parts
1 parent 242f8a1 commit 0a31ed4

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
1. Prettify your code with `npm run format`
1313
2. Create a new branch for your changes
1414
3. Create the PR from that branch to the source branch
15+
16+
# Contributing with translations
17+
When translation of a whole new part is completed, remember to update the file src/utils/translationProgress.json

src/components/PartBanner/PartBanner.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import translationProgress from '../../utils/translationProgress'
12
import { Banner } from '../Banner/Banner';
23
import { ContentLiftup } from '../ContentLiftup/ContentLiftup';
34
import React from 'react';
@@ -74,16 +75,16 @@ const partNameTranslations = {
7475
'Introdução ao React',
7576
'Comunicação com o servidor',
7677
'Programando um servidor com NodeJS e Express',
77-
'Teste de servidores Express e Administração de Usuários (tradução em andamento)',
78-
'Teste de aplicações React (tradução em andamento)',
79-
'Gerenciamento de Estado com Redux (tradução em andamento)',
80-
'React router, hooks personalizados, estilização de aplicações com CSS e Webpack (tradução em andamento)',
81-
'GraphQL (tradução em andamento)',
82-
'TypeScript (tradução em andamento)',
83-
'React Native (tradução em andamento)',
84-
'CI/CD (tradução em andamento)',
85-
'Containers (tradução em andamento)',
86-
'Utilizando bancos de dados relacionais (tradução em andamento)',
78+
'Teste de servidores Express e Administração de Usuários',
79+
'Teste de aplicações React',
80+
'Gerenciamento de Estado com Redux',
81+
'React router, hooks personalizados, estilização de aplicações com CSS e Webpack',
82+
'GraphQL',
83+
'TypeScript',
84+
'React Native',
85+
'CI/CD',
86+
'Containers',
87+
'Utilizando bancos de dados relacionais',
8788
],
8889
};
8990

@@ -102,9 +103,10 @@ export const PartBanner = ({ lang }) => {
102103
>
103104
<div className="container spacing flex-fix-aligning col-7--mobile">
104105
{parts.map(part => {
105-
const partNames =
106-
partNameTranslations[lang] || partNameTranslations.en;
106+
const partNames =
107+
partNameTranslations[lang] || partNameTranslations.en
107108

109+
const summary = translationProgress[lang] < part ? partNames[part] + ' (english only)' : partNames[part]
108110
return (
109111
<ContentLiftup
110112
key={partNames[part]}
@@ -115,7 +117,7 @@ export const PartBanner = ({ lang }) => {
115117
}}
116118
hoverImageSrc={require(`../../images/thumbnails/part-${part}_ovr.svg`)}
117119
name={`${partName(lang)} ${part}`}
118-
summary={partNames[part]}
120+
summary={summary}
119121
path={getPartTranslationPath(lang, part)}
120122
/>
121123
);

src/components/PrevNext/PrevNext.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './PrevNext.scss';
22

3+
import translationProgress from '../../utils/translationProgress'
34
import Element from '../Element/Element';
45
import { Link } from 'gatsby';
56
import { PropTypes } from 'prop-types';
@@ -106,7 +107,9 @@ const PrevNext = ({ part, letter, lang }) => {
106107

107108
const getNext = () => {
108109
if (!letter && hasPart(part + 1, lang)) {
109-
console.log('a', hasPart(part + 1, lang))
110+
if (translationProgress[lang] <= part) {
111+
lang = 'en'
112+
}
110113
return (
111114
<Link
112115
to={`${langUrl(lang)}${part + 1}`}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import translationProgress from './translationProgress'
2+
13
const getPartTranslationPath = (language, part, path = '') => {
2-
// while the ptbr translation are not complete, return the URL for english version
3-
if (language === 'ptbr' && part >= 4) {
4-
// parts 0-3 are done. For part 4 onward, this will return the english version
4+
// while the translation are not complete, return the URL for english version
5+
if (translationProgress[language] < part) {
56
return `/en/part${part}${path}`
67
}
7-
return language === 'fi' ? `/osa${part}${path}` : `/${language}/part${part}${path}`;
8-
};
8+
return language === 'fi' ? `/osa${part}${path}` : `/${language}/part${part}${path}`
9+
}
910

10-
export default getPartTranslationPath;
11+
export default getPartTranslationPath

src/utils/translationProgress.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"en": 13,
3+
"es": 10,
4+
"fi": 13,
5+
"fr": 3,
6+
"ptbr": 3,
7+
"zh": 13
8+
}

0 commit comments

Comments
 (0)