Day: July 28, 2014

  • Pre commit hook for PO files on git.gnome.org

    After a little pestering by André I’ve made the following changes regarding PO file checking on git.gnome.org:

    1. PO files are actually checked using msgfmt
    2. Added a simple check to ensure keyword header in .desktop is properly translated

    That PO files weren’t checked for syntax issues was pretty surprising for me, it seems no translator ever uploaded a PO file with a wrong syntax, else I assume the sysadmin team would’ve received a bugreport/ticket.

    The check for a properly translated keyword header is implemented using sed:

    sed -rn '/^#: [^\n]+\.desktop/{:start /\nmsgstr/!{N;b start};/\nmsgid [^\n]+;"/{/\nmsgstr [^\n]+;"/!p}}'

    Or in English: match from /^#: .*\.desktop/ until /\nmsgstr/. Then if there is a msgid ending with ";, check if there also is a msgstr ending with ;". If msgstr doesn’t end with ;" but all other conditions apply: print the buffer (so #: line up to msgstr). The git hook itself just looks if the output is empty or not.

    Example of the error message.

    $ git push
    Counting objects: 23, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done.
    Total 3 (delta 2), reused 0 (delta 0)
    remote: ---
    remote: The following translation (.po) file should ensure the translated content ends with a semicolon. (When updating branch 'master'.)
    remote:
    remote: po/sl.po
    remote:
    remote: The following part of the file fails to do this. Please correct the translation and try to push again.
    remote:
    remote: #: ../data/nautilus.desktop.in.in.h:3
    remote: msgid "folder;manager;explore;disk;filesystem;"
    remote: msgstr "mapa;upravljalnik;datoteke;raziskovalec;datotečni sistem;disk"
    remote:
    remote: After making fixes, modify your commit to include them, by doing:
    remote:
    remote: git add sl.po
    remote: git commit --amend
    remote:
    remote: If you have any further problems or questions, please contact the GNOME Translation Project mailing list <gnome-i18n@gnome.org>. Thank you.
    remote: ---
    To ssh://git.gnome.org/git/nautilus
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'ssh://git.gnome.org/git/nautilus'
    

    Note: explanation can probably be improved. The check is not just for Keywords, also for other things like e.g. mime types, etc.