2021-05-10 13:26:30 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Safe Eyes is a utility to remind you to take break frequently
|
|
|
|
# to protect your eyes from eye strain.
|
|
|
|
|
|
|
|
# Copyright (C) 2021 Gobinath
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import polib
|
2023-08-03 17:16:06 +02:00
|
|
|
import sys
|
2021-05-10 13:26:30 +02:00
|
|
|
|
2023-08-03 17:16:06 +02:00
|
|
|
def validate_po(locale: str, path: str) -> bool:
|
|
|
|
success = True
|
2021-05-10 13:26:30 +02:00
|
|
|
po = polib.pofile(path)
|
|
|
|
for entry in po:
|
|
|
|
if entry.msgstr and (entry.msgid.count("%") != entry.msgstr.count("%")):
|
2023-08-03 17:16:06 +02:00
|
|
|
print("Number of variables mismatched in " + locale)
|
2021-05-10 13:26:30 +02:00
|
|
|
print(entry.msgid + " -> " + entry.msgstr)
|
|
|
|
print()
|
2023-08-03 17:16:06 +02:00
|
|
|
success = False
|
|
|
|
return success
|
2021-05-10 13:26:30 +02:00
|
|
|
|
2023-08-03 17:16:06 +02:00
|
|
|
success = True
|
2021-05-10 13:26:30 +02:00
|
|
|
locales = os.listdir('safeeyes/config/locale')
|
2023-08-03 17:16:06 +02:00
|
|
|
for locale in sorted(locales):
|
2021-05-10 13:26:30 +02:00
|
|
|
path = os.path.join('safeeyes/config/locale', locale, "LC_MESSAGES/safeeyes.po")
|
|
|
|
if os.path.isfile(path):
|
2023-08-03 17:16:06 +02:00
|
|
|
print('Validating translation %s...' % path)
|
|
|
|
success = validate_po(locale, path) and success
|
|
|
|
sys.exit(0 if success else 1)
|