Bug #15568

Script create staging wiki with suggestions

Added by hefee 2018-05-03 12:34:46 . Updated 2019-06-27 17:16:46 .

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

100%

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

Starter:
Affected tool:
Deliverable for:
309

Description

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


Subtasks


Related issues

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

History

#1 Updated by hefee 2018-05-03 12:36:24

A first version of the script:

<code class="python">
#!/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)

</code>

#2 Updated by hefee 2018-05-03 12:37:59

  • Assignee deleted (hefee)

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 2018-05-03 12:40:36

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

#4 Updated by emmapeel 2018-05-04 08:43:50

  • Status changed from New to Confirmed

#5 Updated by Anonymous 2018-05-05 14:32:25

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

#6 Updated by Anonymous 2018-05-05 14:37:08

@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 Anonymous 2018-05-05 14:39:12

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.suggestions[0]), 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.

#8 Updated by Anonymous 2018-05-16 15:18:48

  • Deliverable for set to Sponsor_L

#9 Updated by Anonymous 2018-05-29 10:27:03

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

#10 Updated by Anonymous 2018-05-29 12:52:14

  • 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 2018-06-20 15:14:53

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

#12 Updated by emmapeel 2018-06-29 08:55:30

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

Maybe they stay somewhere[1], 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 2019-06-27 17:16:46

  • Assignee deleted (hefee)