Refactor: Standardize parsers, improve GUI logic, and analyze enhance…#7
Closed
KhazP wants to merge 1 commit intorefactor/parser-gui-logic-analysisfrom
Closed
Refactor: Standardize parsers, improve GUI logic, and analyze enhance…#7KhazP wants to merge 1 commit intorefactor/parser-gui-logic-analysisfrom
KhazP wants to merge 1 commit intorefactor/parser-gui-logic-analysisfrom
Conversation
#5) Refactor: Standardize parsers, improve GUI logic, and analyze enhancements This commit incorporates a series of refactoring changes and analyses aimed at improving the Localization Comparison Tool's codebase and user experience. Key changes include: 1. **Parser Standardization:** * Introduced a `BaseParser` abstract base class. * Defined custom error types (`ParsingError`, `UnsupportedFormatError`) in `core/errors.py`. * Refactored all existing file parsers in `parsers/` to inherit from `BaseParser`, implement a consistent interface (`parse`, `get_supported_extensions`), and use standardized error handling. * Implemented dynamic parser discovery (`get_available_parsers`, `get_parser_for_file` in `parsers/__init__.py`) and updated `FileProcessingService` to use this mechanism, removing hardcoded parser instantiation. 2. **Improved Parser Testability:** * Added comprehensive unit tests for `JsonParser` in `tests/test_json_parser.py`, covering valid inputs, malformed files, edge cases, and error conditions. This serves as a template for testing other parsers. 3. **`GUI/logic.py` Refactoring:** * Significantly reduced the complexity of `GUI/logic.py` by relocating general utility and core logic functions to more appropriate modules: * `core/comparison_service.py`: For comparison logic (`compare_translations`). * `utils/string_utils.py`: For placeholder extraction and validation. * `utils/translation_service.py`: For machine translation integration. * `utils/exporter_service.py`: For saving/exporting translations. * `utils/git_utils.py` (and `utils/file_utils.py` conceptually, though I used git_utils for `get_file_content`): For file operations. * Updated call sites for these moved functions. 4. **Analysis for Large File Handling:** * Produced a report (`optimizing_large_files_report.md`) outlining strategies for handling very large localization files. This includes identifying problematic formats (JSON, XML, YAML), suggesting stream-based parsing libraries (e.g., `ijson`, `xml.etree.ElementTree.iterparse`), and proposing potential modifications to the `BaseParser` interface and comparison logic to support iterative processing. 5. **Analysis for GUI Diff View Enhancement:** * Produced a design document (`gui_enhancement_diff_view_design.md`) for a detailed diff view for modified strings. This recommends using Python's `difflib` module and proposes a Flet UI design involving an `AlertDialog` with side-by-side `flet.Text` controls styled using `TextSpan` to highlight character-level or word-level differences. These changes improve modularity, testability, maintainability, and provide a clear path for future performance and GUI enhancements. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…… (#5)
Refactor: Standardize parsers, improve GUI logic, and analyze enhancements
This commit incorporates a series of refactoring changes and analyses aimed at improving the Localization Comparison Tool's codebase and user experience.
Key changes include:
Parser Standardization:
BaseParserabstract base class.ParsingError,UnsupportedFormatError) incore/errors.py.parsers/to inherit fromBaseParser, implement a consistent interface (parse,get_supported_extensions), and use standardized error handling.get_available_parsers,get_parser_for_fileinparsers/__init__.py) and updatedFileProcessingServiceto use this mechanism, removing hardcoded parser instantiation.Improved Parser Testability:
JsonParserintests/test_json_parser.py, covering valid inputs, malformed files, edge cases, and error conditions. This serves as a template for testing other parsers.GUI/logic.pyRefactoring:GUI/logic.pyby relocating general utility and core logic functions to more appropriate modules:core/comparison_service.py: For comparison logic (compare_translations).utils/string_utils.py: For placeholder extraction and validation.utils/translation_service.py: For machine translation integration.utils/exporter_service.py: For saving/exporting translations.utils/git_utils.py(andutils/file_utils.pyconceptually, though I used git_utils forget_file_content): For file operations.Analysis for Large File Handling:
optimizing_large_files_report.md) outlining strategies for handling very large localization files. This includes identifying problematic formats (JSON, XML, YAML), suggesting stream-based parsing libraries (e.g.,ijson,xml.etree.ElementTree.iterparse), and proposing potential modifications to theBaseParserinterface and comparison logic to support iterative processing.Analysis for GUI Diff View Enhancement:
gui_enhancement_diff_view_design.md) for a detailed diff view for modified strings. This recommends using Python'sdifflibmodule and proposes a Flet UI design involving anAlertDialogwith side-by-sideflet.Textcontrols styled usingTextSpanto highlight character-level or word-level differences.These changes improve modularity, testability, maintainability, and provide a clear path for future performance and GUI enhancements.