Skip to content

Commit b93a111

Browse files
Merge branch 'main' into simple-numbering
2 parents 2373044 + 2fceb33 commit b93a111

File tree

1 file changed

+59
-26
lines changed

1 file changed

+59
-26
lines changed

web/Weblate-server.qmd

+59-26
Original file line numberDiff line numberDiff line change
@@ -131,50 +131,83 @@ docker-compose -f docker-compose-https.yml -f docker-compose-https.override.yml
131131

132132
_NB: Weblate links below assume you're logged in there, otherwise you'll be redirected to the home page_
133133

134-
To generate a report on the translation updates in a time period:
134+
### To generate a report on the translation updates in a time period:
135135

136136
1. Visit <https://translate.rx.studio/projects/r-project/#reports>
137137
1. Select time period and generate report in rST format
138138
1. Convert ~markdown to HTML and share in the R Contributors slack group's #core-translation channel
139139

140-
To submit a patch file on the translations found in Weblate but not in the trunk of the main R subversion repo:
140+
### To submit a patch file on the translations found in Weblate but not in the trunk of the main R subversion repo:
141141

142-
1. (_if necessary, i.e., there are any "Missing commits in the Weblate repository"_) Update the weblate repo from Subversion at <https://translate.rx.studio/projects/r-project/#repository>
143-
1. Clone the weblate git repo from <https://translate.rx.studio/git/r-project/base-r-gui/>
144-
1. Drop empty translation files to reduce noise, e.g. something like:
142+
The 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.
143+
144+
1. Make 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.
145+
1. Get the two repos cloned on any machine:
146+
147+
```sh
148+
git clone -o weblate https://translate.rx.studio/git/r-project/base-r-gui/ # remote #1: Weblate source
149+
git remote add svn git remote add svn [email protected]:r-devel/r-svn.git # remote #2: SVN source
150+
git fetch svn master # retrieve the latest from SVN
151+
```
152+
153+
1. Revert unwanted changes to reduce noise, e.g. something like:
145154

146155
```r
147156
library(data.table)
157+
library(crayon)
148158
library(logger)
149159
150-
last_commit <- '...'
151-
po_files <- \() list.files(pattern = '\\.po$', recursive = TRUE, full.names = TRUE)
160+
po_files <- \() list.files(pattern = '\\.po$', recursive = TRUE)
161+
# pocount is available from e.g. 'apt install translate-toolkit'
162+
po_counts <- function(f) {
163+
x = fread(cmd = paste('pocount --csv', paste(f, collapse = " ")), sep = ',', fill = TRUE)
164+
setnames(x, c("Filename", "Translated Messages"), c("filename", "n_translated"))
165+
x
166+
}
152167
set_branch <- \(branch) system2('git', c('checkout', branch))
153168
154-
new_files <- po_files()
155-
set_branch(last_commit)
156-
old_files <- po_files()
157-
set_branch('main')
158-
159-
added_files <- setdiff(new_files, old_files)
160-
161-
for (f in added_files) {
162-
if (fread(cmd = paste('pocount --csv', f), sep = ',', fill = TRUE)$`Translated Messages` == 0) {
163-
log_info('dropping empty {f}')
164-
unlink(f)
165-
} else {
166-
log_info('keeping {f}')
167-
}
168-
}
169+
# SUMMARIZE the changed translations, and delete empty .po files
170+
set_branch('weblate/master')
171+
weblate_summary <- po_counts(po_files())
172+
set_branch('svn/master')
173+
svn_summary <- po_counts(po_files())
174+
set_branch('master')
175+
176+
po_summary <- merge(weblate_summary, svn_summary, by = "filename", all = TRUE, suffixes = c("_weblate", "_svn"))
177+
po_summary[, package := basename(dirname(dirname(filename)))]
178+
# Drop empty & record files
179+
po_summary[n_translated_weblate == 0, {
180+
log_info('Dropping {.N} empty files:')
181+
.SD[, by = package, {
182+
log_level(INFO, 'From package {blue(.BY$package)}:')
183+
log_level(INFO, ' {toString(green(basename(filename)))}', .topenv = .SD) # NB: Need .SD since data.table doesn't pick up the variable from the string
184+
}]
185+
unlink(filename)
186+
NULL
187+
}]
188+
po_summary <- po_summary[n_translated_weblate > 0]
189+
190+
# (optional) Summarize the update for the rest of the files
191+
setnafill(po_summary, fill = 0L, cols = which(sapply(po_summary, is.numeric)))
192+
po_summary[, n_newly_translated := n_translated_weblate - n_translated_svn]
193+
po_summary[n_newly_translated > 0, {
194+
log_info('New translations in {.N} files')
195+
.SD[, by = package, {
196+
log_level(INFO, 'From package {blue(.BY$package)}:')
197+
log_level(INFO, ' {sprintf("%s [+%s]", green(format(basename(filename))), red(format(n_newly_translated)))}', .topenv = .SD)
198+
}]
199+
NULL
200+
}]
201+
202+
# REPLACE 'Report-Msgid-Bugs-To' metadata field pointing to #core-translation-po-bugs
203+
system2("sed", c("-i", "'s/[email protected]/bugs.r-project.org/'", po_summary$filename))
169204
```
170205

171-
1. Clone the subversion R repo or its git clone from `[email protected]:wch/r-source.git`
172-
1. Make sure that both repos are up-to-date!
173-
1. Copy over `src/library` from the weblate repo to R/trunk.
174206
1. Generate a patch file from the diff, going back to the most recent commit with translations merged, e.g.
175207

176208
```sh
177-
git diff --no-prefix 366f45a4599e04e00df59d063c67ccfadf27ae96
209+
# NB: _not_ 'git diff weblate/master svn/master' since we've just deleted the empty .po files locally
210+
git diff svn/master --no-prefix -- "*.po"
178211
```
179212

180213
1. Share 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

Comments
 (0)