<commit_before>#!/usr/bin/python

'''
Usage:

    updateTranslations.py LANGCODE [LANGCODE LANGCODE...]

Example:

    ./updateTranslations.py [-d <directory>] fr nl pt_BR

This command must be run from its current source tree location (/src/Tools)
so it can find the correct places to put the translation files. The
latest translations from crowdin will be downloaded, unzipped and put to
the correct locations. The necessary renaming of files and .qm generation
will be taken care of, but no resource file or other stuff will be done,
only the correct copying of .ts and .qm files.

NOTE! The crowdin site only allows to download "builds" (zipped archives)
which must be built prior to downloading. This means a build might not
reflect the latest state of the translations. Better make a build before
using this script!
'''

import sys, os, shutil, tempfile, zipfile, getopt, StringIO
import xml.sax, xml.sax.handler, xml.sax.xmlreader


crowdinpath = "http://crowdin.net/download/project/freecad.zip"

locations = [["Assembly","../Mod/Assembly/Gui/Resources/translations"],
             ["Complete","../Mod/Complete/Gui/Resources/translations"],
             ["draft","../Mod/Draft/Resources/translations"],
             ["Drawing","../Mod/Drawing/Gui/Resources/translations"],
             ["Fem","../Mod/Fem/Gui/Resources/translations"],
             ["FreeCAD","../Gui/Language"],
             ["Image","../Mod/Image/Gui/Resources/translations"],
             ["Mesh","../Mod/Mesh/Gui/Resources/translations"],
             ["MeshPart","../Mod/MeshPart/Gui/Resources/translations"],
             ["Part","../Mod/Part/Gui/Resources/translations"],
             ["PartDesign","../Mod/PartDesign/Gui/Resources/translations"],
             ["Points","../Mod/Points/Gui/Resources/translations"],
             ["Raytracing","../Mod/Raytracing/Gui/Resources/translations"],
             ["ReverseEngineering","../Mod/ReverseEngineering/Gui/Resources/translations"],
             ["Robot","../Mod/Robot/Gui/Resources/translations"],
             ["Sketcher","../Mod/Sketcher/Gui/Resources/translations"]]

tweaks = [["pt-BR","pt"],["es-ES","es"],["sv-SE","se"],["zh-CN","zh"]]

# SAX handler to parse the subversion output
class SvnHandler(xml.sax.handler.ContentHandler):
    def __init__(self):
        self.is_versioned = True

    def startElement(self, name, attributes):
        if name == "wc-status":
            if attributes["item"] == "unversioned":
                self.is_versioned = False

def doFile(tsfilepath,targetpath,lncode):
    "treats a single file"<commit_msg>+ updated crowdin update script with latest modules<commit_after>#!/usr/bin/python

'''
Usage:

    updateTranslations.py [options] LANGCODE [LANGCODE LANGCODE...]

Example:

    ./updateTranslations.py [-d <directory>] fr nl pt_BR

Options:

    -d : specifies a directory containing the freecad.zip file.
    
This command must be run from its current source tree location (/src/Tools)
so it can find the correct places to put the translation files. The
latest translations from crowdin will be downloaded, unzipped and put to
the correct locations. The necessary renaming of files and .qm generation
will be taken care of, but no resource file or other stuff will be done,
only the correct copying of .ts and .qm files.

NOTE! The crowdin site only allows to download "builds" (zipped archives)
which must be built prior to downloading. This means a build might not
reflect the latest state of the translations. Better make a build before
using this script!

You can specify a directory with the -d option if you already downloaded
and the build.
'''

import sys, os, shutil, tempfile, zipfile, getopt, StringIO
import xml.sax, xml.sax.handler, xml.sax.xmlreader


crowdinpath = "http://crowdin.net/download/project/freecad.zip"

locations = [["Assembly","../Mod/Assembly/Gui/Resources/translations"],
             ["Complete","../Mod/Complete/Gui/Resources/translations"],
             ["draft","../Mod/Draft/Resources/translations"],
             ["Drawing","../Mod/Drawing/Gui/Resources/translations"],
             ["Fem","../Mod/Fem/Gui/Resources/translations"],
             ["FreeCAD","../Gui/Language"],
             ["Image","../Mod/Image/Gui/Resources/translations"],
             ["Mesh","../Mod/Mesh/Gui/Resources/translations"],
             ["MeshPart","../Mod/MeshPart/Gui/Resources/translations"],
             ["Part","../Mod/Part/Gui/Resources/translations"],
             ["PartDesign","../Mod/PartDesign/Gui/Resources/translations"],
             ["Points","../Mod/Points/Gui/Resources/translations"],
             ["Raytracing","../Mod/Raytracing/Gui/Resources/translations"],
             ["ReverseEngineering","../Mod/ReverseEngineering/Gui/Resources/translations"],
             ["Robot","../Mod/Robot/Gui/Resources/translations"],
             ["Sketcher","../Mod/Sketcher/Gui/Resources/translations"],
             ["Arch","../Mod/Arch/Resources/translations"],
             ["StartPage","../Mod/Start/Gui/Resources/translations"],
             ["Test","../Mod/Test/Gui/Resources/translations"]]

tweaks = [["pt-BR","pt"],["es-ES","es"],["sv-SE","se"],["zh-CN","zh"]]

# SAX handler to parse the subversion output
class SvnHandler(xml.sax.handler.ContentHandler):
    def __init__(self):
        self.is_versioned = True

    def startElement(self, name, attributes):
        if name == "wc-status":
            if attributes["item"] == "unversioned":
                self.is_versioned = False

def doFile(tsfilepath,targetpath,lncode):
    "treats a single file"
{'fraction_non_alphanumeric': 0.15034086831718693, 'fraction_numerical': 0.0, 'mean_word_length': 3.1204730229120474, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055976', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1553, 'n_words': 409}