From 7750e96ccd5a2840ebe82ced7d202a529d828c3c Mon Sep 17 00:00:00 2001 From: Roberto Simonetti Date: Wed, 31 Aug 2022 12:57:20 +0200 Subject: [PATCH] App: remove endpoint --- README.md | 4 +- .../routes/i18n/[lang]/[asset].json/index.ts | 60 ------------------- src/library/qwik-speak.tsx | 2 +- src/library/speak.tsx | 2 +- 4 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 src/app/routes/i18n/[lang]/[asset].json/index.ts diff --git a/README.md b/README.md index c62ca85..d8356f7 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ export const config: SpeakConfig = { ] }; ``` -Assets will be loaded through the implementation of `getTranslation$` function below. You can call an _endpoint_, or load _json_ files to return a `Translation` object for each language: +Assets will be loaded through the implementation of `getTranslation$` function below. You can load _json_ files or call an _endpoint_ to return a `Translation` object for each language: ```json { "app": { @@ -98,7 +98,7 @@ Assets will be loaded through the implementation of `getTranslation$` function b } } ``` -Then add the `QwikSpeak` component in `root.tsx`: +Add the `QwikSpeak` component in `root.tsx`: ```jsx import { QwikSpeak } from 'qwik-speak'; diff --git a/src/app/routes/i18n/[lang]/[asset].json/index.ts b/src/app/routes/i18n/[lang]/[asset].json/index.ts deleted file mode 100644 index a532442..0000000 --- a/src/app/routes/i18n/[lang]/[asset].json/index.ts +++ /dev/null @@ -1,60 +0,0 @@ -import type { RequestHandler } from '@builder.io/qwik-city'; -import { Translation } from '../../../../../library/types'; - -// E.g. Endpoint to get translation data -export const onGet: RequestHandler = ({ params }) => { - return { [params.asset]: i18n[params.lang][params.asset] }; -}; - -export const i18n: Translation = { - 'en-US': { - 'app': { - 'title': 'Qwik Speak', - 'subtitle': 'Translate your Qwik apps into any language', - 'changeLocale': 'Change locale', - 'nav': { - 'home': 'Home', - 'page': 'Page' - }, - 'home': { - 'title': '{{name}}', - 'description': 'Internationalization (i18n) library to translate texts, dates and numbers in Qwik apps' - }, - 'page': { - 'title': 'Page - {{name}}', - 'description': "I'm another page" - } - }, - 'home': { - 'greeting': 'Hi! I am {{name}}', - 'text': 'Internationalization (i18n) library to translate texts, dates and numbers in Qwik apps' - }, - 'page': { - 'text': "I'm a fallback text" - } - }, - 'it-IT': { - 'app': { - 'title': 'Qwik Speak', - 'subtitle': 'Traduci le tue app Qwik in qualsiasi lingua', - 'changeLocale': 'Cambia località', - 'nav': { - 'home': 'Home', - 'page': 'Pagina' - }, - 'home': { - 'title': '{{name}}', - 'description': 'Libreria di internazionalizzazione (i18n) per tradurre testi, date e numeri nelle app Qwik' - }, - 'page': { - 'title': 'Pagina - {{name}}', - 'description': "Io sono un'altra pagina" - } - }, - 'home': { - 'greeting': 'Ciao! Sono {{name}}', - 'text': 'Libreria di internazionalizzazione (i18n) per tradurre testi, date e numeri nelle app Qwik' - }, - 'page': {} - } -}; diff --git a/src/library/qwik-speak.tsx b/src/library/qwik-speak.tsx index 32c2e46..996908e 100644 --- a/src/library/qwik-speak.tsx +++ b/src/library/qwik-speak.tsx @@ -74,7 +74,7 @@ export const QwikSpeak = component$((props: QwikSpeakProps) => { Object.assign(translation, loadedTranslation); if (speakDev) { - console.debug('Qwik Speak', '', `Translation loaded - ${JSON.stringify(config.assets)} - ${lang}`); + console.debug('Qwik Speak', '', `Translation loaded - ${config.assets} - ${lang}`); } } diff --git a/src/library/speak.tsx b/src/library/speak.tsx index 6d6fe6a..094e6d6 100644 --- a/src/library/speak.tsx +++ b/src/library/speak.tsx @@ -38,7 +38,7 @@ export const Speak = component$((props: SpeakProps) => { Object.assign(translation[lang], loadedTranslation[lang]); if (speakDev) { - console.debug('Qwik Speak', '', `Translation loaded - ${JSON.stringify(props.assets)} - ${lang}`); + console.debug('Qwik Speak', '', `Translation loaded - ${props.assets} - ${lang}`); } }