-
-
Notifications
You must be signed in to change notification settings - Fork 40
Add function to compare translated strings between two commits #138
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
base: 3.12
Are you sure you want to change the base?
Changes from 1 commit
240fb08
e608405
c1a0135
f5e5051
bbc6015
a77da15
1ad887c
964d587
10000
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rffontenelle faz sentido esse abs aqui? Esse commits tanto podem ser novas strings quanto strings traduzidas, certo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faz sentido, me esqueci que poderiam chegar novas strings There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neste caso específico, acredito que "se negativo, retorna 0" seria mais adequado. Significa, provavelmente, que temos novas strings não traduzidas |
||
except Exception as e: | ||
print(f"Error calculating the difference between translated strings counts: {e}") | ||
return 0 |
Uh oh!
There was an error while loading. Please reload this page.