Dashboards & Visualizations

Getting locale in Javascript and gettext()

derekf
Explorer

I am trying to either (or maybe I need both) get the locale setting of the client in Javascript to replace some tokens in my search string, as well as trying to find if the gettext function is available in Javascript for localization.

Any ideas?

0 Karma

poete
Builder

Hello @derekf,

Did you have a look at this?
http://docs.splunk.com/Documentation/Splunk/7.1.1/Viz/tokens
and more precisely at the Use global tokens to access environment information section?
I think $env:locale$ is a good place to start.

Please also have a look at the following js code:

require(['splunkjs/mvc','jquery', 'splunkjs/mvc/simplexml/ready!'], function (mvc,$) {
    var utils = require("splunkjs/mvc/utils");
    $(document).ready(function () {
        // Retrieve the default token model
        var defaultTokenModel = mvc.Components.get("default");
        // Listen for a change to the token value
        defaultTokenModel.on("change:token", function(newToken, token, options){
            var x = document.getElementById("someTag");
            if (token==="True"){
                x.style.stroke="red";
            }
            else{
                x.style.stroke="lightblue";
            }
        });
    });
});

From there, you should be able to get started

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...