Last active
April 7, 2016 10:02
-
-
Save hualet/b99774c18751082592be8cee50edb770 to your computer and use it in GitHub Desktop.
Check translation comments on code review.
This file contains 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
#!/usr/bin/env python3 | |
import os | |
import sys | |
import polib | |
from xml.dom import minidom | |
from configparser import ConfigParser | |
PROJ_ROOT = "." | |
TX_CONFIG_FILE = os.path.join(PROJ_ROOT, ".tx/config") | |
tx_config = ConfigParser() | |
tx_config.read(TX_CONFIG_FILE) | |
def get_translation_type(): | |
return tx_config.get(tx_config.sections()[1], "type") | |
def get_source_file(): | |
return tx_config.get(tx_config.sections()[1], "source_file") | |
# QT related functions | |
def check_comments_qt(filename): | |
doc = minidom.parse(filename) | |
msgElements = doc.getElementsByTagName("message") | |
hasComment = lambda msg : len(msg.getElementsByTagName("extracomment")) > 0 | |
return all(map(hasComment, msgElements)) | |
# PO related functions | |
def check_comments_po(filename): | |
pot = polib.pofile(filename) | |
hasComment = lambda entry : entry.comment != "" | |
return all(map(hasComment, pot)) | |
if __name__ == "__main__": | |
return_value = 0 | |
translation_type = get_translation_type() | |
if translation_type == "QT": | |
if not check_comments_qt(get_source_file()): | |
return_value = -1 | |
elif translation_type == "PO": | |
if not check_comments_po(get_source_file()): | |
return_value = -1 | |
sys.exit(return_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment