Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single translation file per language #53

Closed
EskelCz opened this issue Apr 6, 2022 · 2 comments
Closed

Single translation file per language #53

EskelCz opened this issue Apr 6, 2022 · 2 comments

Comments

@EskelCz
Copy link

EskelCz commented Apr 6, 2022

Thanks for the library.

Is it possible to have just one file per language? I have just a few texts per page and it doesn't make much sense to have then separate files. I'd like to use a js file instead of json and separate the pages with comments.

I tried this config

const lang = { en: 'English', cs: 'Česky' }
export const config = {
  translations: { en: { lang }, cs: { lang } },
  loaders: [
    { locale: 'en', loader: async () => await import('./en.js') },
    { locale: 'cs', loader: async () => await import('./cs.js') }
  ]
}

it doesn't throw any errors but the t method just returns the argument string.

@EskelCz EskelCz changed the title One translation file Single translation file per language Apr 6, 2022
@jarda-svoboda
Copy link
Member

jarda-svoboda commented Apr 6, 2022

Hi @EskelCz!

This library is meant to be module-based, so every translation "module" should have a specific key (so the lib can identify later which modules are already loaded and prevent duplicit loads). This means that you can use this config:

const lang = { en: 'English', cs: 'Česky' }
export const config = {
  translations: { en: { lang }, cs: { lang } },
  loaders: [
    { locale: 'en', key: 'common', loader: async () => await import('./en.js') },
    { locale: 'cs', key: 'common', loader: async () => await import('./cs.js') }
  ]
}

which results in $t('common.your.translations') inside your .svelte files.

Hope this helps!.)

@EskelCz
Copy link
Author

EskelCz commented Apr 7, 2022

Perfect, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants