This is a bit of a weird questions. And I am not sure how to best word it, please bare with me.
Background:
We have a shiny app which uses shiny.i18n package to translate the app into several languages. We have multiple developers working on this app and sometimes they do not enter the text which should be translated into the translate.json file, which means someone has to go through the whole app scripts to check if everything is in the json file.. Our app currently contains 384 R scripts total and going through them all takes days. This is really a massive app..
Problem
I am hoping to automate this task somehow. Ideally I would like to read in a list of all the R scripts, e.g. using list.files(...):
r_scripts <- list.files(
path = "/path/to/scripts",
pattern = ".R",
recursive = TRUE,
full.names = TRUE
)
Then takes this list of R scripts, and read each one and add it to a vector. E.g.
code_vctr <- as.character()
for(i in 1:length(r_scripts)){
code_vctr <- cat(
code_vctr,
readLines(
r_scripts[i]
)
)
}
Then, after I have somehow concatenated the scripts together in one massive vector, I need some way to be able to search for text which is withing translate()$t(...). For example, shiny.i18n uses the functiontranslate()$t() to translate what is between the brackets to the language of user choice. So if in the code it reads: `translate()$t("This should be translated"), then the text string looks within the translate.json file for a matching string: "This should be translated", and then changes it to whatever the other language's string would be e.g. French: "Cela devrait ĂȘtre traduit".
How can I then search for this text string which would be inbetween the brackets of translate()$t(...)? An example of such code would be:
infoBox(
translate()$t(
"Error"
),
subtitle = translate()$t(
"Failed to get this code to work"
),
icon = icon(
"thumbs-down",
lib = "glyphicon"
),
fill = TRUE,
color = "red"
)
)
but could also contain a paste0 function for longer strings. However, just being able to get the text between the brackets, regardless of whether paste0 is included would be super helpful.
infoBox(
translate()$t(
"Warning"
),
subtitle = translate()$t(
paste0(
"This is a very very long text string",
"it continues on, but already just being ",
"able to the text inbetween the translate ",
"brackets, regardless of whether it contains ",
"paste0 or not, would still be super helpful."
),
icon = icon(
"thumbs-down",
lib = "glyphicon"
),
fill = TRUE,
color = "red"
)
)
Ideally, I would like to get a dataframe containing all the text which I can use to search for matches in the translate.json file to see which ones are missing..
Please note, the code example I have above does not really work all that well. I cannot seem to get a very good working example...
Any advice would be GREATLY appreciated! Thank you in advance.
