-
Notifications
You must be signed in to change notification settings - Fork 98
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- When adding new features, please be careful about all relevant dependencies, such as modifying line 12:
parser.add_argument('filename', nargs='+', help='the markdown files to activate')
- Be consistent in variable names, such as
chapter_dir
-> chap_dir,all_ch_sections
-> all_chap_sections - Use meaningful variable names to improve readability. In just a few weeks, it would probably take you time to figure out what
os.path.join(fn, file)
means :) Making code more readable will eventually pay off - Although the existing code base does not always follow best practices, let's try to enforce it whenever we can, such as adding more comments and keeping each line <= 80 chars.
Last, please consider adding example use cases with inputs and expected outputs in this PR. It is like describing your proposed new feature. It will also remind you of your current assumptions/expectations (e.g., assuming md files only, not other extensions), which may be helpful for troubleshooting in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cheungdaven please take a look.
It looks good to me. @astonzhang @AnirudhDagar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll fixe two additional cosmetic issues later.
@@ -9,14 +9,28 @@ | |||
|
|||
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 | |||
parser.add_argument('source', nargs='+', help='chapter dirs or markdown files to activate') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dirs -> directories
if sec_name.endswith(".md"): | ||
trans.translate(os.path.join(source, sec_name)) | ||
else: | ||
logging.error(f'Invalid Directory {source}: Please provide' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory -> directory
This PR adds the ability to pass a whole chapter name instead of passing single sections for translation.
Note that #40 needs to be merged before this works correctly.
Example Use Case:
d2lbook translate --commit 35a64ab chapter_optimization chapter_computer-vision/anchor.md
This will translate all sections in chapter optimization and only the anchor section in chapter computer vision.