cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Can't figure out how to use translation variables #7

Closed MarcGodard closed 3 years ago

MarcGodard commented 3 years ago

I tried:

{$t("foot", { default: 'hello', count: 1 })}

The default works, but using the example, the count isn't working. What am I missing?

cibernox commented 3 years ago

I copied the API from svelte-i18n. Values must be passed inside a values key. In your example it should be {$t("foot", { default: 'hello', values: { count: 1 } })}. I personally don't like that too much, I find it a bit verbose, but since svelte-i18n is the most popular i18n library for svelte by a lot I thought it was wise to just use the exact same API to make transitioning to this library dead simple.

cibernox commented 3 years ago

You can find the docs for svelte-i18n here about this topic in https://github.com/kaisermann/svelte-i18n/blob/main/docs/Formatting.md#format-_-or-t

MarcGodard commented 3 years ago

Has this been tested with the latest kit version? Its not working for me and its the ONLY thing I added so far.

This: {$_("foot", { values: { count: 5 } })} shows up as {count} is awesome! (yes I simplified the example)

cibernox commented 3 years ago

Yes, it does work. I just created a test app quickly to prove it: https://github.com/cibernox/quick-i18n-throwaway-demo

MarcGodard commented 3 years ago

@cibernox Thanks, must be missing something.

cibernox commented 3 years ago

@MarcGodard if you find what you missed let me know, it's probably a signal that I should improve the readme.

MarcGodard commented 3 years ago

There was a svelte error that was causing all this. Once I fixed it, it fixed this.

cibernox commented 3 years ago

Great to hear, closing this!