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

Conversation

AnirudhDagar
Copy link
Member

@AnirudhDagar AnirudhDagar commented Jan 7, 2022

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.

Copy link
Member

@astonzhang astonzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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')
  2. Be consistent in variable names, such as chapter_dir -> chap_dir, all_ch_sections -> all_chap_sections
  3. 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
  4. 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.

d2lbook/translate.py Outdated Show resolved Hide resolved
Copy link
Member

@astonzhang astonzhang left a 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.

d2lbook/translate.py Outdated Show resolved Hide resolved
d2lbook/translate.py Show resolved Hide resolved
d2lbook/translate.py Outdated Show resolved Hide resolved
d2lbook/translate.py Outdated Show resolved Hide resolved
d2lbook/translate.py Outdated Show resolved Hide resolved
@cheungdaven
Copy link
Member

It looks good to me. @astonzhang @AnirudhDagar

Copy link
Member

@astonzhang astonzhang left a 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')
Copy link
Member

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directory -> directory

@astonzhang astonzhang merged commit c7aa08e into master Jan 12, 2022
@AnirudhDagar AnirudhDagar deleted the translate-feat-chapter-arg branch June 30, 2022 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants