Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enables loading locales before Plotly #4453

Merged
merged 5 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ register([
require('./locale-en-us')
]);

// locales that are present in the window should be loaded
if(window.PlotlyLocales && Array.isArray(window.PlotlyLocales)) {
register(window.PlotlyLocales);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could after this line have:

delete window.PlotlyLocales;

to de-pollute the window namespaces after we're done registering the locales.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f169380

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a temporary variable, it may be better to add an underscore i.e. window._PlotlyLocales.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I'll let @etpinard choose between the different options (see also #4453 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering using sessionStorage may be a possibility?

delete window.PlotlyLocales;
}

// plot icons
exports.Icons = require('./fonts/ploticon');

Expand Down
4 changes: 2 additions & 2 deletions tasks/util/wrap_locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ var intoStream = require('into-stream');

var constants = require('./constants');

var prefix = 'Plotly.register(';
var suffix = ');';
var prefix = 'var locale=';
var suffix = ';if(typeof Plotly === \'undefined\') {window.PlotlyLocales = window.PlotlyLocales || []; window.PlotlyLocales.push(locale);} else {Plotly.register(locale);}';

var moduleMarker = 'module.exports = ';

Expand Down