Skip to content

Refactor: Standardize parsers, improve GUI logic, and analyze enhance…#7

Closed
KhazP wants to merge 1 commit intorefactor/parser-gui-logic-analysisfrom
main
Closed

Refactor: Standardize parsers, improve GUI logic, and analyze enhance…#7
KhazP wants to merge 1 commit intorefactor/parser-gui-logic-analysisfrom
main

Conversation

@KhazP
Copy link
Copy Markdown
Owner

@KhazP KhazP commented May 29, 2025

…… (#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.

#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>
@KhazP KhazP closed this May 29, 2025
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.

1 participant