Skip to content

Commit 3b74ea2

Browse files
committed
Update translation script
should be completely automated now
1 parent 93ee991 commit 3b74ea2

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

R/translate.R

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,66 @@
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+
14
library(dovetail)
25
library(quarto)
3-
6+
library(gert)
47
source("R/functions.R")
58

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)
941

1042
# Translate md files
1143
translate_md(
1244
md_in = "index.qmd",
1345
po = "po/en/index.po",
1446
md_out = "locale/en/index.qmd")
1547

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

Comments
 (0)