question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: dynamically load sharedMessages

See original GitHub issue

Hello,

We know we can add sharedMessages to a component by using the sharedMessages key which enables us to create a set of keys that we can write once, reuse in several components.

We have a usecase in which we want to “abuse” this by dynamically adding keys to the component.

Consider a DataTable that you want to reuse to display resources of different types. I Could use it to show a list of invoices, or a list of support tickets, or whatever resource we support in our app.

We have this component set up as follows for instance:

<template>
    <div>
        <h1>{{$tc('resource', 2)}}</h1>
    </div>
</template>

As you can tell, we want to define one key, resourcewhich we can override depending on what resource we want to display in the component.

Our idea was to use the sharedMessages for this, and do something like this.

<script>
    export default {
        props: {
            resource: { required: true}
        },
        i18n: {
            messages: {
                // generic datatable keys would go here
            },
            sharedMessages: this.resource.i18n
        }
    }
</script>

the idea is that we can initialise our component as follows:

<data-table-component resource="XXXXX"></data-table-component>

It’s not important for this feature request, but XXXXX in our case is a class. We use https://github.com/robsontenorio/vue-api-query for our client side resources handling, and it just made sense to us to add a get i18n() {} method in there that returns our sharedMessages our component could pull in.

Currently, I don’t see how sharedMessages can take anything that is defined on the Vue component. I’ve also tried defining it as a function return this.resource.i18n, but it didn’t work either, so I guess it’s unsupported at this time.

Since the datatable component should not know what resource it’s being created for, I can not pull it in using an import statement there, since the resource will always be a property value.

The only thing I currently see as an option is namespacing all our keys and pull in ALL the resources, so we can do something like {{$tc(resource + '.resource', 2}} and I could define it all in one big object, but I wouldn’t like having to do this as it clutters our templates.

Any possible workaround or possibility for supporting this in the (near) future?

For your info, I create a CodeSandBox for it here: https://codesandbox.io/s/vue-template-21l7z?fontsize=14

thanks again for a great library!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
denjalandcommented, Oct 21, 2019

I’m basically looking for a way to programaticaly set the component message strings without having it affect the locale messages of the same component or even other components on the page sharing the same keys…

1reaction
denjalandcommented, Oct 21, 2019

Hi @kazupon,

Doesn’t that introduce the same issue as with mergeLocaleMessage, namely that if you have two components on the page, they end up sharing the same locale keys and messages?

David.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request - Dynamically load a widget
I'd like to see the ability to have a dashboard determine which widget(s) to load based on the content of the data. Example:...
Read more >
Feature request: Dynamic children - Share an idea
My solution would designate an already predetermined child to be dynamic in number, so only that child could be repeated. There are limits...
Read more >
Feature request – Dynamic plugins - WordPress.org
I feel like a lot of people that use this plugin want to show off multiple plugins / themes that they sell in...
Read more >
21 More Facebook Tricks Features You Should Be Using
Click on the top right dropdown in Facebook, and go to Settings > Notifications > on Facebook. Then next to App Requests and...
Read more >
imessage slack integration
Shared messages and tasks in Evernote, Asana, Trello, BaseCamp. ... the other hand, offers a simple two-tier approach depending on the features you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found