"text": "Quarterly patch for R Core\nNB: Weblate links below assume you’re logged in there, otherwise you’ll be redirected to the home page\n\nTo generate a report on the translation updates in a time period:\n\nVisit https://translate.rx.studio/projects/r-project/#reports\nSelect time period and generate report in rST format\nConvert ~markdown to HTML and share in the R Contributors slack group’s #core-translation channel\n\n\n\nTo submit a patch file on the translations found in Weblate but not in the trunk of the main R subversion repo:\nThe basic idea is to compare the Weblate repo (which copies the R subversion repo, but also adds translations provided via Weblate) to the “official” R sources; any difference in .po files should be submitted as a patch.\n\nMake sure the Weblate repo is fully up-to-date. Check status at https://translate.rx.studio/projects/r-project/#repository – be sure there are no Update or Commit actions needed.\nGet the two repos cloned on any machine. If this is your first time generating a patch on this machine:\nmkdir weblate-diff && cd weblate-diff\ngit clone -o weblate https://translate.rx.studio/git/r-project/base-r-gui/ . # remote #1: Weblate source\ngit remote add svn
[email protected]:r-devel/r-svn.git # remote #2: SVN source\ngit fetch svn main # retrieve the latest from SVN\nIf you’ve got the repo set up locally already, update:\ngit fetch svn main\ngit fetch weblate master\ngit reset --hard weblate/master # force-reset to match state on Weblate (usual caution with --hard applies)\nMake needed manual changes to reduce noise and ensure quality, e.g. something like:\nlibrary(data.table)\nlibrary(crayon)\nlibrary(logger)\n\npo_files <- \\() list.files(pattern = '\\\\.po$', recursive = TRUE)\n# pocount is available from e.g. 'apt install translate-toolkit'\npo_counts <- function(f) {\n x = fread(cmd = paste('pocount --csv', paste(f, collapse = \" \")), sep = ',', fill = TRUE)\n setnames(x, c(\"Filename\", \"Translated Messages\"), c(\"filename\", \"n_translated\"))\n x\n}\nset_branch <- \\(branch) system2('git', c('checkout', branch))\n\nset_branch('weblate/master')\npo_report <- tools::checkPoFiles(\"\")\nif (length(po_report)) {\n print(po_report)\n stop(\"Fix above issues in .po files identified by tools::checkPoFiles() to proceed.\")\n}\n\nweblate_summary <- po_counts(po_files())\nset_branch('svn/main')\nsvn_summary <- po_counts(po_files())\nset_branch('master')\n\n# SUMMARIZE the changed translations, and delete empty .po files\npo_summary <- merge(weblate_summary, svn_summary, by = \"filename\", all = TRUE, suffixes = c(\"_weblate\", \"_svn\"))\npo_summary[, package := basename(dirname(dirname(filename)))]\n# Drop empty & record files\npo_summary[n_translated_weblate == 0 & is.na(n_translated_svn), { # NB: keep empty files if they're already in SVN, hence is.na() check\n log_info('Dropping {.N} empty files:')\n .SD[, by = package, {\n log_level(INFO, 'From package {blue(.BY$package)}:')\n log_level(INFO, ' {toString(green(basename(filename)))}', .topenv = .SD) # NB: Need .SD since data.table doesn't pick up the variable from the string\n }]\n unlink(filename)\n NULL\n}]\npo_summary <- po_summary[n_translated_weblate > 0]\n\n# (optional) Summarize the update for the rest of the files\nsetnafill(po_summary, fill = 0L, cols = which(sapply(po_summary, is.numeric)))\npo_summary[, n_newly_translated := n_translated_weblate - n_translated_svn]\npo_summary[n_newly_translated > 0, {\n log_info('New translations in {.N} files')\n .SD[, by = package, {\n log_level(INFO, 'From package {blue(.BY$package)}:')\n log_level(INFO, ' {sprintf(\"%s [+%s]\", green(format(basename(filename))), red(format(n_newly_translated)))}', .topenv = .SD)\n }]\n NULL\n}]\n\n# REPLACE 'Report-Msgid-Bugs-To' metadata field pointing to #core-translation-po-bugs\nsystem2(\"sed\", c(\"-i\", \"'s/
[email protected]/bugs.r-project.org/'\", po_summary$filename))\n\n# CHECK msgfmt works -- 'make update*' commands run by R-core check this as well\ntmp <- tempfile()\n## NB: lapply() over for() to show all failures at once\nres <- suppressWarnings(lapply(\n po_summary$filename,\n \\(po_file) system2(\"msgfmt\", c(\"-c\", \"--statistics\", \"-o\", tmp, po_file), stdout=TRUE, stderr=TRUE)\n))\nfailed <- which(!sapply(res, \\(r) is.null(attr(r, \"status\"))))\nif (length(failed)) {\n cat(\"'msgfmt' failed for some .po files:\\n\")\n for (idx in failed) {\n cat(sprintf(\" %s:\\n\", red(po_summary$filename[idx])))\n writeLines(paste0(\" \", res[[idx]]))\n }\n}\nGenerate a patch file from the diff, going back to the most recent commit with translations merged, e.g.\n# NB: _not_ 'git diff weblate/master svn/main' since we've just deleted the empty .po files locally\ngit diff svn/main --no-prefix -- \"*.po\"\nShare the patch file on the R Contributors Slack group’s #core-translation channel and kindly ping @MichaelLawrence for his assistance on getting the patch file applied on the trunk of R dev to get it merged. We should do this ~once per quarter.",
0 commit comments