]> git.r.bdr.sh - rbdr/forum/commitdiff
Add internationalization support
authorBen Beltran <redacted>
Sat, 20 Jun 2020 14:20:31 +0000 (16:20 +0200)
committerBen Beltran <redacted>
Sat, 20 Jun 2020 14:20:31 +0000 (16:20 +0200)
app/components/error_block/error_block.svelte
app/components/footer/footer.svelte [new file with mode: 0644]
app/components/forum_list/forum_list.svelte
app/components/language_selector/language_selector.svelte [new file with mode: 0644]
app/config/i18n.js
app/config/translations/en.json
app/config/translations/es.json [new file with mode: 0644]
app/forum.svelte
package-lock.json
package.json

index d649fb46d31dc605b03b8f5b7b15fcdd7f2636dc..e46afa1400eab3a8cfed2029b451771b6996987b 100644 (file)
@@ -1,11 +1,11 @@
 <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>
diff --git a/app/components/footer/footer.svelte b/app/components/footer/footer.svelte
new file mode 100644 (file)
index 0000000..2d45cef
--- /dev/null
@@ -0,0 +1,47 @@
+<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>
index c218bac81b214473ea92b706e311a77b565ab1d8..5ce4dc119a6af374b0b73f9b31f9a0a1c90db749 100644 (file)
@@ -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}
diff --git a/app/components/language_selector/language_selector.svelte b/app/components/language_selector/language_selector.svelte
new file mode 100644 (file)
index 0000000..67c0814
--- /dev/null
@@ -0,0 +1,28 @@
+<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>
+
index e00adb5a0998064455e61a9b8a1a5f074588522b..25ffc45ec774673c8a620615059353c6d6b31983 100644 (file)
@@ -1,8 +1,10 @@
 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',
index 935f4fe32d5f4b363a7ad7b5a2df9902c38c43cb..468bdc15dcf3062e4b9867a9c48f9a7ed32680b4 100644 (file)
@@ -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"
+    }
   }
 }
diff --git a/app/config/translations/es.json b/app/config/translations/es.json
new file mode 100644 (file)
index 0000000..8831d2a
--- /dev/null
@@ -0,0 +1,34 @@
+{
+  "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"
+    }
+  }
+}
index d83438d9766056c9e893100735dccc2331a0edd0..d2a6e1bc07dd7bb06b6eb46eb43f57fece1cf81c 100644 (file)
@@ -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 {
index 1219a26637099fd7ca1c5017cf5941a1a12e922a..b0240a7a3397946eacb37a346e0491adb81e3908 100644 (file)
         "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",
       "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",
     "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",
index acc166e756dce08b59ab1c7936da59306eb711c7..d49dc7497596268309c6764044cf83a28aedec74 100644 (file)
@@ -22,6 +22,7 @@
   },
   "dependencies": {
     "eventemitter3": "^4.0.4",
+    "language-name-map": "^0.3.0",
     "lightrouter": "^0.3.3"
   },
   "devDependencies": {