Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting changes to django translations (PO) files in TravisCI

I am using Django translations for a project, and would like to ensure, on TravisCI, that translations are not left behind when changes are made to translatable strings.

This is a simplified snippet of my .travis.yml:

script:
 - ...
 - python manage.py makemessages -l ja --no-wrap --no-location
 - git diff --exit-code

That recreates the PO files, and fails when the file changes. So far so good.

Unfortunately, django updates the POT-Creation-Date every time the script is run, and I can't see any flags to makemessages that would disable that, so even if there are no changes, the file changes on every run.

Am I on the right lines, or is there a better way to detect that there has been a change?

like image 684
meshy Avatar asked Oct 19 '22 18:10

meshy


2 Answers

So, after makemessages diff will allways show at least 1 insert and 1 deletion, right?

git diff --numstat | awk '{if ($1>1 || $2>1) { exit 1 } else { exit 0 }}'

This script should exit with status=1 if there is more than 1 insert and 1 deletion in diff.

like image 176
glyuck Avatar answered Oct 22 '22 22:10

glyuck


Git now has a nice way to ignore specific matches. The following line will fail if there is a diff, but exclude the problematic header:

git diff --ignore-matching-lines=POT-Creation-Date --exit-code

What's better, Django recently merged a change to stop this header from getting updated when there are no changes to the translations. It hasn't been released as of Django 4.0, so I expect it will arrive in Django 4.1.

See Django bug #6106 and the commit that fixes this issue.

like image 41
meshy Avatar answered Oct 22 '22 23:10

meshy