diff --git a/RichSpan.py b/RichSpan.py index 7a9f52d..78fb905 100644 --- a/RichSpan.py +++ b/RichSpan.py @@ -1,5 +1,6 @@ import base64 import datetime +import locale import mimetypes import os import sys @@ -8,7 +9,6 @@ import chardet import mammoth import psutil -import qtawesome as qta from langdetect import DetectorFactory, detect from PySide6.QtCore import * from PySide6.QtGui import * @@ -35,7 +35,7 @@ "isSaved": None, "scrollPosition": None, "appTheme": "light", - "appLanguage": "English", + "appLanguage": "1252", "adaptiveResponse": 1, "readFilter": "General File (*.rsdoc *.docx);;HTML (*.html);;Text (*.txt);;Key-Value (*.ini);;LOG (*.log);;JavaScript Object Notation (*.json);;Extensible Markup Language (*.xml);;Javascript (*.js);;Cascading Style Sheets (*.css);;Structured Query Language (*.sql);;Markdown (*.md)", "writeFilter": "RichSpan Document (*.rsdoc);;HTML (*.html);;Text (*.txt);;Key-Value (*.ini);;LOG (*.log);;JavaScript Object Notation (*.json);;Extensible Markup Language (*.xml);;Javascript (*.js);;Cascading Style Sheets (*.css);;Structured Query Language (*.sql);;Markdown (*.md)", @@ -43,6 +43,24 @@ } +# Locale ID (LCID) +languages = { + "1252": "English", + "1031": "Deutsch", + "1034": "Español", + "1055": "Türkçe", + "1068": "Azərbaycanca", + "1091": "Uzbek", + "2052": "中文", # Chinese + "1042": "한국어", # Korean + "1041": "日本語", # Japanese + "1025": "العربية", # Saudi Arabia + "1049": "Русский", # Russia + "1036": "Français", + "1032": "Ελληνικά", # Greek +} + + class RS_Threading(QThread): update_signal = Signal() @@ -87,7 +105,7 @@ def __init__(self, parent=None): f"{app.applicationDisplayName()}

" "Real-time computing and formatting supported word processor

" "Made by Berkay Gediz

" - "GNU General Public License v3.0
GNU LESSER GENERAL PUBLIC LICENSE v3.0
Mozilla Public License Version 2.0

Libraries: mwilliamson/python-mammoth, Mimino666/langdetect, PySide6, chardet, psutil, qtawesome

" + "GNU General Public License v3.0
GNU LESSER GENERAL PUBLIC LICENSE v3.0
Mozilla Public License Version 2.0

Libraries: mwilliamson/python-mammoth, Mimino666/langdetect, PySide6, chardet, psutil

" "OpenGL: ON" ) self.setCentralWidget(self.about_label) @@ -96,16 +114,17 @@ def __init__(self, parent=None): class RS_Workspace(QMainWindow): def __init__(self, parent=None): super(RS_Workspace, self).__init__(parent) - self.setWindowIcon(QIcon("richspan_icon.ico")) - self.setWindowModality(Qt.WindowModality.ApplicationModal) - self.setMinimumSize(768, 540) QTimer.singleShot(0, self.initUI) def initUI(self): starttime = datetime.datetime.now() + self.setWindowIcon(QIcon("richspan_icon.ico")) + self.setWindowModality(Qt.WindowModality.ApplicationModal) + self.setMinimumSize(768, 540) + system_language = locale.getlocale()[1] settings = QSettings("berkaygediz", "RichSpan") - if settings.value("appLanguage") == None: - settings.setValue("appLanguage", "English") + if system_language not in languages.keys(): + settings.setValue("appLanguage", "1252") settings.sync() if settings.value("adaptiveResponse") == None: settings.setValue("adaptiveResponse", 1) @@ -187,9 +206,8 @@ def closeEvent(self, event): event.accept() def RS_changeLanguage(self): - language = self.language_combobox.currentText() settings = QSettings("berkaygediz", "RichSpan") - settings.setValue("appLanguage", language) + settings.setValue("appLanguage", self.language_combobox.currentData()) settings.sync() self.RS_updateTitle() self.RS_updateStatistics() @@ -260,7 +278,7 @@ def RS_updateStatistics(self): lowercase_count = sum(1 for char in text if char.islower()) statistics += f"{translations[settings.value('appLanguage')]['analysis_message_3'].format(uppercase_count)}" statistics += f"{translations[settings.value('appLanguage')]['analysis_message_4'].format(lowercase_count)}" - if word_count > 8: + if word_count > 20: try: DetectorFactory.seed = 0 lang = detect(text) @@ -308,7 +326,7 @@ def RS_saveState(self): settings.setValue( "appTheme", "dark" if self.palette() == self.dark_theme else "light" ) - settings.setValue("appLanguage", self.language_combobox.currentText()) + settings.setValue("appLanguage", self.language_combobox.currentData()) settings.setValue("adaptiveResponse", self.adaptiveResponse) settings.sync() @@ -319,7 +337,8 @@ def RS_restoreState(self): self.file_name = settings.value("fileName") self.rs_area.setHtml(settings.value("content")) self.is_saved = settings.value("isSaved") - self.language_combobox.setCurrentText(settings.value("appLanguage")) + index = self.language_combobox.findData(settings.value("appLanguage")) + self.language_combobox.setCurrentIndex(index) if self.geometry is not None: self.restoreGeometry(self.geometry) @@ -455,6 +474,18 @@ def RS_toolbarTranslate(self): self.theme_action.setStatusTip( translations[settings.value("appLanguage")]["darklight_message"] ) + self.powersaveraction.setText( + translations[settings.value("appLanguage")]["powersaver"] + ) + self.powersaveraction.setStatusTip( + translations[settings.value("appLanguage")]["powersaver_message"] + ) + self.hide_dock_widget_action.setText( + f"{translations[settings.value("appLanguage")]["help"]} && AI" + ) + self.hide_dock_widget_action.setStatusTip( + translations[settings.value("appLanguage")]["help_message"] + ) self.findaction.setText(translations[settings.value("appLanguage")]["find"]) self.findaction.setStatusTip( translations[settings.value("appLanguage")]["find_message"] @@ -491,6 +522,36 @@ def RS_toolbarTranslate(self): self.alignjustifiedevent.setStatusTip( translations[settings.value("appLanguage")]["justify_message"] ) + self.bold.setText( + translations[settings.value("appLanguage")]["bold"] + ) + self.bold.setStatusTip( + translations[settings.value("appLanguage")]["bold_message"] + ) + self.italic.setText( + translations[settings.value("appLanguage")]["italic"] + ) + self.italic.setStatusTip( + translations[settings.value("appLanguage")]["italic_message"] + ) + self.underline.setText( + translations[settings.value("appLanguage")]["underline"] + ) + self.underline.setStatusTip( + translations[settings.value("appLanguage")]["underline_message"] + ) + self.bulletevent.setText( + translations[settings.value("appLanguage")]["bullet"] + ) + self.bulletevent.setStatusTip( + translations[settings.value("appLanguage")]["bullet"] + ) + self.numberedevent.setText( + translations[settings.value("appLanguage")]["numbered"] + ) + self.numberedevent.setStatusTip( + translations[settings.value("appLanguage")]["numbered"] + ) self.color.setText(translations[settings.value("appLanguage")]["font_color"]) self.color.setStatusTip( translations[settings.value("appLanguage")]["font_color_message"] @@ -503,9 +564,25 @@ def RS_toolbarTranslate(self): "contentBackgroundColor_message" ] ) + self.fontfamily.setText( + translations[settings.value("appLanguage")]["font"] + ) + self.fontfamily.setStatusTip( + translations[settings.value("appLanguage")][ + "font_message" + ] + ) self.dock_widget.setWindowTitle( translations[settings.value("appLanguage")]["help"] + " && AI" ) + self.addimage.setText( + translations[settings.value("appLanguage")]["image"] + ) + self.addimage.setStatusTip( + translations[settings.value("appLanguage")][ + "image_message" + ] + ) self.dock_widget.setWidget(self.helpText) self.helpText.setText( "