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.

Hello 👋 I am having trouble with localization. I have looked at plotly.js tests for some inspiration and I’ve seen that config.locale and config.locales are being set here and passed to newPlot fn. But it didn’t really help me.

My Chart components looks like this:

import * as Plotly from 'plotly.js'
import * as csDictionary from 'plotly.js/lib/locales/cs.js'
import * as React from 'react'
import * as Plot from 'react-plotly.js'

Plotly.register(csDictionary)
Plotly.setPlotConfig({ locale: 'cs' })

const trace1 = {
  x: [0, 1, 2],
  y: [1, 1, 1],
  mode: 'lines+markers+text',
  name: 'Lines, Markers and Text',
  text: ['Text A', 'Text B', 'Text C'],
  textposition: 'top right',
  textfont: {
    family: 'sans serif',
    size: 18,
    color: '#1f77b4',
  },
  type: 'scatter',
}

class Chart extends React.Component {
  render() {
    return (
      <Plot
        config={{ locale: 'cs' }}
        data={[trace1]}
        layout={{
          width: 800,
          height: 400,
          title: 'A Fancy Plot',
        }}
      />
    )
  }
}
export default Chart

❓ Any ideas how to make this work?

Localization is crucial for me and it looks that it is somehow supported, but I just cannot figure how to set it up.

Thanks 🙏

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
angelorbastoscommented, Dec 1, 2020

For anyone still having this issue: after hours of struggling with this, having @conradoqg’s solution not work for me because of Webpack, I found an easy workaround.

At your top-level imports, do:

import * as localeDictionary from 'plotly.js/lib/locales/pt-br.js'

Notice you can import whatever Plotly-provided locale on the line above, and probably even create your own (following Plotly’s pre-defined dictionary structure for locales).

Then, inside your component definition, do:

<Plot 
  config = {{
    locales: { 'pt-BR': localeDictionary }, // This makes the locale available to your plot
    locale: 'pt-BR' // This uses the locale on the plot
  }}
  ...
/>

Hope this helps, cheers!

3reactions
conradoqgcommented, Nov 17, 2018

Got it:

import * as Plotly from 'plotly.js';
import * as csDictionary from 'plotly.js/lib/locales/pt-br.js';
import createPlotlyComponent from 'react-plotly.js/factory';
const Plot = createPlotlyComponent(Plotly);
Plotly.register(csDictionary);

Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Localization - Wikipedia
Language localization, translating a product into different languages or adapting a product to a country or region ; Internationalization and localization, the ...
Read more >
What is localization? | Definition from TechTarget
Localization is the adaptation of a product or service to meet the needs of a particular language, culture or desired population's "look-and-feel.".
Read more >
Everything You Need to Know About Localization - Smartling
Localization is the process of adapting a piece of content's full meaning for a new region, including translation, associated imagery, and cultural elements ......
Read more >
LOCALIZATION definition | Cambridge English Dictionary
the process of organizing a business or industry so that its main activities happen in local areas rather than nationally or internationally: In...
Read more >
What Is Localization, and How to Build a Strategy? | Phrase
Localization is the process of adapting a product or service to the culture and language of customers in a target market.
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