8000 support 'sub-locales' and better example to showoff date localization · plotly/plotly.R@20c8aae · GitHub
[go: up one dir, main page]

Skip to content

Commit 20c8aae

Browse files
committed
support 'sub-locales' and better example to showoff date localization
1 parent 36d8b5e commit 20c8aae

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

R/layout.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,29 @@ 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
93+
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info.
9494
#' @author Carson Sievert
9595
#' @export
9696
#' @examples
9797
#'
98-
#' p <- plot_ly(x = rnorm(1000))
98+
#' today <- Sys.Date()
99+
#' x <- seq.Date(today, today + 360, by = "day")
100+
#' p <- plot_ly(x = x, y = rnorm(length(x))) %>%
101+
#' add_lines()
99102
#'
100103
#' # remove the plotly logo and collaborate button from modebar
101104
#' config(p, displaylogo = FALSE, collaborate = FALSE)
102105
#'
106+
#' #' # japanese
107+
#' config(p, locale = "ja")
108+
#' #' # german
109+
#' config(p, locale = "de")
110+
#' # swiss-german
111+
#' config(p, locale = "de-CH")
103112
#' # spanish
104113
#' config(p, locale = "es")
105-
#' # german
106-
#' config(p, locale = "de")
107114
#' # french
108115
#' config(p, locale = "fr")
109-
#' # japanese
110-
#' config(p, locale = "ja")
111116
#'
112117

113118
config <- function(p, ..., collaborate = TRUE, cloud = FALSE, locale = NULL) {

R/plotly.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,20 @@ locale_dependency <- function(locale) {
455455
)
456456
}
457457

458+
459+
# some locales rely on a base/main locale (e.g. de-CH relies on de)
460+
# https://codepen.io/etpinard/pen/pKvLVX?editors=1010
461+
scripts <- paste0(locale, ".js")
462+
if (grepl("-", locale)) {
463+
locale_main <- strsplit(locale, "-")[[1]][1]
464+
scripts <- c(scripts, paste0(locale_main, ".js"))
465+
}
466+
458467
htmltools::htmlDependency(
459468
name = paste0("plotly-locale-", locale),
460469
version = plotlyMainBundle()$version,
461470
src = list(file = locale_dir),
462-
script = paste0(locale, ".js"),
471+
script = scripts,
463472
all_files = FALSE
464473
)
465474
}

man/config.Rd

Lines changed: 11 additions & 6 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