From fcf79cc248ccefbca855c19a038bc71d59f8a2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Manzano?= Date: Tue, 20 Jun 2023 18:37:16 +0200 Subject: [PATCH] i18n added language selector Added language selector and some translations. --- locales/en.yml | 25 +++++++++++++++++- locales/es.yml | 26 +++++++++++++++++++ src/components/ToolCard.vue | 4 ++- src/layouts/base.layout.vue | 22 ++++++++++++++++ src/layouts/tool.layout.vue | 3 ++- .../command-palette/command-palette.store.ts | 14 ++++++---- .../command-palette/command-palette.vue | 8 +++--- .../components/command-palette-option.vue | 3 ++- src/pages/Home.page.vue | 17 ++++++------ src/tools/xml-formatter/index.ts | 2 +- src/tools/xml-formatter/xml-formatter.vue | 14 +++++----- 11 files changed, 110 insertions(+), 28 deletions(-) create mode 100644 locales/es.yml diff --git a/locales/en.yml b/locales/en.yml index 4982dc53..0feb50b4 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -1,3 +1,26 @@ home: + commandPalette: + search: Search... + placeholder: Type to search a tool or a command... + commandPaletteStore: + actions: Actions + external: External + tools: Tools categories: - newestTools: "Newest tools" + newestTools: Newest tools + title: IT Tools - Handy online tools for developers + allTools: All the tools + favoriteTools: Your favorite tools + thanks: '! Thank you' + giveUsAStarOn: Give us a star on + orFollowUsOn: or follow us on + youLikeItTools: You like it-tools? +tools: + xmlFormat: + description: Prettify your XML string to a human friendly readable format. + indentSize: 'Indent size:' + collapseContent: 'Collapse content:' + providedXmlIsNotValid: Provided XML is not valid. + inputLabel: Your XML + outputLabel: Formatted XML from your XML + placeHolder: Paste your XML here... diff --git a/locales/es.yml b/locales/es.yml new file mode 100644 index 00000000..855d4f45 --- /dev/null +++ b/locales/es.yml @@ -0,0 +1,26 @@ +home: + commandPalette: + search: Buscar... + placeholder: Escribe para buscar una herramienta o comando... + commandPaletteStore: + actions: Acciones + external: Externa + tools: Herramientas + categories: + newestTools: Herramientas Nuevas + title: 'IT Tools - Prácticas herramientas en línea para desarrolladores.' + allTools: Todas las herramientas + favoriteTools: Tus herramientas favorias + thanks: '! Thank you' + giveUsAStarOn: Give us a star on + orFollowUsOn: or follow us on + youLikeItTools: You like it-tools? +tools: + xmlFormat: + description: Embellece tu XML a un formato XML más amigable. + indentSize: 'Tamaño de indentación:' + collapseContent: 'Colapsar contenido:' + providedXmlIsNotValid: El XML proporcionado no es válido. + inputLabel: Tu XML + outputLabel: XML Formateado desde tu XML + placeHolder: Pega tu XML aquí... diff --git a/src/components/ToolCard.vue b/src/components/ToolCard.vue index 00f22466..5ffeae96 100644 --- a/src/components/ToolCard.vue +++ b/src/components/ToolCard.vue @@ -8,6 +8,8 @@ const props = defineProps<{ tool: Tool & { category: string } }>(); const { tool } = toRefs(props); const theme = useThemeVars(); +const { t } = useI18n(); + const appTheme = useAppTheme(); @@ -38,7 +40,7 @@ const appTheme = useAppTheme();
- {{ tool.description }} + {{ t(tool.description) }}
 
diff --git a/src/layouts/base.layout.vue b/src/layouts/base.layout.vue index 36edd77d..a80505ff 100644 --- a/src/layouts/base.layout.vue +++ b/src/layouts/base.layout.vue @@ -7,6 +7,7 @@ import { Heart, Home2, Menu2 } from '@vicons/tabler'; import HeroGradient from '../assets/hero-gradient.svg?component'; import MenuLayout from '../components/MenuLayout.vue'; import NavbarButtons from '../components/NavbarButtons.vue'; +import { availableLocales, loadLanguageAsync } from '../plugins/i18n.plugin'; import { toolsByCategory } from '@/tools'; import { useStyleStore } from '@/stores/style.store'; import { config } from '@/config'; @@ -24,10 +25,19 @@ const { tracker } = useTracker(); const toolStore = useToolStore(); +const currentLang = useStorage('application:selected-language', 'en'); + +loadLanguageAsync(currentLang.value); + const tools = computed(() => [ ...(toolStore.favoriteTools.length > 0 ? [{ name: 'Your favorite tools', components: toolStore.favoriteTools }] : []), ...toolsByCategory, ]); + +function onChange(event: any) { + currentLang.value = event; + loadLanguageAsync(event); +}