-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_progress.R
61 lines (47 loc) · 1.99 KB
/
check_progress.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# script to check progress for a given language ---------------------------
library(tibble)
library(purrr)
get_po_status <- function(pot_file, lang) {
# define matching po_file file
po_file <- paste0(lang, ".po")
if (grepl("RGui.*", pot_file)) po_file <- paste0("RGui-", po_file)
if (grepl("R-.*", pot_file)) po_file <- paste0("R-", po_file)
po_file <- file.path(dirname(pot_file), po_file)
if (!file.exists(po_file)){
return(tibble(pot = pot_file,
n = NA,
translated = NA,
fuzzy = NA))
}
txt <- readLines(po_file, encoding = "UTF-8")
# get lines for untranslated and (potentially) translated strings
msg_id <- grep("^msgid ", txt)[-1]
msgstr_id <- grep('^msgstr( \\"|\\[0).*', txt)[-1]
# split text into entries for each message
new_entry <- which(txt == "")
n_lines <- diff(c(0, new_entry, length(txt)))
grp <- rep.int(x = seq(0, length(n_lines) - 1), times = n_lines)
entries <- split(txt, grp)[-1]
# ignore old messages
any_grepl <- function(x, pattern) any(grepl(pattern, x))
old <- vapply(entries, any_grepl, logical(1), "#~")
entries <- entries[!old]
# fuzzy translations
fuzzy <- vapply(entries, any_grepl, logical(1), "^#,.*fuzzy.*")
# translated messages
translated <- grepl('\\".+\\"', txt[msgstr_id]) |
grepl('\\".+\\"', txt[msgstr_id + 1])
# summarise
tibble(pot = pot_file,
n = length(entries),
translated = mean(translated),
fuzzy = mean(fuzzy))
}
# set language code -------------------------------------------------------
# https://www.phpkb.com/kb/article/iso-639-1-standard-language-codes-255.html
if (interactive()) lang <- "es"
# get current status-------------------------------------------------------
pot <- list.files(pattern = paste0("*[.]pot$"), recursive = TRUE)
po_status <- map_df(pot, get_po_status, lang = lang)
if (interactive()) View(po_status)
if (!interactive()) po_status