8000 add locale arg to config() which automatically adds relevant script, … · plotly/plotly.R@423db5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 423db5d

Browse files
committed
add locale arg to config() which automatically adds relevant script, addresses #1270
1 parent 236a814 commit 423db5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+126
-13
lines changed

R/layout.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,23 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
9090
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js}
9191
#' @param collaborate include the collaborate mode bar button (unique to the R pkg)?
9292
#' @param cloud include the send data to cloud button?
93+
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info
9394
#' @author Carson Sievert
9495
#' @export
9596
#' @examples
9697
#'
9798
#' config(plot_ly(), displaylogo = FALSE, collaborate = FALSE)
98-
#'
99+
#' config(plot_ly(), locale = "de-CH")
99100

100-
config <- function(p, ..., collaborate = TRUE, cloud = FALSE) {
101+
config <- function(p, ..., collaborate = TRUE, cloud = FALSE, locale = NULL) {
102+
103+
if (!is.null(locale)) {
104+
p$dependencies <- c(
105+
p$dependencies,
106+
list(locale_dependency(locale))
107+
)
108+
p$x$config$locale <- locale
109+
}
101110

102111
p$x$config <- modify_list(p$x$config, list(...))
103112

R/plotly.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,30 @@ plotlyHtmlwidgetsCSS <- function() {
440440
)
441441
}
442442

443+
locale_dependency <- function(locale) {
444+
if (!is.character(locale) || length(locale) != 1) {
445+
stop("locale must be a character string (vector of length 1)", call. = FALSE)
446+
}
447+
448+
locale_dir <- depPath("plotlyjs", "locales")
449+
locales_all <- sub("\\.js$", "", list.files(localeDir))
450+
if (!tolower(locale) %in% locales_all) {
451+
stop(
452+
"Invalid locale: '", locale, "'.\n\n",
453+
sprintf("Supported locales include: '%s'", paste(locales_all, collapse = "', '")),
454+
call. = FALSE
455+
)
456+
}
457+
458+
htmltools::htmlDependency(
459+
name = paste0("plotly-locale-", locale),
460+
version = plotlyMainBundle()$version,
461+
src = list(file = locale_dir),
462+
script = paste0(locale, ".js"),
463+
all_files = FALSE
464+
)
465+
}
466+
443467
#' Remove TypedArray polyfill
444468
#'
445469
#' By default, plotly.js' TypedArray polyfill is included as a dependency, so

inst/htmlwidgets/lib/plotlyjs/locales/af.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/am.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/ar-dz.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/ar-eg.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/ar.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/az.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/bg.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/bs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/ca.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/cs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/da.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/de-ch.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/de.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/el.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/eo.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/lib/plotlyjs/locales/es-ar.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0