<commit_before>import os
import io
import shutil

def strSplit(str):
    result = []
    ind1 = str.find('"')
    ind2 = str.find('"', ind1+1)
    result.append(str[ind1+1:ind2])
    ind3 = str.find('"', ind2+1)
    indLast = str.rfind('"')
    result.append(str[ind3+1:indLast])
    return result
def sortByAlphabet(inputStr):
    return inputStr.lower()

app_names = ['documenteditor', 'presentationeditor', 'spreadsheeteditor']
app_types = ['embed', 'main', 'mobile']
prefix_apps = '../apps/'
prefix_src = 'src/'
prefix_dest = 'dest/'
str_apps = []
langs = []
for i in range(len(app_names)):
    for j in range (len(app_types)):
        locale_path = prefix_apps + app_names[i] + '/' + app_types[j] + '/locale/'
        src_path = prefix_src + app_names[i] + '/' + app_types[j] + '/locale/'
        dest_path = prefix_dest + app_names[i] + '/' + app_types[j] + '/locale/'
        print(locale_path)
        if os.path.isdir(locale_path):
            langs = os.listdir(locale_path)
            if not os.path.isdir(dest_path):
                os.makedirs(dest_path)
            if len(langs)>0:
                try:
                    f = io.open(locale_path + 'en.json', mode='r', encoding='utf-8')
                except Exception:
                    continue
                lines = f.readlines()
                f.close()
                str_apps = []
                for k in range(1, len(lines)-1):
                    arr = strSplit(lines[k])
                    if len(arr) > 0:
                        str_apps.append(arr[0])
                str_apps.sort(key=sortByAlphabet)
                for l in range(len(langs)):
                    lang = langs[l].split('.')[0]
                    f = io.open(locale_path + lang+ '.json', mode='r', encoding='utf-8')
                    lines = f.readlines()
                    f.close()
                    try:
                        f = io.open(src_path + lang+ '.json', mode='r', encoding='utf-8')
                    except Exception:
                        f.close()
                        f = io.open(dest_path + lang + '.json', mode='w', encoding='utf-8')
                        f.writelines(lines)
                        f.close()
                        print('    ' + lang+ '.json - copied')
                        continue
                    d_locale = dict()
                    d_src = dict()
                    # locale
                    for k in range(1, len(lines)-1):
                        arr = strSplit(lines[k])
                        if len(arr) > 1:
                            d_locale[arr[0]] = arr[1]
                    # src
                    lines = f.readlines()
                    for k in range(1, len(lines)-1):
                        arr = strSplit(lines[k])
                        if len(arr) > 1:
                            d_src[arr[0]] = arr[1]
                    f.close()
                    f = io.open(dest_path + lang + '.json', mode='w', encoding='utf-8')
                    f.write(u'{')
                    f.write(u'\n')
                    changed = 'not changed'
                    isFirst = True
                    arr_len = len(str_apps)
                    for k in range(arr_len):
                        str = str_apps[k]
                        if str.find('del_')==0:
                            continue
                        if str in d_src:
                            changed = 'changed'
                            str = '  "' + str + '": "' + d_src[str] + '"'
                            if isFirst:
                                isFirst = False
                            else:
                                f.write(u',\n')
                            f.write(str)
                        elif str in d_locale:
                            str = '  "' + str + '": "' + d_locale[str] + '"'
                            if isFirst:
                                isFirst = False
                            else:
                                f.write(u',\n')
                            f.write(str)
                    f.write(u'\n')
                    f.write(u'}')
                    f.close()
                    print('    ' + lang + '.json - ' + changed)
            if os.path.isdir(src_path):
                add_langs = os.listdir(src_path)
                for l in range(len(langs)):
                    add_langs.remove(langs[l])
                for l in range(len(add_langs)):
                    lang = add_langs[l]
                    shutil.copyfile(src_path + lang, dest_path + lang)
                    print('    ' + lang + ' - ' + 'added')<commit_msg>Fix script for translations<commit_after>import os
import io
import shutil

def strSplit(str):
    result = []
    ind1 = str.find('"')
    ind2 = str.find('"', ind1+1)
    result.append(str[ind1+1:ind2])
    ind3 = str.find('"', ind2+1)
    indLast = str.rfind('"')
    result.append(str[ind3+1:indLast])
    return result
def sortByAlphabet(inputStr):
    return inputStr.lower()

app_names = ['documenteditor', 'presentationeditor', 'spreadsheeteditor']
app_types = ['embed', 'main', 'mobile']
prefix_apps = '../apps/'
prefix_src = 'src/'
prefix_dest = 'dest/'
str_apps = []
langs = []
for i in range(len(app_names)):
    for j in range (len(app_types)):
        locale_path = prefix_apps + app_names[i] + '/' + app_types[j] + '/locale/'
        src_path = prefix_src + app_names[i] + '/' + app_types[j] + '/locale/'
        dest_path = prefix_dest + app_names[i] + '/' + app_types[j] + '/locale/'
        print(locale_path)
        if os.path.isdir(locale_path):
            langs = os.listdir(locale_path)
            if not os.path.isdir(dest_path):
                os.makedirs(dest_path)
            if len(langs)>0:
                try:
                    f = io.open(locale_path + 'en.json', mode='r', encoding='utf-8')
                except Exception:
                    continue
                lines = f.readlines()
                f.close()
                str_apps = []
                for k in range(1, len(lines)-1):
                    arr = strSplit(lines[k])
                    if len(arr) > 0:
                        str_apps.append(arr[0])
                str_apps.sort(key=sortByAlphabet)
                for l in range(len(langs)):
                    lang = langs[l].split('.')[0]
                    f = io.open(locale_path + lang+ '.json', mode='r', encoding='utf-8')
                    lines = f.readlines()
                    f.close()
                    try:
                        f = io.open(src_path + lang+ '.json', mode='r', encoding='utf-8')
                    except Exception:
                        f.close()
                        f = io.open(dest_path + lang + '.json', mode='w', encoding='utf-8')
                        f.writelines(lines)
                        f.close()
                        print('    ' + lang+ '.json - copied')
                        continue
                    d_locale = dict()
                    d_src = dict()
                    # locale
                    for k in range(1, len(lines)-1):
                        arr = strSplit(lines[k])
                        if len(arr) > 1:
                            d_locale[arr[0]] = arr[1]
                    # src
                    lines = f.readlines()
                    for k in range(1, len(lines)-1):
                        arr = strSplit(lines[k])
                        if len(arr) > 1:
                            d_src[arr[0]] = arr[1]
                    f.close()
                    f = io.open(dest_path + lang + '.json', mode='w', encoding='utf-8')
                    f.write(u'{')
                    f.write(u'\n')
                    changed = 'not changed'
                    isFirst = True
                    arr_len = len(str_apps)
                    for k in range(arr_len):
                        str = str_apps[k]
                        if str.find('del_')==0:
                            continue
                        if str in d_src:
                            changed = 'changed'
                            str = '  "' + str + '": "' + d_src[str] + '"'
                            if isFirst:
                                isFirst = False
                            else:
                                f.write(u',\n')
                            f.write(str)
                        elif str in d_locale:
                            str = '  "' + str + '": "' + d_locale[str] + '"'
                            if isFirst:
                                isFirst = False
                            else:
                                f.write(u',\n')
                            f.write(str)
                    f.write(u'\n')
                    f.write(u'}')
                    f.close()
                    print('    ' + lang + '.json - ' + changed)
            if os.path.isdir(src_path):
                add_langs = os.listdir(src_path)
                for l in range(len(langs)):
                    if add_langs.count(langs[l])>0:
			add_langs.remove(langs[l])
                for l in range(len(add_langs)):
                    lang = add_langs[l]
                    shutil.copyfile(src_path + lang, dest_path + lang)
                    print('    ' + lang + ' - ' + 'added')
{'fraction_non_alphanumeric': 0.12711225917554622, 'fraction_numerical': 0.007426541814659348, 'mean_word_length': 1.0235191637630663, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379557', 'n_tokens_mistral': 2675, 'n_tokens_neox': 2527, 'n_words': 518}