Skip to content

Commit

Permalink
added flags and pkgdown structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmarindiaz committed Apr 23, 2020
1 parent cfdfa08 commit 36cfef5
Show file tree
Hide file tree
Showing 334 changed files with 2,814 additions and 255 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ vignettes/*.pdf
## Local locale for testing
locale/
locale/*
inst/doc
30 changes: 21 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
Package: shi18ny
Title: Tools for shiny apps internationalization
Version: 0.0.1
Authors@R: person("Juan Pablo", "Marin Diaz", email = "[email protected]", role = c("aut", "cre"))
Description: Tools for shiny apps internationalization
Version: 0.1.0
Authors@R:
person(given = "Juan Pablo",
family = "Marin Diaz",
role = c("aut", "cre"),
email = "[email protected]")
Maintainer: Juan Pablo Marin Diaz <[email protected]>
Description: Create shiny apps in multiples languages. You can include
common words in multiple languages or provide your custom translations.
URL: https://github.com/datasketch/shi18ny, https://shi18ny.datasketch.dev
BugReports: https://github.com/datasketch/shi18ny/issues
License: MIT + file LICENSE
LazyData: true
Depends:
R (>= 3.0.0),
yaml
Imports:
shiny (>= 0.11.1),
shinyjs
License: MIT
LazyData: true
RoxygenNote: 6.1.1
shiny,
shinyjs,
yaml
Encoding: UTF-8
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
RoxygenNote: 7.1.0
2 changes: 1 addition & 1 deletion R/i18n.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ uiLangUpdate <- function(classes, lang){
#' @export
availableLangs <- function(localeDir = NULL){
x <- read.csv(system.file("ui-translations.csv", package = "shi18ny"), stringsAsFactors = FALSE)
names(x)[-1]
sort(names(x)[-1])
}


Expand Down
92 changes: 92 additions & 0 deletions R/input-selectImage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@


#' Add images to dropdown options
#'
#' This function works only with bootstrap for now
#'
#' @param inputId The input slot that will be used to access the value.
#' @param choices List of values to select from, when named the names are
#' appended to the right of the image.
#' @param images List of image location that can be put in a src attribute.
#' @param selected Selected image, defaults to first one.
#' @param placeholder HTML to render as placeholder, overrides selected param.
#' @param width width in of input.
#'
#' Borrowed from the package shinyinvoer
#'
selectImageInput <- function(inputId, label, choices, images = NULL,
selected = 1,
placeholder = NULL,
width = 120) {

shiny::addResourcePath(
prefix='selectImage',
directoryPath=system.file("lib/selectImage",
package='shinyinvoer')
)

choices_list <- lapply(seq_along(choices), function(x){
list(id = choices[x],
image = images[x],
label = ifelse(is.null(names(choices[x])), 0, names(choices[x]))
)
})

if(is.numeric(selected))
selected <- choices[selected]
if(is.null(placeholder)){
x <- choices_list[[selected]]
placeholder <- shiny::div(class = "selectImage", shiny::img(src=x$image), x$label)
}

input <- jsonlite::toJSON(choices_list, auto_unbox = TRUE)

shiny::div(
`data-options` = htmltools::HTML(input),
`data-selected` = selected,
id = inputId,
class = "dropdown",
style = paste0('width:', width, 'px;'),
label,
shiny::tagList(
shiny::singleton(
shiny::tags$head(
shiny::tags$link(rel = 'stylesheet',
type = 'text/css',
href = 'selectImage/selectImage.css'),
shiny::tags$script(src = 'selectImage/selectImage-bindings.js')
)
)
),
)
}

#' Update select image input
#'
#' @param session Shiny session
#' @param inputId The input slot that will be used to access the value.
#' @param choices List of values to select from, when named the names are
#' appended to the right of the image.
#' @param images List of image location that can be put in a src attribute.
#' @param selected Selected image, defaults to first one.
#' @param placeholder HTML to render as placeholder, overrides selected param.
#' @param width width in of input.
#'
#' @export
updateSelectImageInput <- function(session, inputId, label = NULL, choices = NULL,
images = NULL, selected = NULL) {
message <- dropNulls(
list(
label = label,
choices = choices,
images = images,
selected = selected)
)
session$sendInputMessage(inputId, message)
}


# copied from shiny since it's not exported
dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE=logical(1))]
}
107 changes: 27 additions & 80 deletions R/selectLangInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,42 @@
#' @param width width in of input.
#'
#' @export
selectLangInput <- function(inputId, label, choices,
selectLangInput <- function(inputId, label, langs,
flags = NULL,
show_flags = TRUE,
selected = 1,
placeholder = NULL,
width = 120, img_width = 20) {

addResourcePath(
prefix='selectLang',
directoryPath=system.file("lib/selectLang",
package='shi18ny')
)

images <- list.files(system.file("flags", package = "shi18ny"), full.names = TRUE)
imagesNames <- basename(file_path_sans_ext(images))
names(images) <- imagesNames
choices_list <- lapply(seq_along(choices), function(x){
choice <- choices[x]
list(id = choices[x],
image = paste0("data:image/svg+xml;utf8,",paste0(readLines(images[[choice]]),collapse="")),
label = names(choices[x])
)
})
names(choices_list) <- choices

if(is.numeric(selected))
selected <- choices[selected]
if(is.null(placeholder) && !is.null(choices)){
x <- choices_list[[selected]]
placeholder <- div(class = "selectLang", img(src=x$image, width = img_width), x$label)
width = 100) {
if(show_flags){
flags <- flags %||% get_flags_image(langs)
}
selectImageInput(inputId, label = label, choices = langs,
images = flags, selected = selected, placeholder = placeholder,
width = width)

l <- lapply(choices_list, function(x){
tags$li(class = "selectLang",
tags$a(href="#", title = "Select", class = "selectLang", id = x$id,
img(src=x$image, width = img_width), x$label
)
)
})

shiny::div(
label,
shiny::div(
`data-shiny-input-type` = "selectLang",
shiny::tagList(
shiny::singleton(
shiny::tags$head(
shiny::tags$link(rel = 'stylesheet',
type = 'text/css',
href = 'selectLang/selectLang.css'),
shiny::tags$script(src = 'selectLang/selectLang-bindings.js')
))
),
div(class = "btn-group", id = inputId, `data-init-value` = selected,
tags$button(type = "button", class = "btn btn-default dropdown-toggle selectLang",
style = "display: flex;align-items: center;",
`data-toggle`="dropdown", `aria-haspopup`="true", `aria-expanded`="false",
div(class = "buttonInner selectLang",
placeholder
),
span(class="glyphicon glyphicon-chevron-down", style = "padding-left: 10px;")
),
tags$ul( class="dropdown-menu",
l
)
)
)
)
}


updateSelectLangInput <- function (session, inputId, label = NULL, choices = NULL, selected = NULL) {
# # Only updates selected for now
# choices <- if (!is.null(choices))
# choicesWithNames(choices)
# if (!is.null(selected))
# selected <- as.character(selected)
# options <- if (!is.null(choices))
# selectOptions(choices, selected)
message <- dropNulls(
list(
label = label,
choices = choices,
selected = selected)
)
session$sendInputMessage(inputId, message)
get_flags_image <- function(langs){
flags <- list.files(system.file("flags","png",package = "shi18ny"), full.names = TRUE)
names(flags) <- basename(tools::file_path_sans_ext(flags))
flags <- flags[langs]
image_data <- unlist(lapply(flags, function(flag){
knitr::image_uri(flag)
}))
}

#' @export
updateSelectLangInput <- function(session, inputId, label = NULL, langs = NULL,
flags = NULL,
show_flags = TRUE,
selected = NULL){
if(show_flags){
flags <- flags %||% get_flags_image(langs)
}
updateSelectImageInput(session, inputId, label = label, choices = langs,
images = flags, selected = selected)

# copied from shiny since it's not exported
dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE=logical(1))]
}


77 changes: 77 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# shi18ny

<!-- badges: start -->
<!-- badges: end -->

Shiny apps internationalization: same app, multiple languages.

Check the full documentation at http://shi18ny.datasketch.dev


## Installation

You can install the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("datasketch/shi18ny")
```
## Your first multilanguage shiny app

This is a basic example which shows you how to solve a common problem:

```{r example}
#library(shi18ny)
## basic example code
```


## Configuration



## Add custom languages

Explore more examples.


## Roadmap

- Support RTL languages properly
- Add locale formatting for dates
- ...


## FAQ

### My language is not yet supported, what can I do to help?

File an issue and make a pull request following the instructions in the vignette.



# Acknowledgements

## Flags from

Country Flags taken from https://github.com/hjnilsson/country-flags
Catalonia flag from [wikipedia](https://meta.wikimedia.org/wiki/File:Flag_of_Catalonia.svg)




Binary file added data-raw/32/AD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AN.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AQ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/AZ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data-raw/32/BJ.png
Binary file added data-raw/32/BL.png
Binary file added data-raw/32/BM.png
Binary file added data-raw/32/BN.png
Binary file added data-raw/32/BO.png
Binary file added data-raw/32/BR.png
Binary file added data-raw/32/BS.png
Binary file added data-raw/32/BT.png
Binary file added data-raw/32/BW.png
Binary file added data-raw/32/BY.png
Binary file added data-raw/32/BZ.png
Binary file added data-raw/32/CA.png
Binary file added data-raw/32/CC.png
Binary file added data-raw/32/CD.png
Binary file added data-raw/32/CF.png
Binary file added data-raw/32/CG.png
Binary file added data-raw/32/CH.png
Binary file added data-raw/32/CI.png
Binary file added data-raw/32/CK.png
Binary file added data-raw/32/CL.png
Binary file added data-raw/32/CM.png
Binary file added data-raw/32/CN.png
Binary file added data-raw/32/CO.png
Binary file added data-raw/32/CR.png
Binary file added data-raw/32/CT.png
Binary file added data-raw/32/CU.png
Binary file added data-raw/32/CV.png
Binary file added data-raw/32/CW.png
Binary file added data-raw/32/CX.png
Binary file added data-raw/32/CY.png
Binary file added data-raw/32/CZ.png
Binary file added data-raw/32/DE.png
Binary file added data-raw/32/DJ.png
Binary file added data-raw/32/DK.png
Binary file added data-raw/32/DM.png
Binary file added data-raw/32/DO.png
Binary file added data-raw/32/DZ.png
Binary file added data-raw/32/EC.png
Binary file added data-raw/32/EE.png
Binary file added data-raw/32/EG.png
Binary file added data-raw/32/EH.png
Binary file added data-raw/32/ER.png
Binary file added data-raw/32/ES.png
Binary file added data-raw/32/ET.png
Binary file added data-raw/32/EU.png
Binary file added data-raw/32/FI.png
Binary file added data-raw/32/FJ.png
Binary file added data-raw/32/FK.png
Binary file added data-raw/32/FM.png
Binary file added data-raw/32/FO.png
Binary file added data-raw/32/FR.png
Binary file added data-raw/32/GA.png
Binary file added data-raw/32/GB.png
Binary file added data-raw/32/GD.png
Binary file added data-raw/32/GE.png
Binary file added data-raw/32/GG.png
Binary file added data-raw/32/GH.png
Binary file added data-raw/32/GI.png
Binary file added data-raw/32/GL.png
Binary file added data-raw/32/GM.png
Binary file added data-raw/32/GN.png
Binary file added data-raw/32/GQ.png
Binary file added data-raw/32/GR.png
Binary file added data-raw/32/GS.png
Binary file added data-raw/32/GT.png
Binary file added data-raw/32/GU.png
Binary file added data-raw/32/GW.png
Binary file added data-raw/32/GY.png
Binary file added data-raw/32/HK.png
Binary file added data-raw/32/HN.png
Binary file added data-raw/32/HR.png
Binary file added data-raw/32/HT.png
Binary file added data-raw/32/HU.png
Binary file added data-raw/32/IC.png
Binary file added data-raw/32/ID.png
Binary file added data-raw/32/IE.png
Binary file added data-raw/32/IL.png
Binary file added data-raw/32/IM.png
Binary file added data-raw/32/IN.png
Binary file added data-raw/32/IQ.png
Binary file added data-raw/32/IR.png
Binary file added data-raw/32/IS.png
Binary file added data-raw/32/IT.png
Binary file added data-raw/32/JE.png
Binary file added data-raw/32/JM.png
Binary file added data-raw/32/JO.png
Binary file added data-raw/32/JP.png
Binary file added data-raw/32/KE.png
Binary file added data-raw/32/KG.png
Binary file added data-raw/32/KH.png
Binary file added data-raw/32/KI.png
Binary file added data-raw/32/KM.png
Binary file added data-raw/32/KN.png
Binary file added data-raw/32/KP.png
Binary file added data-raw/32/KR.png
Binary file added data-raw/32/KW.png
Binary file added data-raw/32/KY.png
Binary file added data-raw/32/KZ.png
Binary file added data-raw/32/LA.png
Binary file added data-raw/32/LB.png
Binary file added data-raw/32/LC.png
Binary file added data-raw/32/LI.png
Binary file added data-raw/32/LK.png
Binary file added data-raw/32/LR.png
Binary file added data-raw/32/LS.png
Binary file added data-raw/32/LT.png
Binary file added data-raw/32/LU.png
Binary file added data-raw/32/LV.png
Binary file added data-raw/32/LY.png
Binary file added data-raw/32/MA.png
Binary file added data-raw/32/MC.png
Binary file added data-raw/32/MD.png
Binary file added data-raw/32/ME.png
Binary file added data-raw/32/MF.png
Binary file added data-raw/32/MG.png
Binary file added data-raw/32/MH.png
Binary file added data-raw/32/MK.png
Binary file added data-raw/32/ML.png
Binary file added data-raw/32/MM.png
Binary file added data-raw/32/MN.png
Binary file added data-raw/32/MO.png
Binary file added data-raw/32/MP.png
Binary file added data-raw/32/MQ.png
Binary file added data-raw/32/MR.png
Binary file added data-raw/32/MS.png
Binary file added data-raw/32/MT.png
Binary file added data-raw/32/MU.png
Binary file added data-raw/32/MV.png
Binary file added data-raw/32/MW.png
Binary file added data-raw/32/MX.png
Binary file added data-raw/32/MY.png
Binary file added data-raw/32/MZ.png
Binary file added data-raw/32/NA.png
Binary file added data-raw/32/NC.png
Binary file added data-raw/32/NE.png
Binary file added data-raw/32/NF.png
Binary file added data-raw/32/NG.png
Binary file added data-raw/32/NI.png
Binary file added data-raw/32/NL.png
Binary file added data-raw/32/NO.png
Binary file added data-raw/32/NP.png
Binary file added data-raw/32/NR.png
Binary file added data-raw/32/NU.png
Binary file added data-raw/32/NZ.png
Binary file added data-raw/32/OM.png
Binary file added data-raw/32/PA.png
Binary file added data-raw/32/PE.png
Binary file added data-raw/32/PF.png
Binary file added data-raw/32/PG.png
Binary file added data-raw/32/PH.png
Binary file added data-raw/32/PK.png
Binary file added data-raw/32/PL.png
Binary file added data-raw/32/PN.png
Binary file added data-raw/32/PR.png
Binary file added data-raw/32/PS.png
Binary file added data-raw/32/PT.png
Binary file added data-raw/32/PW.png
Binary file added data-raw/32/PY.png
Binary file added data-raw/32/QA.png
Binary file added data-raw/32/RE.png
Binary file added data-raw/32/RO.png
Binary file added data-raw/32/RS.png
Binary file added data-raw/32/RU.png
Binary file added data-raw/32/RW.png
Binary file added data-raw/32/SA.png
Binary file added data-raw/32/SB.png
Binary file added data-raw/32/SC.png
Binary file added data-raw/32/SD.png
Binary file added data-raw/32/SE.png
Binary file added data-raw/32/SG.png
Binary file added data-raw/32/SH.png
Binary file added data-raw/32/SI.png
Binary file added data-raw/32/SK.png
Binary file added data-raw/32/SL.png
Binary file added data-raw/32/SM.png
Binary file added data-raw/32/SN.png
Binary file added data-raw/32/SO.png
Binary file added data-raw/32/SR.png
Binary file added data-raw/32/SS.png
Binary file added data-raw/32/ST.png
Binary file added data-raw/32/SV.png
Binary file added data-raw/32/SX.png
Binary file added data-raw/32/SY.png
Binary file added data-raw/32/SZ.png
Binary file added data-raw/32/TC.png
Binary file added data-raw/32/TD.png
Binary file added data-raw/32/TF.png
Binary file added data-raw/32/TG.png
Binary file added data-raw/32/TH.png
Binary file added data-raw/32/TJ.png
Binary file added data-raw/32/TK.png
Binary file added data-raw/32/TL.png
Binary file added data-raw/32/TM.png
Binary file added data-raw/32/TN.png
Binary file added data-raw/32/TO.png
Binary file added data-raw/32/TR.png
Binary file added data-raw/32/TT.png
Binary file added data-raw/32/TV.png
Binary file added data-raw/32/TW.png
Binary file added data-raw/32/TZ.png
Binary file added data-raw/32/UA.png
Binary file added data-raw/32/UG.png
Binary file added data-raw/32/US.png
Binary file added data-raw/32/UY.png
Binary file added data-raw/32/UZ.png
Binary file added data-raw/32/VA.png
Binary file added data-raw/32/VC.png
Binary file added data-raw/32/VE.png
Binary file added data-raw/32/VG.png
Binary file added data-raw/32/VI.png
Binary file added data-raw/32/VN.png
Binary file added data-raw/32/VU.png
Binary file added data-raw/32/WF.png
Binary file added data-raw/32/WS.png
Binary file added data-raw/32/YE.png
Binary file added data-raw/32/YT.png
Binary file added data-raw/32/ZA.png
Binary file added data-raw/32/ZM.png
Binary file added data-raw/32/ZW.png
Binary file added data-raw/32/_abkhazia.png
Binary file added data-raw/32/_basque-country.png
Binary file added data-raw/32/_british-antarctic-territory.png
Binary file added data-raw/32/_commonwealth.png
Binary file added data-raw/32/_england.png
Binary file added data-raw/32/_gosquared.png
Binary file added data-raw/32/_kosovo.png
Binary file added data-raw/32/_mars.png
Binary file added data-raw/32/_nagorno-karabakh.png
Binary file added data-raw/32/_nato.png
Binary file added data-raw/32/_northern-cyprus.png
Binary file added data-raw/32/_olympics.png
Binary file added data-raw/32/_red-cross.png
Binary file added data-raw/32/_scotland.png
Binary file added data-raw/32/_somaliland.png
Binary file added data-raw/32/_south-ossetia.png
Binary file added data-raw/32/_united-nations.png
Binary file added data-raw/32/_unknown.png
Binary file added data-raw/32/_wales.png
50 changes: 50 additions & 0 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
library(tidyverse)

# PNG flags from
# https://github.com/gosquared/flags

langs <- availableLangs()
images <- list.files("data-raw/32", full.names = TRUE)

langs_country <- tribble(
~lang, ~country,
"ar","SA",
"da","DK",
"de","DE",
"en","US",
"es","ES",
"fr","FR",
"he","GR",
"hi","IN",
"it","IT",
"pt","PT",
"pt_BR","BR",
"ru","RU",
"sv","SE",
"zh_CN","CN"
)
# Manually add Catalonia and fallbacks (e.g. Colombia)

all(langs_country$country %in% basename(file_path_sans_ext(images)))

lapply(transpose(langs_country), function(x){
file.copy(paste0("data-raw/32/",x$country,".png"),
paste0("inst/flags/png/",x$lang,".png"))
})


### Another attempt resizing SVGs directly.

# library(magick)
# images <- list.files(system.file("flags","svg", package = "shi18ny"), full.names = TRUE)
#
# lapply(images, function(image){
# img <- image_read(image) %>% image_resize("32")
# path <- gsub("\\/svg","\\/png32",image)
# path <- gsub("\\.svg","\\.png",path)
# image_write(img, path, format = "png")
# })



#usethis::use_data("DATASET")
Loading

0 comments on commit 36cfef5

Please sign in to comment.