Add function to compare translated strings between two commits #138
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import os | ||
| from pathlib import Path | ||
| import re | ||
|
|
||
| absolute_path = Path(__file__).resolve().parents[2] | ||
| pattern_translated_strings = r'Translated:\s+(\d+)' | ||
|
|
||
|
|
||
| def run_git_command(command): | ||
| try: | ||
| return os.popen(command).read() | ||
| except Exception as e: | ||
| print(f"Error executing Git command: {e}") | ||
| return "" | ||
|
|
||
|
|
||
| def get_translated_commit_strings(commit_hash): | ||
| try: | ||
| changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n") | ||
| changed_files.remove("") | ||
| changed_count = 0 | ||
| for file in changed_files: | ||
| file_path = absolute_path / file | ||
| output = os.popen(f"pocount {file_path}").read() | ||
| strings_match = re.search(pattern_translated_strings, output) | ||
| matched_strings = int(strings_match.group(1)) if strings_match else 0 | ||
| changed_count += matched_strings | ||
| return changed_count | ||
| except Exception as e: | ||
| print(f"Error getting translated strings count: {e}") | ||
| return 0 | ||
|
|
||
|
|
||
| def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2): | ||
| try: | ||
| commit_hash1_count = get_translated_commit_strings(commit_hash1) | ||
| commit_hash2_count = get_translated_commit_strings(commit_hash2) | ||
| return abs(commit_hash1_count - commit_hash2_count) | ||
|
||
| except Exception as e: | ||
| print(f"Error calculating the difference between translated strings counts: {e}") | ||
| return 0 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.