Commit 862a5f9c authored by Ben Beltran's avatar Ben Beltran

Add internationalization support

parent 7372fe18
<script>
import { _ } from 'svelte-i18n';
export let message = $_('error.generic.message');
export let message;
</script>
<div>
<h2>{$_('error.generic.title')}</h2>
<p>{message}</p>
<p>{message || $_('error.generic.message')}</p>
</div>
<style>
......
<script>
import { _ } from 'svelte-i18n';
import LanguageSelector from '../language_selector/language_selector.svelte';
const licenseUrl = 'https://gitlab.com/rbdr/forum/';
</script>
<footer title="Toolbar">
<ul>
<li>{@html $_('footer.license', { values: { licenseUrl } })}</li>
<li>{$_('footer.choose_language')}: <LanguageSelector /></li>
</ul>
</footer>
<style>
footer {
grid-column: col-start 1 / span 12;
border-top: 1px solid black;
}
ul {
padding: 0;
}
.action-key {
font-weight: bold;
text-decoration: underline;
}
li {
display: inline;
margin: 5px;
}
a {
text-decoration: none;
line-height: 3em;
display: inline-block;
}
strong a {
color: blue;
text-decoration: underline;
}
</style>
......@@ -13,7 +13,7 @@
<li>
<a href="/f/{forum.id}">
<span aria-hidden="true" class="navigation-glyph {forum.glyph}">{forum.glyph}</span>
<span class="navigation-label">{forum.label}</span>
<span class="navigation-label">{$_(forum.label)}</span>
</a>
</li>
{/each}
......
<script>
import { locale, locales } from 'svelte-i18n';
import { getLangNameFromCode } from 'language-name-map';
$: namedLocales = $locales
.map((locale) => ({
code: locale,
...getLangNameFromCode(locale)
}))
.sort((a, b) => a.native - b.native);
let selected = $locale;
$: {
console.log(`the current locale is ${selected}`);
locale.set(selected);
}
</script>
<select bind:value={selected}>
{#each namedLocales as namedLocale}
<option value="{ namedLocale.code }">{ namedLocale.native }</option>
{/each}
</select>
<style>
</style>
import { addMessages, getLocaleFromNavigator, init } from 'svelte-i18n';
import en from './translations/en.json';
import es from './translations/es.json';
addMessages('en', en);
addMessages('es', es);
init({
fallbackLocale: 'en',
......
......@@ -5,9 +5,30 @@
"message": "Unknown error has occurred. Panic!"
}
},
"footer": {
"choose_language": "Choose your language",
"license": "Forum is <a href=\"{licenseUrl}\">open source.</a>"
},
"forum_list": {
"error": {
"unavailable": "Forum list unavailable."
}
},
"forum": {
"name": {
"everything": "Everything",
"us": "Us",
"words": "Words",
"sound": "Sounds",
"structure": "Structure",
"interaction": "Interaction",
"emotion": "Emotion",
"movement": "Movement",
"belief": "Belief",
"experience": "Experience",
"online": "Online",
"the_world": "The World",
"life": "Life"
}
}
}
{
"error": {
"generic": {
"title": "Error!",
"message": "Hubo un error desconocido. Entra en pánico!"
}
},
"footer": {
"choose_language": "Escoge un lenguaje",
"license": "Forum es <a href=\"{licenseUrl}\">software libre.</a>"
},
"forum_list": {
"error": {
"unavailable": "Lista de foros no disponible."
}
},
"forum": {
"name": {
"everything": "Todo",
"us": "Nosotros",
"words": "Palabras",
"sound": "Sonidos",
"structure": "Estructura",
"interaction": "Interacción",
"emotion": "Emoción",
"movement": "Movimiento",
"belief": "Creencia",
"experience": "Experiencia",
"online": "En Línea",
"the_world": "El Mundo",
"life": "Vida"
}
}
}
......@@ -9,6 +9,7 @@
import ForumList from './components/forum_list/forum_list.svelte';
import Header from './components/header/header.svelte';
import Footer from './components/footer/footer.svelte';
// Routed Components
import Author from './components/author/author.svelte';
......@@ -53,6 +54,7 @@
<svelte:component this={ page } params={ params } />
</main>
<ForumList />
<Footer />
<style>
main {
......
......@@ -2308,24 +2308,6 @@
"typedarray": "^0.0.6"
}
},
"config": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/config/-/config-3.3.1.tgz",
"integrity": "sha512-+2/KaaaAzdwUBE3jgZON11L1ggLLhpf2FsGrfqYFHZW22ySGv/HqYIXrBwKKvn+XZh1UBUjHwAcrfsSkSygT+Q==",
"requires": {
"json5": "^2.1.1"
},
"dependencies": {
"json5": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz",
"integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==",
"requires": {
"minimist": "^1.2.5"
}
}
}
},
"console-browserify": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz",
......@@ -4816,6 +4798,11 @@
"integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==",
"dev": true
},
"language-name-map": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/language-name-map/-/language-name-map-0.3.0.tgz",
"integrity": "sha512-uoBHtfY6h4S2RoIpyqvQGhynX2hshQu/9S4ySbppGxG5VwEsiWZJ83xSjzx25Mb+Bmc+WxpQC0H54eNZVMWLuA=="
},
"leven": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz",
......@@ -5071,7 +5058,8 @@
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"dev": true
},
"mixin-deep": {
"version": "1.3.2",
......
......@@ -22,6 +22,7 @@
},
"dependencies": {
"eventemitter3": "^4.0.4",
"language-name-map": "^0.3.0",
"lightrouter": "^0.3.3"
},
"devDependencies": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment