Skip to content

Commit f449e20

Browse files
Merge pull request #29 from r-devel/MichaelChirico-patch-1
Update instructions for generating a patch
2 parents 43c1318 + c3d9a50 commit f449e20

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

web/Weblate-server.qmd

+54-26
Original file line numberDiff line numberDiff line change
@@ -131,50 +131,78 @@ 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
2. Select time period and generate report in rST format
138138
3. 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:
141+
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+
2. 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+
```
141152

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-
2. Clone the weblate git repo from <https://translate.rx.studio/git/r-project/base-r-gui/>
144153
3. Drop empty translation files 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+
set_branch('weblate/master')
170+
weblate_summary <- po_counts(po_files())
171+
set_branch('svn/master')
172+
svn_summary <- po_counts(po_files())
173+
set_branch('master')
174+
175+
po_summary <- merge(weblate_summary, svn_summary, by = "filename", all = TRUE, suffixes = c("_weblate", "_svn"))
176+
po_summary[, package := basename(dirname(dirname(filename)))]
177+
# Drop empty & record files
178+
po_summary[n_translated_weblate == 0, {
179+
log_info('Dropping {.N} empty files:')
180+
.SD[, by = package, {
181+
log_level(INFO, 'From package {blue(.BY$package)}:')
182+
log_level(INFO, ' {toString(green(basename(filename)))}', .topenv = .SD) # NB: Need .SD since data.table doesn't pick up the variable from the string
183+
}]
184+
unlink(filename)
185+
NULL
186+
}]
187+
po_summary <- po_summary[n_translated_weblate > 0]
188+
189+
# (optional) Summarize the update for the rest of the files
190+
setnafill(po_summary, fill = 0L, cols = which(sapply(po_summary, is.numeric)))
191+
po_summary[, n_newly_translated := n_translated_weblate - n_translated_svn]
192+
po_summary[n_newly_translated > 0, {
193+
log_info('New translations in {.N} files')
194+
.SD[, by = package, {
195+
log_level(INFO, 'From package {blue(.BY$package)}:')
196+
log_level(INFO, ' {sprintf("%s [+%s]", green(format(basename(filename))), red(format(n_newly_translated)))}', .topenv = .SD)
197+
}]
198+
}]
169199
```
170200

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

176203
```sh
177-
git diff --no-prefix 366f45a4599e04e00df59d063c67ccfadf27ae96
204+
# NB: _not_ 'git diff weblate/master svn/master' since we've just deleted the empty .po files locally
205+
git diff svn/master --no-prefix -- "*.po"
178206
```
179207

180208
8. 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)