diff --git a/inst/traduire/fr-translation.json b/inst/traduire/fr-translation.json index 845a1539..af8f66a7 100644 --- a/inst/traduire/fr-translation.json +++ b/inst/traduire/fr-translation.json @@ -148,7 +148,6 @@ "ART_CHILD": "Enfants sous TARV", "ART_ADULT_SEX_RATIO": "Rapport de masculinité des adultes TARV", "ART_CHILD_ADULT_RATIO": "Rapport enfant-adulte ART sous TARV", - "ANC_STATUS": "Statut connu de la CPN", "ANC_PREVALENCE": "Prévalence CPN", "ANC_ART_COVERAGE": "Couverture de TARV au CPN", "ART_NEW_TOTAL": "TARV (Nouveau)", @@ -254,7 +253,6 @@ "AWARE_PLHIV_PROP_RATIO": "Proportion de PVVIH conscients rapport", "INCIDENCE_RATIO": "Rapport d'incidence du VIH", "WARNING_PROGRAMME_DATA_NOT_EQUAL_TO_SPECTRUM": "Les données infranationales de Naomi ne correspondent pas aux données nationales de Spectrum. Vérifier le tableau de révision des intrants pour: \n{{years}}", - "WARNING_ADDITIONAL": "et {{count}} de plus", "PJNZ_INVALID_ZIP": "Le zip ne contient aucun fichier PJNZ", "ANC_PREVALENCE_AGE_MATCHED": "Prévalence CPN appariés par âge", "ANC_ART_COVERAGE_AGE_MATCHED": "Couverture de TARV au CPN appariés par âge", diff --git a/inst/traduire/pt-translation.json b/inst/traduire/pt-translation.json index add5e8a0..c797bfeb 100644 --- a/inst/traduire/pt-translation.json +++ b/inst/traduire/pt-translation.json @@ -148,7 +148,6 @@ "ART_CHILD": "crianças (<15) em TARV", "ART_ADULT_SEX_RATIO": "Relação homem com mulher em adultos no TARV", "ART_CHILD_ADULT_RATIO": "Relação criança-adulto da TARV", - "ANC_STATUS": "Estatuto conhecido do CPN", "ANC_PREVALENCE": "Prevalência do CPN", "ANC_ART_COVERAGE": "Cobertura TARV arte em CPN", "ART_NEW_TOTAL": "TARV (novo)", @@ -254,7 +253,6 @@ "AWARE_PLHIV_PROP_RATIO": "Proporção de PVVIH com conhecimento relação", "INCIDENCE_RATIO": "Incidência de VIH relação", "WARNING_PROGRAMME_DATA_NOT_EQUAL_TO_SPECTRUM": "Os dados subnacionais da Naomi não são iguais aos dados nacionais da Spectrum. Verificar a tabela de revisão de entradas para: \n{{years}}", - "WARNING_ADDITIONAL": "e {{count}} mais", "PJNZ_INVALID_ZIP": "O zip não contém ficheiros PJNZ", "ANC_PREVALENCE_AGE_MATCHED": "Prevalência do CPN idade compatível", "ANC_ART_COVERAGE_AGE_MATCHED": "Cobertura TARV em CPN idade compatível", diff --git a/scripts/collect_translations.R b/scripts/collect_translations.R new file mode 100755 index 00000000..77521523 --- /dev/null +++ b/scripts/collect_translations.R @@ -0,0 +1,85 @@ +#!/usr/bin/env Rscript + +## Run as ./collect_translations.R 2021-11-17 +## Date format is YYYY-MM-DD +args = commandArgs(trailingOnly=TRUE) +if (!is.null(args[1]) && !is.na(args[1])) { + from_date <- args[1] +} else { + from_date <- NULL +} + +files <- file.path("inst/traduire", list.files("inst/traduire")) + +## Helpers for reading file from git archive +`%||%` <- function(a, b) { + if (is.null(a)) b else a +} +system3 <- function(command, args) { + res <- suppressWarnings(system2(command, args, stdout = TRUE, stderr = TRUE)) + code <- attr(res, "status") %||% 0 + attr(res, "status") <- NULL + list(success = code == 0, + code = code, + output = res) +} +git_run <- function(args, root = NULL, check = FALSE) { + if (!is.null(root)) { + args <- c("-C", root, args) + } + res <- system3(git, args) + if (check && !res$success) { + stop(sprintf("Error code %d running command:\n%s", + res$code, paste0(" > ", res$output, collapse = "\n"))) + } + res +} +git_show <- function(path, date) { + path <- sprintf("HEAD@{%s}:./%s", date, path) + git <- unname(Sys.which("git")) + res <- system3(git, c("show", path)) + if (!res$success) { + stop(sprintf("Error code %d running command:\n%s", + res$code, paste0(" > ", res$output, collapse = "\n"))) + } + res$output +} + +yml <- lapply(files, function(file) { + lang <- strsplit(basename(file), "-")[[1]][1] + current_strings <- jsonlite::read_json(file) + d <- data.frame(names(current_strings), + unname(unlist(current_strings))) + colnames(d) <- c("key", lang) + d +}) + +if (!is.null(from_date)) { + old_yml <- lapply(files, function(file) { + lang <- strsplit(basename(file), "-")[[1]][1] + content <- git_show(file, from_date) + strings <- jsonlite::fromJSON(content, simplifyVector = FALSE) + d <- data.frame(names(strings), + unname(unlist(strings))) + colnames(d) <- c("key", lang) + d + }) + + yml <- Map(function(old, current) { + ## Keep rows from current not in old or if the value has changed + row.names(current) <- current$key + row.names(old) <- old$key + keys_out <- vapply(row.names(current), function(key) { + !(key %in% row.names(old)) || any(current[key, ] != old[key, ]) + }, logical(1)) + row.names(current) <- NULL + current[keys_out, ] + }, old_yml, yml) +} + +translations <- Reduce(function(x, y) merge(x, y, by = "key", all = TRUE), + yml, accumulate = FALSE) + +out <- sprintf("translations-%s.csv", Sys.Date()) +message(sprintf("Saving translations to %s", out)) +write.csv(translations, out, row.names = FALSE, na = "")