Make your {golem}
based apps more beautiful with {gemstones}
.
You can install the development version of {gemstones}
like so:
remotes::install_github("thinkr-open/gemstones")
You’re reading the doc about version : 0.0.0.9001
This README has been compiled on the
Sys.time()
#> [1] "2023-03-27 13:26:46 CEST"
Here are the test & coverage results :
devtools::check(quiet = TRUE)
#> ℹ Loading gemstones
#> ── R CMD check results ─────────────────────────────── gemstones 0.0.0.9001 ────
#> Duration: 7.7s
#>
#> 0 errors ✔ | 0 warnings ✔ | 0 notes ✔
covr::package_coverage()
#> gemstones Coverage: 48.04%
#> R/use_notifyjs.R: 0.00%
#> R/use_jqueryi18next.R: 77.78%
The goal of {gemstones}
is to allow you to add some JavaScript
libraries to your {golem}
based app.
{gemstones}
will automate the download and the linking of some JS
libraries, but it’s important to understand that {gemstones}
is not
providing a full wrapper or widget for these libraries. You’ll still
have to code some elements to make it work.
Note also that the functions in this package are not intended to work
outside of a {golem}
based app.
Skeleton for Notifyjs can be added
with gemstones::use_notifyjs()
.
This function will do the following:
- Download
notifyjs
from the website. - Add a
notifyjs_handlers.js
file, which are shiny custom message handlesr - Add
fct_notifyjs.R
, which containsnotify_success()
,notify_warning()
, ¬ify_error()
. - Add tes.
This JS plugin provides notifications that can be sent and customize via
the R functions defined in fct_notifyjs.R
Skeleton for jquery-i18next
can be added with gemstones::use_jqueryi18next()
.
This function will do the following:
- Download
i18next
&jquery-i18next
from a CDN. - Add a
i18n_locales.json
file, which you can use to add your translation. - Add a
i18n_shiny.js
file, which will load the lib & data when your shiny app launched. - Add a
i18n_handlers.js
file, which are shiny custom message handlesr - Add
fct_i18n.R
, which containswith_i18n()
,localize()
,change_language()
&get_language()
. - Add test for
with_i18n()
.
This JS plugin provides client-side translation of the UI elements.
To define a translation, you need to follow this pattern:
gemstones::use_jqueryi18next()
# Add a i18n tag to your element
h1("Hello") |> with_i18n("main_title")
{
"en": {
"translation": {
"main_title": "Hello World"
}
},
"fr": {
"translation": {
"main_title": "Wesh la famille"
}
}
}
Then at app launch, this title will be translated.
To switch from one language to the other, you can use one of these two technics:
- Run code in JavaScript:
// Set the language
i18next.changeLanguage('fr')
// Localize
$("html").localize()
- Run code in R:
change_language("fr")
localize("html")