Skip to content

Commit 240fb08

Browse files
committed
Add function to compare translated strings between two commits
1 parent 69ff2f8 commit 240fb08

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
from pathlib import Path
3+
import re
4+
5+
absolute_path = Path(__file__).resolve().parents[2]
6+
pattern_translated_strings = r'Translated:\s+(\d+)'
7+
8+
9+
def run_git_command(command):
10+
try:
11+
return os.popen(command).read()
12+
except Exception as e:
13+
print(f"Error executing Git command: {e}")
14+
return ""
15+
16+
17+
def get_translated_commit_strings(commit_hash):
18+
try:
19+
changed_files = run_git_command(f"git diff-tree --no-commit-id --name-only {commit_hash} -r").split("\n")
20+
changed_files.remove("")
21+
changed_count = 0
22+
for file in changed_files:
23+
file_path = absolute_path / file
24+
output = os.popen(f"pocount {file_path}").read()
25+
strings_match = re.search(pattern_translated_strings, output)
26+
matched_strings = int(strings_match.group(1)) if strings_match else 0
27+
changed_count += matched_strings
28+
return changed_count
29+
except Exception as e:
30+
print(f"Error getting translated strings count: {e}")
31+
return 0
32+
33+
34+
def get_difference_between_translated_commits_strings(commit_hash1, commit_hash2):
35+
try:
36+
commit_hash1_count = get_translated_commit_strings(commit_hash1)
37+
commit_hash2_count = get_translated_commit_strings(commit_hash2)
38+
return abs(commit_hash1_count - commit_hash2_count)
39+
except Exception as e:
40+
print(f"Error calculating the difference between translated strings counts: {e}")
41+
return 0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy