Skip to content

Commit

Permalink
add lint tool
Browse files Browse the repository at this point in the history
Signed-off-by: Lessica <[email protected]>
  • Loading branch information
Lessica committed Nov 18, 2024
1 parent 9de1f82 commit 5d89aa1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
18 changes: 18 additions & 0 deletions devkit/i18n-lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import os
import subprocess

def lint_strings_files(directory):
for root, _, files in os.walk(directory):
for file in files:
if file.endswith('.strings') or file.endswith('.stringsdict'):
file_path = os.path.join(root, file)
try:
subprocess.run(['plutil', '-lint', file_path], check=True)
print(f"Linting passed for {file_path}")
except subprocess.CalledProcessError:
print(f"Linting failed for {file_path}")

if __name__ == "__main__":
lint_strings_files('res')
25 changes: 21 additions & 4 deletions devkit/i18n-statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import matplotlib.pyplot as plt
import pathlib
import plistlib


lproj_base = pathlib.Path('res')
Expand All @@ -20,7 +21,7 @@
def get_lproj_path(lang) -> pathlib.Path:
return lproj_base / f'{lang}.lproj'

def get_lproj_strings_paths(lang) -> [pathlib.Path]:
def get_lproj_strings_paths(lang) -> list[pathlib.Path]:
return [
get_lproj_path(lang) / 'Localizable.strings',
get_lproj_path(lang) / 'InfoPlist.strings',
Expand All @@ -29,20 +30,36 @@ def get_lproj_strings_paths(lang) -> [pathlib.Path]:
def get_lproj_strings_count(lang) -> tuple[int, int]:
all_lines = []
for strings_path in get_lproj_strings_paths(lang):
if strings_path.exists():
with open(strings_path, 'r') as f:
all_lines.extend(f.readlines())
if not strings_path.exists():
continue
with open(strings_path, 'r') as f:
all_lines.extend(f.readlines())
todo_count = 0
for line in all_lines:
if line.find('/* TODO */') != -1 or line.find('/* Translated with ') != -1:
todo_count += 1
return int((len(all_lines) + 1) / 3), todo_count

def get_lproj_stringsdict_paths(lang) -> list[pathlib.Path]:
return [
get_lproj_path(lang) / 'Localizable.stringsdict',
]

def get_lproj_stringsdict_count(lang) -> int:
all_count = 0
for stringsdict_path in get_lproj_stringsdict_paths(lang):
if not stringsdict_path.exists():
continue
stringsdict = plistlib.load(open(stringsdict_path, 'rb'))
all_count += len(stringsdict)
return all_count

if __name__ == '__main__':
x_labels = available_languages
y_values = []
for lang in available_languages:
total, todo = get_lproj_strings_count(lang)
total += get_lproj_stringsdict_count(lang)
percent = (total - todo) / total
y_values.append((lang, percent, total - todo, total))
print(f'{lang}: {total - todo}/{total} translated, {percent * 100:.2f}%')
Expand Down
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contourpy==1.3.1
cycler==0.12.1
fonttools==4.55.0
kiwisolver==1.4.7
matplotlib==3.9.2
numpy==2.1.3
packaging==24.2
pillow==11.0.0
pyparsing==3.2.0
python-dateutil==2.9.0.post0
six==1.16.0
Binary file modified res/stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5d89aa1

Please sign in to comment.