Parsers

A monorepo including sveltekit-i18n message parsers. These parsers are ment be used together with @sveltekit-i18n/base, but can be used with other libraries as well – they don't require Svelte or SvelteKit.

Creating custom parsers

Every parser is a method consuming a config and returning an object containing parse method:

const customParser = (customParserConfig = {}) => ({
  parse: () => '',
});

parse: Parser.Parse

Parse method deals with interpolation of user payload and returns a string.

It consumes these parameters:

value: any – translation value from definitions
params: any[] – array of rest parameters given by user (e.g. payload variables etc...)
locale: string – locale of translated message
key: string – this key is serialized path to translation (e.g., home.content.title)

Example:

const parse = (value, params, locale, key) => {
  const fallbackValue = `${key} (${locale})`;

  return interpolate(value, ...params) || fallbackValue;
}

Issues

If you are facing issues with some parser, create a ticket here.

Top categories

Loading Svelte Themes