-
Notifications
You must be signed in to change notification settings - Fork 79
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
Getting an object of translation #50
Comments
The Here's a simple REPL to demonstrate that: https://svelte.dev/repl/49412f11564b41a183f414177ffc52b9?version=3.18.2 |
It's not super practical, I literally have the identifier of all the countries to copy and paste 🤡. |
If anyone comes into this need, I did this import { pickBy } from "lodash"
let dic = $dictionary[$locale];
let countries = [];
pickBy(dic, (v, k) => {
if (k.includes("countries.list")) {
const key = k.split(".")[2];
countries.push({ key, value: v });
}
}); It does the trick, but something native could be really cool 😉 |
Following what you wanted on the OP, what would Dictionaries are flatten since #39 and I understand that it's not the optimal solution to have an extra list, but there's currently no other way to do that. Having a deep dictionary only adds complexity to the code and it wasn't necessarily being useful. I still think that using the dictionary to loop through values isn't the right way of doing this, but I'm open to discussion. (about your workaround: I'd manually import |
I don't want it to be rendered, I just want to get back an object to then use it for a dropdown. |
Ok, so for some reason my workaround only works server side. event tho I have that <script context="module">
import { waitLocale } from "svelte-i18n";
export async function preload() {
return waitLocale();
}
</script> |
Can you provide a repro? |
The |
I'm using Sapper.
In my repro I used $isLoading, as you saw the repro doesn't work anyway. |
Oh okay, so please provide a sapper repro, not a svelte one 😁 A simple .zip helps a lot. And my bad, outdated doc. It's called |
My point was, shouldn't the svelte one works? because it doesn't 😥. |
Move those references to $dictionary and $locale to inside the |
Hey @RemiKalbe 👋 Sorry for taking so long to answer you. It seems that when you're getting the current dictionary via I'm thinking if it makes sense to return a merged dictionary of, in example, |
What would be great is that if $dictionary[$locale] of a given $locale doesn't exist it fallback to the default one set in the init. |
For now, I'll just to that, thank you for solving my issue 😉 let dic =
typeof $dictionary[$locale] === "undefined"
? $dictionary["en"]
: $dictionary[$locale]; |
I have in my JSON something like that:
and I would like to be able to do that
and get the list of countries as an object.
Right now I get an error telling me that
countries.list
doesn't exist.For the moment I will probably use the
$dictionary
but it is painful because everything is shallow so I need to manually filter each key to find what I want.Am I missing something?
The text was updated successfully, but these errors were encountered: