-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from pvdthings/main
Spanish lang support and other improvements
- Loading branch information
Showing
9 changed files
with
117 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Code unapologetically copied from: https://dev.to/danawoodman/svelte-quick-tip-adding-basic-internationalization-i18n-to-you-app-2lm | ||
|
||
import { derived, writable } from "svelte/store"; | ||
import translations from "./translations"; | ||
|
||
export const locale = writable("en"); | ||
export const locales = Object.keys(translations); | ||
|
||
function translate(locale, key, vars) { | ||
// Let's throw some errors if we're trying to use keys/locales that don't exist. | ||
// We could improve this by using Typescript and/or fallback values. | ||
if (!key) throw new Error("no key provided to $t()"); | ||
if (!locale) throw new Error(`no translation for key "${key}"`); | ||
|
||
// Grab the translation from the translations object. | ||
let text = translations[locale][key]; | ||
|
||
if (!text) throw new Error(`no translation found for ${locale}.${key}`); | ||
|
||
// Replace any passed in variables in the translation string. | ||
Object.keys(vars).map((k) => { | ||
const regex = new RegExp(`{{${k}}}`, "g"); | ||
text = text.replace(regex, vars[k]); | ||
}); | ||
|
||
return text; | ||
} | ||
|
||
export const t = derived(locale, ($locale) => (key, vars = {}) => | ||
translate($locale, key, vars) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export default { | ||
en: { | ||
"Button.Home": "Home", | ||
"Button.Donate": "Donate", | ||
"Button.WishList": "Wish List", | ||
"Chooser.CategoryPrompt": "Choose a category:", | ||
"Input.Search": "Search...", | ||
"Thing.Tags.Available": "Available", | ||
"A project by": "A project by", | ||
"No Results": "No Results" | ||
}, | ||
es: { | ||
"Button.Home": "Inicio", | ||
"Button.Donate": "Donar", | ||
"Button.WishList": "Donaciones", | ||
"Chooser.CategoryPrompt": "Elija una categoría:", | ||
"Input.Search": "Buscar...", | ||
"Thing.Tags.Available": "Disponible", | ||
"A project by": "Un proyecto de", | ||
"No Results": "No hay resultados", | ||
"All": "Todas", | ||
"DIY": "Bricolaje", | ||
"Media": "Media", | ||
"Games": "Juegos", | ||
"Outdoors": "Aire libre", | ||
"Sports": "Deportes", | ||
"Entertainment": "Diversión", | ||
"Yard": "Patio", | ||
"Cleaning": "Limpia", | ||
"Cooking": "Cocina", | ||
"Crafts": "Artesanía", | ||
"Pet": "Mascotas", | ||
"Automotive": "Automotor", | ||
"Health": "Salud" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters