Skip to content

Commit

Permalink
Add translation to error page
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed May 31, 2020
1 parent 80b20ee commit 25d44b6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 46 deletions.
41 changes: 21 additions & 20 deletions messages/ar.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"title": {
"index": "Sapper project template!"
},
"nav": {
"home": "الرئيسية",
"about": "من نحن",
"blog": "اتصل بنا"
},
"messages": {
"success": "عظيم",
"high_five": "خمسة",
"try_editing": "حاول تحرير هذا الملف (src/routes/index.svelte) لاختبار إعادة التحميل المباشر."
},
"languages": {
"en": "English",
"pt_BR": "Português",
"es_ES": "Espanol",
"ar": "عربى"
},
"direction": "rtl"
"title": {
"index": "Sapper project template!"
},
"nav": {
"home": "الرئيسية",
"about": "من نحن",
"blog": "اتصل بنا"
},
"messages": {
"error": "خطأ: {status}",
"success": "عظيم",
"high_five": "خمسة",
"try_editing": "حاول تحرير هذا الملف (src/routes/index.svelte) لاختبار إعادة التحميل المباشر."
},
"languages": {
"en": "English",
"pt_BR": "Português",
"es_ES": "Espanol",
"ar": "عربى"
},
"direction": "rtl"
}
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"blog": "Blog"
},
"messages": {
"error": "Error: {status}",
"success": "Great success!",
"high_five": "High five",
"try_editing": "Try editing this file (src/routes/index.svelte) to test live reloading."
Expand Down
1 change: 1 addition & 0 deletions messages/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"blog": "Blog"
},
"messages": {
"error": "Error: {status}",
"success": "Gran éxito!",
"high_five": "Cinco altos",
"try_editing": " Intente editar este archivo (src/routes/index.svelte) para probar la recarga en vivo."
Expand Down
41 changes: 21 additions & 20 deletions messages/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"title": {
"index": "Modelo de projeto em Sapper!"
},
"nav": {
"home": "Home",
"about": "Sobre",
"blog": "Blog"
},
"messages": {
"success": "Suuuucesso!",
"high_five": "Toca aqui",
"try_editing": "Tente editar este arquivo (src/routes/index.svelte) para testar o recarregamento ao vivo."
},
"languages": {
"en": "English",
"pt_BR": "Português",
"es_ES": "Espanol",
"ar": "عربى"
},
"direction": "ltr"
"title": {
"index": "Modelo de projeto em Sapper!"
},
"nav": {
"home": "Home",
"about": "Sobre",
"blog": "Blog"
},
"messages": {
"error": "Error: {status}",
"success": "Suuuucesso!",
"high_five": "Toca aqui",
"try_editing": "Tente editar este arquivo (src/routes/index.svelte) para testar o recarregamento ao vivo."
},
"languages": {
"en": "English",
"pt_BR": "Português",
"es_ES": "Espanol",
"ar": "عربى"
},
"direction": "ltr"
}
10 changes: 5 additions & 5 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ export function i18nMiddleware() {
return;
}

let lang = getCookie('locale', req.headers.cookie);
let locale = getCookie('locale', req.headers.cookie);

// no cookie, let's get the first accepted language
if (lang == null) {
if (locale == null) {
const headerLang = req.headers['accept-language'].split(',')[0].trim();
if (headerLang.length > 1) {
lang = headerLang;
locale = headerLang;
}
}

if (lang != null && lang !== currentLocale) {
$locale.set(lang);
if (locale != null && locale !== currentLocale) {
$locale.set(locale);
}

next();
Expand Down
6 changes: 5 additions & 1 deletion src/routes/_error.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<script>
import { _ } from 'svelte-i18n';
export let status;
export let error;
const dev = process.env.NODE_ENV === 'development';
</script>

<style>
h1, p {
h1,
p {
margin: 0 auto;
}
Expand All @@ -32,6 +35,7 @@
</svelte:head>

<h1>{status}</h1>
<h1>{$_('messages.error', { values: { status } })}</h1>

<p>{error.message}</p>

Expand Down

0 comments on commit 25d44b6

Please sign in to comment.