Project

General

Profile

Bug #15568

Feature #10034: Translation web platform

Feature #15079: Integrate the platform with our Git and ikiwiki infrastructure

Feature #15077: Have a staging website to build planned languages, with a resilient build

Script create staging wiki with suggestions

Added by hefee over 1 year ago. Updated 5 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Internationalization
Target version:
Start date:
05/03/2018
Due date:
% Done:

100%

Feature Branch:
translate-server:master
Type of work:
Code
Blueprint:
Starter:
Affected tool:

Description

As we want the statging wiki with everything from weblate including suggestions, we need a script for it.


Related issues

Related to Tails - Bug #15679: update puppet-tails to have scripts in weblate vm Resolved 06/20/2018

History

#1 Updated by hefee over 1 year ago

A first version of the script:

#!/usr/bin/env python3

# This script generates a temporary copy of all translations encoded in a local git repository including suggestions.
# TMPDIR - the directory where the temporary copy of the git repository should be located
#
# KNOWN ISSUES:
#   * needs an inital copy of the tails repo under TMPDIR, as weblate creates some symbolic links and makes
#     the copying failing :(
#
# Usage:
#
#   WEBLATE_ROOT=/usr/local/share/weblate
#   SAVE_SUGGESTIONS=/mnt/save-suggestions.py
#   ${WEBLATE_ROOT}/manage.py shell < ${SAVE_SUGGESTIONS}

import os
import shutil
import pathlib

from weblate.trans.models import *

TMPDIR=pathlib.Path("/tmp/tails/")

#init tmpbuild directory
#   * the intial copy of the tails repo fails - as weblate creates some strange symbolic links
#sp = SubProject.objects.first()
#shutil.copytree(sp.full_path, str(TMPDIR))

len_subprojects = len(SubProject.objects.all())
for i, sp in enumerate(SubProject.objects.all()):
    print("[{}/{}] {}".format(i+1, len_subprojects, sp.name))
    for t in sp.translation_set.all():
        for u in t.unit_set.all():
            if u.suggestions:
                s = u.suggestions[0]
                print("({}) {} -> {}".format(t.language, u.target.encode(), s.target.encode()))
                # u.target = s.target #to "approve" suggestion

                #weblate/trans/models/translations.py: update_units
                pounit, add = t.store.find_unit(
                    u.context,
                    u.get_source_plurals()[0]
                )
                pounit.set_target(s.target)     # update po file with first suggestion

        #save with suggestions
        with (TMPDIR/t.filename).open('wb') as f:
            t.store.store.serialize(f)

#2 Updated by hefee over 1 year ago

  • Assignee changed from hefee to u

Please ask the author of weblate, if we can rely on the API we are using to create a tempary copy of the repo with suggestions included.

#3 Updated by hefee over 1 year ago

What we want to do if there are more than one suggestion?
I created the script to select the first suggestion (s = u.suggestions0), but is this the bahaviour we want?

#4 Updated by emmapeel over 1 year ago

  • Status changed from New to Confirmed

#5 Updated by u over 1 year ago

  • Category set to Internationalization
  • Target version set to Tails_3.8

#6 Updated by u over 1 year ago

@hefee: thanks! Can we agree to use named variables so that "t" would be called "translation" for example? I know it looks less optimized but I like to be able to read everything and not have to search my brain for what a variable means on every line :) I will send the email now.

#7 Updated by u over 1 year ago

hefee wrote:

What we want to do if there are more than one suggestion?
I created the script to select the first suggestion (s = u.suggestions0), but is this the bahaviour we want?

That's a bit weird indeed and I guess we should instead use the last suggestion: because if there is more than one it's because people like thought the previous ones were not suited enough.. But I agree this is also a bit weird.

We should verify if suggestions get deleted automatically in Weblate once the strings have been reviewed.

#9 Updated by u over 1 year ago

  • Status changed from Confirmed to In Progress
  • Assignee changed from u to hefee

#10 Updated by u over 1 year ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100
  • Feature Branch set to translate-server:master

Yaaaaay!

See
commit 6d97acc5e45a1ff4959998090f84b193797c801f
commit f27071020f710a6c81620e0bdad28336e64967df
commit 428dfa77f1743a0f58f87207746660953c94f519
commit 5b4811fc191c1deb90a3b866404439545a3c21d1

#11 Updated by hefee over 1 year ago

  • Related to Bug #15679: update puppet-tails to have scripts in weblate vm added

#12 Updated by emmapeel over 1 year ago

u wrote:

We should verify if suggestions get deleted automatically in Weblate once the strings have been reviewed.

Maybe they stay somewhere1, but they dissapear from the normal interface once they become accepted.

[1]There is a history table for each string where they can be accessed afterwards.

#13 Updated by intrigeri 5 months ago

  • Assignee deleted (hefee)

Also available in: Atom PDF