1
+ # R script to translate the website contents from Japanese (JA) to English (EN)
2
+ # Actual translation takes place in PO files; everything else is automated
3
+
1
4
library(dovetail )
2
5
library(quarto )
3
-
6
+ library( gert )
4
7
source(" R/functions.R" )
5
8
6
- # Create ./locale/{lang} containing files needed for translation
7
- if (fs :: dir_exists(" local/en" )) fs :: dir_delete(" locale/en" ) # start clean
8
- create_locale(" en" )
9
+ # The English source files live in ./locale/en, which is itself a git repo
10
+ # hosted at
11
+ # https://github.com/swcarpentry-ja/en
12
+
13
+ # Clone the repo if it doesn't already exist
14
+ if (! fs :: dir_exists(" locale/en" )) {
15
+ git_clone(
16
+ " https://github.com/swcarpentry-ja/en" ,
17
+ path = " locale/en" )
18
+ }
19
+
20
+ # Sync any changes made to ./locale/en from the remote
21
+ git_pull(" origin" , repo = " locale/en" )
22
+
23
+ # Create ./locale/{lang} containing files needed for translation.
24
+ # Copies all untranslated files over to locale/{lang}, overwrites
25
+ # any existing translations.
26
+ swcja_create_locale(" en" )
27
+
28
+ # Copy localized files that don't get translated by PO
29
+ fs :: file_copy(
30
+ " assets/locale/en/_quarto.yml" ,
31
+ " locale/en/_quarto.yml" ,
32
+ overwrite = TRUE
33
+ )
34
+
35
+ # Create / update PO files
36
+ create_po(md_in = " index.qmd" , po = " po/en/index.po" )
37
+ create_po(md_in = " links.qmd" , po = " po/en/links.po" )
38
+ create_po(md_in = " quickguide.qmd" , po = " po/en/quickguide.po" )
39
+
40
+ # (edit PO files)
9
41
10
42
# Translate md files
11
43
translate_md(
12
44
md_in = " index.qmd" ,
13
45
po = " po/en/index.po" ,
14
46
md_out = " locale/en/index.qmd" )
15
47
16
- # Render translated webpage
17
- quarto_render(execute_dir = " locale/en" , as_job = FALSE )
48
+ translate_md(
49
+ md_in = " links.qmd" ,
50
+ po = " po/en/links.po" ,
51
+ md_out = " locale/en/links.qmd" )
52
+
53
+ translate_md(
54
+ md_in = " quickguide.qmd" ,
55
+ po = " po/en/quickguide.po" ,
56
+ md_out = " locale/en/quickguide.qmd" )
57
+
58
+ # Optional: render translated webpage for local viewing
59
+ quarto_render(execute_dir = " locale/en" , as_job = FALSE )
60
+
61
+ # Commit changes in English translation
62
+ git_add(" *" , repo = " locale/en" )
63
+ git_commit(" Update translations" , repo = " locale/en" )
64
+
65
+ # Push to the remote
66
+ git_push(" origin" , repo = " locale/en" )
0 commit comments