Getting the getLocale() value into payload


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 getLocale() function.
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?


1 Like

Hi @mateorid,

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.

  1. which panel visualisation you are using?

  2. Grafana version?


Hi @usman.ahmad,

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:

"Start": "${__from:date}",
"Stop": "${__to:date}",
"Lang": "${lang}"

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:

  1. I have multiple dashboards, with multiple pannels (bar gauges, tables, maps, pie charts,…)
  2. 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 :smile:)

Hi @mateorid

Thank you for your patience :pray:

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.

1 Like

here’s the link: Make GetLocale() a global variable · grafana/grafana · Discussion #66013 · GitHub

Thanks for this. I added some more metadata into it :slight_smile: