-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
I have been trying to access our translations in our server responses: outside of the svelte store lifecycle. I have figured out that I can do something similar to this:
import { _, addMessages } from 'svelte-i18n';
import en from '../../../../i18n/en.json';
import ukr from '../../../../i18n/ukr.json';
addMessages('en', en);
addMessages('ukr', ukr);
let translate = (message: string, options: object) => 'translator not set up yet';
_.subscribe((f) => {
translate = f;
});
const translation = translate('app.page_not_found', { locale: 'ukr' });
console.log(translation);This gets the correct translations out of the provided files. I keep thinking there must be an easier way to do this, But I can't find anything in the documentation. It seems to me like the svelte-i18n api should expose a simple function to get a translation, if it has already been registered, outside of the store and front-end lifecycle. In our case we can get the locale from the database, the user's preferences, or read the cookies in the api response.
Am I missing something?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels