Search code examples
gitangular-translateweblate

Weblate: Update base language file using POST_UPDATE_SCRIPT


In our AngularJS project, translation strings are marked using angular-translate's <translate> tag and extracted using gulp-angular-translate-extract. This is run automatically by Weblate using a POST_UPDATE_SCRIPT, so the developers shouldn't have extract strings manually.

This is the post update script:

#!/bin/bash
gulp --gulpfile gulp-i18n-extract.js

And for reference, this is the gulpfile:

#!/usr/bin/env gulp --gulpfile

'use strict';

var gulp = require('gulp'),
    angularTranslate = require('gulp-angular-translate-extract');

gulp.task('default', function() {
    return gulp.src('src/**/*.{html,js}')
        .pipe(angularTranslate({
            lang: ['en'],
            defaultLang: 'en',
            suffix: '.lang.json',
            safeMode: false,
            dest: './src/languages',
            stringifyOptions: true, // Sort alphabetically.
            verbose: false
        }))
        .pipe(gulp.dest('./src'));
});

The script is run and will extract the strings. So changes to the base language file are displayed in the Repository details view as pasted below:

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   src/languages/en.lang.json

no changes added to commit (use "git add" and/or "git commit -a")

My problem is that the changes are not noticed by Weblate, so in order to get updated strings into Weblate, I've had to manually run:

django-admin loadpo --force --all

Also, when I do commit changes, the base language file will not be committed.

What am I doing wrong here?


Solution

  • Weblate needs to see the file in the Git repository, it doesn't look for uncommited changes.

    So to fix this, commit the file to git in the hook as well:

    git commit -m 'Update source strings' src/languages/en.lang.json
    

    PS: I've updated the documentation to cover this as well.