-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor i18-checks to use YAML, modularize utils, and fix errors #7
Refactor i18-checks to use YAML, modularize utils, and fix errors #7
Conversation
…e correct directory
…ng direct directory reads with YAML-configured paths, and fixing bugs so the project initially works.
Thank you for the pull request! ❤️The i18n-check team will do our best to address your contribution as soon as we can. If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the |
Maintainer ChecklistThe following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)
|
Nice, @OmarAI2003! First glance, this is looking really great 😊 I'll try to bring this in before the sync tomorrow and then we can discuss next steps! |
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.
Writing out some notes as I go through the changes, @OmarAI2003:
- I'd suggest getting your IDE set up with the ruff (edit: ruff, not black) code formatter and also to install the extension (if you already have this done, then check your settings)
- Imports weren't sorted and there were some formatting changes that can happen automatically on save
- Set formatting to run on save, if you don't have that, and also on paste so that code you get from elsewhere is automatically formatted
Installing ruff will also lint the code, which will tell you when you have unused imports and other things like that :) |
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.
This is looking great so far, @OmarAI2003 :) Can I ask you to look through the comments I made and the changes I sent along in my commit so you can familiarize yourself with the changes? 😊 I'll make a suggestion on which issue to work on next in the issues 🚀
) | ||
en_us_json_dict = read_json_file(en_us_json_file) | ||
|
||
files_to_check =collect_files(frontend_directory, file_types_to_check, directories_to_skip, files_to_skip) |
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.
Let's always do explicit function arguments as it makes it easier for others who don't know what the function does to see what the purpose is. Even if it's just repeating the argument as we use the same name, it still makes it more clear what the argument is being used for :)
.i18n-check.yaml
Outdated
@@ -5,6 +5,7 @@ src-dir: tests | |||
i18n-dir: tests/test_frontend/test_i18n | |||
i18n-src: tests/test_frontend/test_i18n/test-i18n-src.json | |||
i18n-map: tests/test_frontend/test-i18n-map.ts | |||
types_dir: src\i18n_check\types |
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.
I don't think we'll need this, as the i18n-map
object location should come directly from the YAML i18n-map
value :)
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.
I'll remove this and the file.
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.
The usages of this can all be replaced with i18n_map_file
from utils :)
src/i18n_check/utils.py
Outdated
""" | ||
Reads a JSON file and returns its content. | ||
Parameters: |
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.
Let's be sure to follow the formatting for the function docstrings :)
src/i18n_check/utils.py
Outdated
Parameters | ||
---------- | ||
p : list str |
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.
list[str]
src/i18n_check/utils.py
Outdated
i18n_check_dir = str(Path(config["i18n-dir"]).resolve()) | ||
json_file_directory = Path(config["i18n-dir"]).resolve() | ||
frontend_directory = Path(config["src-dir"]).resolve() | ||
en_us_json_file = Path(config["i18n-src"]).resolve() |
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.
Let's remember that en-US might not be the src language for other projects, and also we might expand this out to work for other file types eventually :) Will rename this accordingly.
src/i18n_check/utils.py
Outdated
|
||
# MARK: collecting File | ||
|
||
def collect_files(directory, file_types, directories_to_skip, files_to_skip): |
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.
Let's also remember to type the arguments for functions :)
# MARK: YAML Reading | ||
|
||
# Define the path to the YAML configuration file | ||
config_path = Path(__file__).parent.parent.parent / ".i18n-check.yaml" |
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.
There's a chance that this is going to be more robust. Specifically we need to figure out how other CLIs find their specific YAML files. The CLI should search the directory where the code is being called, odds are, but we can do this later :)
Parameters | ||
---------- | ||
p : list str | ||
p : list[str] | ||
The string of the directory path of a file that has a key. |
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.
I think this part should be changed to
p : str
The directory path of a file that contains a key.
Since p
is a plain string, not a list. You can see this from the loop variable c in for i, c in enumerate(p):
, where c
represents individual characters in the inputted p
parameter
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.
Ah ok, nice :) Feel free to revert this in the next PR!
I had Ruff installed as well as its extension, but maybe I wasn't warned by Ruff when I did the commit because I didn't run |
Could be the case, @OmarAI2003 :) Maybe also set up format on save? It'll get figured out eventually :) |
Contributor checklist
Description
This PR refactors the i18n check scripts by improving modularity, introducing YAML-based configuration, and ensuring full project functionality.
[utils.py](http://utils.py/)
to improve maintainability..i18n-check.yaml
, making the scripts more flexible.i18n-map.ts
file with structured key mappings.types_dir
path in.i18n-check.yaml
to ensure scripts locate the correct directories.Related issue
utility.py
#6