Пример #1
0
    def __init__(self, master):
        tk.Frame.__init__(self, master=master)
        title = tk.Label(master=self, text=u"中文JSON:")
        jfile = ui.FileOpenUI(master=self,
                              file_types=[("Json File", "*.json")],
                              base_root=lambda: config.json_root(),
                              title=u"中文JSON")
        title3_1 = tk.Label(master=self, text=u"忽略的表:")
        input3_1 = tk.Text(master=self, width=80, height=10)
        pickbtn = tk.Button(
            master=self,
            text="提取",
            command=lambda: self.skip_language(jfile.get_value(), input3_1))
        row = 0
        title.grid(row=row, column=0, columnspan=6, sticky=tk.W)
        row += 1
        jfile.grid(row=row, column=0, columnspan=6, sticky=tk.EW)
        # btn1_2.grid(row = row, column = 6, sticky = tk.EW, padx = 5)

        row += 1
        title3_1.grid(row=row, column=0, sticky=tk.W)
        row += 1
        input3_1.grid(row=row, column=0, columnspan=6, sticky=tk.NSEW)
        row += 1
        pickbtn.grid(row=row, column=0, sticky=tk.W)
Пример #2
0
    def skip_language(self, jsonfilename, input_ui):
        root = self.winfo_toplevel()
        dbnamestring = input_ui.get("0.0", tk.END).strip()
        if jsonfilename == "" or not os.path.isfile(jsonfilename):
            MsgBox.showerror(u"错误", u"请选择一个json文件")
            return
        elif dbnamestring == "":
            MsgBox.showerror(u"错误", u"请输入要忽略的表名,用','隔开")
            return
        else:
            dbnames = dbnamestring.split(",")
            with open(jsonfilename, "r", encoding='UTF-8') as f:
                jdata = json.load(f)
                lanlist = jdata['data']

                def passed(item):
                    return item != None and item['table_name'] not in dbnames

                slimlist = [item for item in lanlist if passed(item)]
                jdata['data'] = slimlist
                (_, file_name) = os.path.split(jsonfilename)
                # (short_name, _) = os.path.splitext(file_name)
                save_dir = Dialog.asksaveasfilename(
                    master=root,
                    filetypes=[("Json File", "*.json")],
                    title="请选择保存json文件的路径",
                    initialdir=config.json_root(),
                    initialfile=file_name)
                if save_dir == "":
                    sytlog.log(u'取消\n')
                    return
                (save_dir, file_name) = os.path.split(save_dir)
                (short_name, _) = os.path.splitext(file_name)
                save_full_name = os.path.join(save_dir, short_name + ".json")
                with open(save_full_name, "w", encoding='UTF-8') as f:
                    json.dump(jdata,
                              f,
                              separators=(',', ':'),
                              ensure_ascii=False)
                    sytlog.log(u"成功.\n")


# if __name__ == "__main__":
#     DiffLan(TkinterDnD.Tk(), u"抽取未翻译的原文")
Пример #3
0
 def __init__(self, master):
     tk.Frame.__init__(self, master=master)
     title1_2 = tk.Label(master=self, text="Excel:")
     file1_2 = tk.StringVar(value="")
     input1_2 = tk.Entry(master=self, textvariable=file1_2, width=80)
     btn1_2 = tk.Button(master=self,
                        text="打开",
                        command=lambda: viewtool.set_json_dir(
                            self.winfo_toplevel(),
                            file1_2,
                            filetypes=[("Excel File", "*.xlsx")],
                            title="翻译文件",
                            initialdir=config.excel_root()))
     title2_2 = tk.Label(master=self, text="Json:")
     file2_2 = tk.StringVar(value="")
     input2_2 = tk.Entry(master=self, textvariable=file2_2, width=80)
     btn2_2 = tk.Button(master=self,
                        text="打开",
                        command=lambda: viewtool.set_json_dir(
                            self.winfo_toplevel(),
                            file2_2,
                            filetypes=[("Json File", "*.json")],
                            title="中文json",
                            initialdir=config.json_root()))
     pickbtn = tk.Button(
         master=self,
         text="清理",
         command=lambda: self.slim_language(file1_2, file2_2))
     row = 0
     title1_2.grid(row=row, column=0, columnspan=6, sticky=tk.W)
     row += 1
     input1_2.grid(row=row, column=0, columnspan=6)
     btn1_2.grid(row=row, column=6, sticky=tk.EW, padx=5)
     row += 1
     title2_2.grid(row=row, column=0, columnspan=6, sticky=tk.W)
     row += 1
     input2_2.grid(row=row, column=0, columnspan=6)
     btn2_2.grid(row=row, column=6, sticky=tk.EW, padx=5)
     row += 1
     pickbtn.grid(row=row, column=0, sticky=tk.W)
Пример #4
0
Файл: views.py Проект: j-som/syt
    def __init__(self, parent):
        tkinter.Frame.__init__(self, master = parent)
        root = self.winfo_toplevel()
        title2_1 = tkinter.Label(master=self, text = u"待翻译json文件:")
        file2_1 = tkinter.StringVar(value = "")
        self._jsonfile = file2_1
        input2_1 = tkinter.Entry(master=self, textvariable=file2_1)
        viewtool.bind_drop(input2_1)
        command = lambda : viewtool.set_json_dir(root, file2_1, filetypes=[("Json File", "*.json")], title=u"待翻译json", initialdir=config.json_root())
        btn2_1 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
        row = 0
        title2_1.grid(row = row, column = 0, sticky = tkinter.W)
        row += 1
        input2_1.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
        btn2_1.grid(row = row, column = 6, sticky = tkinter.EW, padx = 5)

        title2_2 = tkinter.Label(master=self, text = u"新译文:")
        file2_2 = tkinter.StringVar(value = "")
        self._excelfilenew = file2_2
        input2_2 = tkinter.Entry(master=self, textvariable=file2_2, width = 80)
        viewtool.bind_drop(input2_2)
        command = lambda : viewtool.set_json_dir(root, file2_2, filetypes=[("Excel File", "*.xlsx")], title=u"新译文", initialdir=config.excel_root())
        btn2_2 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
        row += 1
        title2_2.grid(row = row, column = 0, sticky = tkinter.W)
        row += 1
        input2_2.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
        btn2_2.grid(row = row, column = 6, sticky = tkinter.EW, padx = 5)

        title3_2 = tkinter.Label(master=self, text = u"旧译文:(可选,假如存在,则会把json中的旧译文替换成新译文)")
        file3_2 = tkinter.StringVar(value = "")
        self._excelfileold = file3_2
        input3_2 = tkinter.Entry(master=self, textvariable=file3_2, width = 80)
        viewtool.bind_drop(input3_2)
        command = lambda : viewtool.set_json_dir(root, file3_2, filetypes=[("Excel File", "*.xlsx")], title=u"旧译文", initialdir=config.excel_root())
        btn3_2 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
        row += 1
        title3_2.grid(row = row, column = 0, sticky = tkinter.W, columnspan = 6)
        row += 1
        input3_2.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
        btn3_2.grid(row = row, column = 6, sticky = tkinter.EW, padx = 5)

        transbtn = tkinter.Button(master=self, text=u"翻译", command=self.translate)
        row += 1
        transbtn.grid(row = row, column = 2, sticky = tkinter.EW)
Пример #5
0
Файл: views.py Проект: j-som/syt
 def translate(self):
     root = self.winfo_toplevel()
     jsonfilename = self._jsonfile.get()
     if jsonfilename == "" or not os.path.isfile(jsonfilename):
         MsgBox.showerror(u"错误", u"请选择一个json文件")
         return
     else:
         with open(jsonfilename, "r", encoding='UTF-8') as f:
             jdata = json.load(f)
         lanlist = jdata['data']
         translateapi.translate2tw(lanlist)
         (_, file_name) = os.path.split(jsonfilename)
         # (short_name, _) = os.path.splitext(file_name)
         save_dir = Dialog.asksaveasfilename(master = root, filetypes=[("Json File", "*.json")], title = u"请选择保存json文件的路径", initialdir = config.json_root(), initialfile = file_name)
         if save_dir == "":
             sytlog.log(u'取消\n')
             return
         (save_dir, file_name) = os.path.split(save_dir)
         (short_name, _) = os.path.splitext(file_name)
         save_full_name = os.path.join(save_dir, short_name + ".json")
         with open(save_full_name, "w", encoding='UTF-8') as f:
             json.dump(jdata, f, separators=(',',':'), ensure_ascii=False)
             sytlog.log(u"翻译完成.\n")
Пример #6
0
Файл: views.py Проект: j-som/syt
 def __init__(self, parent):
     tkinter.Frame.__init__(self, master = parent)
     root = self.winfo_toplevel()
     title2_1 = tkinter.Label(master=self, text = u"待翻译json文件:")
     file2_1 = tkinter.StringVar(value = "")
     self._jsonfile = file2_1
     input2_1 = tkinter.Entry(master=self, textvariable=file2_1, width = 80)
     viewtool.bind_drop(input2_1)
     command = lambda : viewtool.set_json_dir(root, file2_1, filetypes=[("Json File", "*.json")], title=u"待翻译json", initialdir=config.json_root())
     btn2_1 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
     row = 0
     title2_1.grid(row = row, column = 0, sticky = tkinter.W)
     row += 1
     input2_1.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
     btn2_1.grid(row = row, column = 6, sticky = tkinter.EW, padx = 5)
     transbtn = tkinter.Button(master=self, text=u"机译", command=self.translate)
     row += 1
     transbtn.grid(row = row, column = 2, sticky = tkinter.EW)
     title3_1 = tkinter.Label(master=self, text = u"原文:")
     # self._srcword = file3_1
     input3_1 = tkinter.Text(master=self, width = 80, height = 10)
     command = lambda : sytlog.log(translateapi.twconvertor.convert(input3_1.get("0.0", tkinter.END)))
     btn3_1 = tkinter.Button(master=self, text=u"翻译", command=command, width = 10)
     row += 1
     title3_1.grid(row = row, column = 0, sticky = tkinter.W)
     row += 1
     input3_1.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.NSEW)
     btn3_1.grid(row = row, column = 6, sticky = tkinter.EW, padx = 5)
Пример #7
0
Файл: views.py Проект: j-som/syt
    def update(self):
        root = self.winfo_toplevel()
        jsonfilename = self._jsonfile.get()
        if jsonfilename == "" or not os.path.isfile(jsonfilename):
            MsgBox.showerror(u"错误", u"请选择一个json文件")
            return
        else:
            excelfilename = self._excelfilenew.get()
            excelfilename2 = self._excelfileold.get()
            if excelfilename == "" or not os.path.isfile(excelfilename) or excelfilename2 == "" or not os.path.isfile(excelfilename2):
                MsgBox.showerror(u"错误", u"请选择好Excel文件")
                return 
            sytlog.log(u"开始更新\n")
            with open(jsonfilename, "r", encoding='UTF-8') as f:
                jdata = json.load(f)

            lanlist = jdata['data']
            ref_workbook=openpyxl.load_workbook(excelfilename, read_only = True)
            ws = ref_workbook[ref_workbook.sheetnames[0]]# index为0为第一张表 
            dictionary = translateapi.excel_to_dict(ws)
            ref_workbook.close()
            ref_workbook = openpyxl.load_workbook(excelfilename2, read_only = True)
            ws = ref_workbook[ref_workbook.sheetnames[0]]
            old_dict = translateapi.excel_to_dict(ws)
            ref_workbook.close()
            update_dict = translateapi.make_update_dict(old_dict, dictionary)
            if len(update_dict) > 0:
                newlist = translateapi.update_with_dict(lanlist, update_dict)
                if len(newlist) > 0:
                    jdata['data'] = newlist
                    (_, file_name) = os.path.split(jsonfilename)
                    # (short_name, _) = os.path.splitext(file_name)
                    save_dir = Dialog.asksaveasfilename(master = root, filetypes=[("Json File", "*.json")], title = "请选择保存json文件的路径", initialdir = config.json_root(), initialfile = file_name)
                    if save_dir == "":
                        sytlog.log(u'取消\n')
                        return
                    (save_dir, file_name) = os.path.split(save_dir)
                    (short_name, _) = os.path.splitext(file_name)
                    save_full_name = os.path.join(save_dir, short_name + ".json")
                    with open(save_full_name, "w", encoding='UTF-8') as f:
                        json.dump(jdata, f, separators=(',',':'), ensure_ascii=False)
                        sytlog.log(u"更新完成.\n")
                else:
                    sytlog.log(u"找不到更新的译文\n" + str(update_dict.keys()) + '\n')
            else:
                sytlog.log(u"无更新的译文\n")
Пример #8
0
Файл: views.py Проект: j-som/syt
 def __init__(self, parent):
     tkinter.Frame.__init__(self, master = parent)
     title1_1 = tkinter.Label(master=self, text = u"提取json源文件:")
     file1_1 = tkinter.StringVar(value = "")
     input1_1 = tkinter.Entry(master=self, textvariable=file1_1, width = 80)
     viewtool.bind_drop(input1_1)
     command = lambda : viewtool.set_json_dir(self.winfo_toplevel(), file1_1, filetypes=[("Json File", "*.json")], title=u"文件源json", initialdir=config.json_root())
     btn1_1 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
     title1_2 = tkinter.Label(master=self, text = u"排除译文(可选,设置该路径将排除掉该Excel中已有的中文):")
     file1_2 = tkinter.StringVar(value = "")
     input1_2 = tkinter.Entry(master=self, textvariable=file1_2, width = 80)
     viewtool.bind_drop(input1_2)
     command = lambda : viewtool.set_json_dir(self.winfo_toplevel(), file1_2, filetypes=[("Excel File", "*.xlsx")], title=u"翻译文件", initialdir=config.excel_root())
     btn1_2 = tkinter.Button(master=self, text=u"打开", command=command, width = 10)
     pickbtn = tkinter.Button(master=self, text=u"提取", command=self.pick_cn)
     row = 0    
     title1_1.grid(row = row, column = 0, sticky = tkinter.W)
     row += 1
     input1_1.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
     btn1_1.grid(row = row, column = 10, sticky = tkinter.EW, padx = 5)
     row += 1
     title1_2.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.W)
     row += 1
     input1_2.grid(row = row, column = 0, columnspan = 6, sticky = tkinter.EW)
     btn1_2.grid(row = row, column = 10, sticky = tkinter.EW, padx = 5)
     row += 1
     pickbtn.grid(row = row, column = 2, sticky = tkinter.EW)
     self._jsonfile = file1_1
     self._excelfile = file1_2