kaisermann / svelte-i18n

Internationalization library for Svelte
MIT License
1.24k stars 79 forks source link

a way to display translation keys instead of translation values #212

Open attisimon opened 1 year ago

attisimon commented 1 year ago

Hello!

I was wondering if there would be a way to display the translation keys instead of the translation values, exactly the same way as a language/locale selector works for changing the language on page. This would help to see where a particular translation key is in context, making it easier for translators to understand the context and make a translation that fits.

Thanks!

Note: if the fallbackLocale is set to empty string at init, later on setting a locale that does not exist will make the keys to be displayed on page. This is not ideal for production, but it can be a starting point for a better solution.

import { browser } from '$app/environment'
import { init } from 'svelte-i18n';

init({
  fallbackLocale: '',
  initialLocale: browser ? window.navigator.language : defaultLocale
});

This could also be combined with import.meta.env.MODE, if using Vite, but that is not ideal either, even if it works to differentiate between production and other environments.

laszlo1337 commented 1 year ago

I second that. Would be a great debug tool.