I’m trying to internationalize my panels information. For that, I need to get the language code to the payload that is sent in queries to my backend.
I’ve been using variables to set the language so far, but I want to to move to adopt the grafana language picker (the one in preferences) and it’s
Is there a way how I can get the language code from the
getLocale() function to the payload or to the variables and how can I do it?
Thanks for opening this post.
So there is a Dynamic Text Panel which does support the
getLocale() as built-in.
If this does not fit to your case then can you please provide some more details e.g.
which panel visualisation you are using?
Thanks for answering, I know about Dynamic Text Panel and I’am using it.
What am I trying to achieve?
I have a backend that sends data to my grafana frontend. Some of this content is language dependant so until now I’ve been using a simple dashboard variable to select the language.
I am using the JSON datasource, and I use the variable in its payload something like this:
Now my problem is, how do I get the language from grafana preferences here? It would be great if it was accessible as a global variable, but I believe that’s not the case. I found out about the
getLocale() function and I’ve been experimenting with it now.
What have I figured out:
I still have the dashboard variable (hidden) and I’am using the Dynamic Text Panel to edit the URL of the dashboard based on the
getLocale() function, it’s working but it isn’t a clean solution. If you can figure out a better way to do this that would be great! (I think making it a global variable is the most sensible way to do it)
To answer your questions:
- I have multiple dashboards, with multiple pannels (bar gauges, tables, maps, pie charts,…)
- Currently my custom fork of grafana 9.3.6 where I added some features that I am missing from the official one (translation of plugins, other languages, …, might try to figure out how and add the language as a global variable as well )
Thank you for your patience
I had a chance to ask the team about this one. As this is currently not on the roadmap but makes a good case to have it and for that please make a feature request at our GitHub Discussions.
Fill out the details and paste the link here so that the community can vote for it to get higher priority and visibility.
Thanks for this. I added some more metadata into it