Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c259ee1

Browse files
Fix config generation script
1 parent 3554fc2 commit c259ee1

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.github/scripts/generate_tx_config.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Please note that this script requires a Transifex API token to run."""
2+
import glob
23
import subprocess
34
from functools import partial
45
from pathlib import Path
@@ -32,20 +33,33 @@ def add_files(version: str):
3233
def name_replacer(match: re.Match[str]):
3334
prefix, resource = match.group("prefix", "resource")
3435
override_prefix = prefix.replace("file_filter", "trans.zh_CN")
35-
override_resource = (
36+
pattern = (
3637
resource.replace("trans/<lang>/", "")
37-
.replace("--", "/")
3838
.replace("glossary_", "glossary")
39-
.replace("_", ".")
39+
.replace("--", "/")
40+
.replace("_", "?")
4041
)
41-
return f"{prefix}{resource}\n{override_prefix}{override_resource}"
42-
43-
44-
def patch_config():
42+
matches = list(glob.glob(pattern.replace(".po", ".rst")))
43+
if not matches:
44+
print("missing", pattern)
45+
return f"{prefix}{resource}\n{override_prefix}{pattern}"
46+
elif len(matches) == 1:
47+
filename = matches[0].replace(".rst", ".po").replace("\\", "/")
48+
else:
49+
raise ValueError("multi match", resource, pattern, matches)
50+
return f"{prefix}{resource}\n{override_prefix}{filename}"
51+
52+
53+
def patch_config(path: str):
4554
tx_config_path = Path(".tx", "config")
4655

4756
config_content = tx_config_path.read_text("utf-8")
57+
58+
cwd = os.getcwd()
59+
os.chdir(path)
4860
config_content = FILTER_PATTERN.sub(name_replacer, config_content)
61+
os.chdir(cwd)
62+
4963
tx_config_path.write_text(config_content, "utf-8")
5064

5165

@@ -55,13 +69,14 @@ def patch_config():
5569

5670
parser = ArgumentParser()
5771

58-
parser.add_argument("--token")
59-
parser.add_argument("--version")
72+
parser.add_argument("--token", required=True)
73+
parser.add_argument("--version", required=True)
74+
parser.add_argument("--doc-path", required=True)
6075

6176
params = parser.parse_args()
6277

6378
os.environ["TX_TOKEN"] = params.token
6479

6580
init_project()
6681
add_files(params.version)
67-
patch_config()
82+
patch_config(params.doc_path)

.github/scripts/update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
tx=$(realpath ./tx)
44
cd docs || exit 1
5-
$tx pull --languages "$LOCALE"
5+
$tx pull --languages "$LOCALE" -t --use-git-timestamps

0 commit comments

Comments
 (0)