-
Notifications
You must be signed in to change notification settings - Fork 56
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
Access items in array #60
Comments
Hi @kengres Thank you for your input. This is currently not possible. I will look into the issue and see if it can be implemented without adding to much overhead to the processing. |
Hi! Thanks a lot for this awesome plugin, love it! I have a similar issue regarding this, I bring the data from a /graphql endpoint, it brings it fine and I added it the following way:
I can access the data through Vuexi18n doing {{ $t('herounits') }} and it shows it the following way [ { "title": "Hero unit title", "description": "Hero unit description" } ], but I need to access it individually like {{ $t('herounits[0].title') }} which it's not possible for what I see under this issue, my question is if there's any workaround at the moment since I really need to bring the data from the endpoint because I'm using a CMS, or if it's possible for example to bring the data from GraphQL as a pure object without arrays (I'm searching about this under it's respective section but worth asking here in case). Thanks a lot and keep up the awesome work! |
Hi @orsileonel Thank you for your feedback. It is possible to return pure objects from graphql instead of arrays. This depends on the graphql schema definition and implementation. The plugin will actually transform any language information into a flat lookup map. Unfortunately, the corresponding function does not handle arrays of objects yet. {
herounits: {
title: „some title“
}
}
// will be flattened to
{
„herounits.title“: „some title“
} As a workaround, you could write a function to transform the locale information into a flattened map yourself and pass this flattened information to the plugin. The lookup will then be done with simple string comparison. |
Thank you @tikiatua, once this feature is applied will replace it for sure, meanwhile will try using that workaround. EDIT: for anyone who's in need of the same (or similar) as me, you can use the following example which is working great (feel free to update if you come up with a better one)!
After it all the arrays will be removed allowing you to access the data as {{ $t('metatag.title') }} for example, hope it helps! Keep up the awesome work! |
vuex-i18n/test/index.html
Line 105 in 8824369
Thanks for the plugin, really useful. question though. is it possible to access a single item in a list (array) say i wanted the first item of listing.
<p>{{ $t('listing[0]') }}</p>
The text was updated successfully, but these errors were encountered: