Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Pass whole chapter for translation #41

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions d2lbook/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@

def translate():
parser = argparse.ArgumentParser(description='Translate to another language')
parser.add_argument('filename', nargs='+', help='the markdown files to activate')
# Example usage: d2lbook translate --commit 35a64ab chapter_optimization chapter_computer-vision/anchor.md
AnirudhDagar marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('name', nargs='+', help='chapter dirs or markdown files to activate')
AnirudhDagar marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--commit', default='latest', help='the commit of the base repo')
args = parser.parse_args(sys.argv[2:])

cf = config.Config()
trans = Translate(cf, args.commit)
for fn in args.filename:
trans.translate(fn)
for name in args.name:
# Check if name is a file or a chapter dir
if not name.endswith(".md"):
chap_name = name
AnirudhDagar marked this conversation as resolved.
Show resolved Hide resolved
chap_dir = os.path.join(trans.repo_dir, chap_name)
if os.path.isdir(chap_dir):
logging.info(f'Translating all sections of {chap_name}')
all_chap_sec = os.listdir(chap_dir)
AnirudhDagar marked this conversation as resolved.
Show resolved Hide resolved
for sec_name in all_chap_sec:
if sec_name.endswith(".md"):
trans.translate(os.path.join(chap_name, sec_name))
else:
logging.error(f'Invalid Directory {chap_name}: Please provide'
'a valid chapter name for translation')
else:
trans.translate(name)

class Translate(object):
def __init__(self, cf: config.Config, commit: str):
Expand Down