Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions gui/KCC.ui
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="langButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Language</string>
</property>
<property name="icon">
<iconset resource="KCC.qrc">
<normaloff>:/Status/icons/info.png</normaloff>:/Status/icons/info.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
52 changes: 51 additions & 1 deletion kindlecomicconverter/KCC_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pathlib import Path
from PySide6.QtCore import (QSize, QUrl, Qt, Signal, QIODeviceBase, QEvent, QThread, QSettings)
from PySide6.QtGui import (QColor, QIcon, QPixmap, QDesktopServices)
from PySide6.QtWidgets import (QApplication, QLabel, QListWidgetItem, QMainWindow, QSystemTrayIcon, QFileDialog, QMessageBox, QDialog, QTreeView, QAbstractItemView)
from PySide6.QtWidgets import (QApplication, QLabel, QListWidgetItem, QMainWindow, QSystemTrayIcon, QFileDialog, QMessageBox, QDialog, QTreeView, QAbstractItemView, QInputDialog)
from PySide6.QtNetwork import (QLocalSocket, QLocalServer)

import os
Expand Down Expand Up @@ -692,6 +692,50 @@ def openKofi(self):
# noinspection PyCallByClass
QDesktopServices.openUrl(QUrl('https://ko-fi.com/eink_dude'))

def changeLanguage(self):
current = self.settings.value('locale', 'es', type=str)
items = ['EspaΓ±ol (es)', 'English (en)']
current_idx = 1 if current == 'en' else 0
choice, ok = QInputDialog.getItem(None, 'Idioma / Language', 'Select language:', items, current_idx, False)
if ok:
locale = 'en' if choice.endswith('(en)') else 'es'
self.settings.setValue('locale', locale)
self.settings.sync()
# Update the translator and UI immediately
global APP, MW
if hasattr(APP, '_translator'):
APP._translator.loadLocale(locale)

# Save current jobs (items without icons)
jobs = []
for i in range(GUI.jobList.count()):
item = GUI.jobList.item(i)
if item.icon().isNull():
jobs.append(item.text())

# Clear the list
GUI.jobList.clear()

# Re-add tips/messages in the new language
self.addMessage('<b>Tip:</b> Hover mouse over options to see additional information in tooltips.', 'info')
self.addMessage('<b>Tip:</b> You can drag and drop image folders or comic files/archives into this window to convert.', 'info')
if self.startNumber < 5:
self.addMessage('Since you are a new user of <b>KCC</b> please see few '
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
'info')
if not any([self.tar, self.sevenzip]):
self.addMessage('<a href="https://github.com/ciromattia/kcc#7-zip">Install 7z (link)</a>'
' to enable CBZ/CBR/ZIP/etc processing.', 'warning')

for job in jobs:
item = QListWidgetItem(job)
GUI.jobList.addItem(item)

self.retranslateUi(MW)
else:
QMessageBox.information(None, 'Idioma / Language',
'Reinicia la aplicaciΓ³n para aplicar el cambio.\nRestart the app to apply the change.')

def modeChange(self, mode):
if mode == 1:
self.currentMode = 1
Expand Down Expand Up @@ -931,6 +975,11 @@ def stripTags(self, html):
return s.get_data()

def addMessage(self, message, icon, replace=False):
from PySide6.QtCore import QCoreApplication
# Translate the message if possible
# Use a context that matches our JSON keys (some are already there)
translated = QCoreApplication.translate("KCCGUI", message, None)
message = translated
if icon != '':
icon = getattr(self.icons, icon)
item = QListWidgetItem(icon, ' ' + self.stripTags(message))
Expand Down Expand Up @@ -1399,6 +1448,7 @@ def __init__(self, kccapp, kccwindow):
GUI.editorButton.clicked.connect(self.selectFileMetaEditor)
GUI.wikiButton.clicked.connect(self.openWiki)
GUI.kofiButton.clicked.connect(self.openKofi)
GUI.langButton.clicked.connect(self.changeLanguage)
GUI.convertButton.clicked.connect(self.convertStart)
GUI.gammaSlider.valueChanged.connect(self.changeGamma)
GUI.gammaBox.stateChanged.connect(self.togglegammaBox)
Expand Down
44 changes: 22 additions & 22 deletions kindlecomicconverter/KCC_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13767,59 +13767,59 @@
\x00\x00\x00h\x00\x02\x00\x00\x00\x04\x00\x00\x00\x08\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x02<\x00\x00\x00\x00\x00\x01\x00\x02\xb4\x18\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x02z\x00\x00\x00\x00\x00\x01\x00\x03\x08\xb2\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x02f\x00\x00\x00\x00\x00\x01\x00\x02\xde\xb7\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xec\
\x00\x00\x02R\x00\x00\x00\x00\x00\x01\x00\x02\xd3T\
\x00\x00\x01\x89\x89D9.\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x00h\x00\x02\x00\x00\x00\x04\x00\x00\x00\x0d\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x01\x22\x00\x00\x00\x00\x00\x01\x00\x01\xad\xc2\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x018\x00\x00\x00\x00\x00\x01\x00\x01\xb7\x1a\
\x00\x00\x01\x98\x8a\xa4\xaa\xe2\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x01\x08\x00\x00\x00\x00\x00\x01\x00\x01\xa2\xbb\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x01L\x00\x00\x00\x00\x00\x01\x00\x01\xbf0\
\x00\x00\x01\x88;p\xbcB\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x00h\x00\x02\x00\x00\x00\x03\x00\x00\x00\x12\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x02\xbe\x00\x00\x00\x00\x00\x01\x00\x03:\xfe\
\x00\x00\x01\x88;p\xbcJ\
\x00\x00\x01\x9c\xfd\x92\xb2\xf1\
\x00\x00\x02\x90\x00\x00\x00\x00\x00\x01\x00\x03%\x01\
\x00\x00\x01\x88;p\xbcI\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x02\xa6\x00\x00\x00\x00\x00\x01\x00\x03.^\
\x00\x00\x01\x88;p\xbcI\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x00h\x00\x02\x00\x00\x00\x07\x00\x00\x00\x16\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x01\x98\x00\x00\x00\x00\x00\x01\x00\x01\xd5\xdc\
\x00\x00\x01\x88;p\xbcJ\
\x00\x00\x01\x9c\xfd\x92\xb2\xf1\
\x00\x00\x01\xae\x00\x00\x00\x00\x00\x01\x00\x01\xfe\x84\
\x00\x00\x01\x88;p\xbcI\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x02\x10\x00\x00\x00\x00\x00\x01\x00\x02WX\
\x00\x00\x01\x94\xb4\xd4\xf0a\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x01\xf6\x00\x00\x00\x00\x00\x01\x00\x02\x12\x11\
\x00\x00\x01\x88;p\xbcH\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x01\x80\x00\x00\x00\x00\x00\x01\x00\x01\xd1}\
\x00\x00\x01\x88;p\xbcF\
\x00\x00\x01\x9c\xfd\x92\xb2\xef\
\x00\x00\x01d\x00\x00\x00\x00\x00\x01\x00\x01\xc5\x14\
\x00\x00\x01\x88;p\xbcH\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x01\xd0\x00\x00\x00\x00\x00\x01\x00\x02\x07\xdb\
\x00\x00\x01\x88;p\xbcH\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x00h\x00\x02\x00\x00\x00\x03\x00\x00\x00\x1e\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\xe4\x00\x00\x00\x00\x00\x01\x00\x01~z\
\x00\x00\x01\x98\x8a\xa4\xaa\xe2\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
\x00\x00\x00\x9c\x00\x00\x00\x00\x00\x01\x00\x01\x1d\x90\
\x00\x00\x01\x9a\x02\xcf\x8cb\
\x00\x00\x01\x9c\xfd\x92\xb2\xec\
\x00\x00\x00\xbe\x00\x00\x00\x00\x00\x01\x00\x01=\xd0\
\x00\x00\x01\x9a\x02\xcf\x8cc\
\x00\x00\x01\x9c\xfd\x92\xb2\xed\
\x00\x00\x00h\x00\x02\x00\x00\x00\x01\x00\x00\x00\x22\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00x\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x88;p\xbcH\
\x00\x00\x01\x9c\xfd\x92\xb2\xf0\
"

def qInitResources():
Expand Down
36 changes: 23 additions & 13 deletions kindlecomicconverter/KCC_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def setupUi(self, mainWindow):

self.horizontalLayout.addWidget(self.wikiButton)

self.langButton = QPushButton(self.toolWidget)
self.langButton.setObjectName(u"langButton")
self.langButton.setMinimumSize(QSize(0, 30))
icon4 = QIcon()
icon4.addFile(u":/Status/icons/info.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.langButton.setIcon(icon4)

self.horizontalLayout.addWidget(self.langButton)


self.gridLayout.addWidget(self.toolWidget, 0, 0, 1, 2)

Expand Down Expand Up @@ -174,18 +183,18 @@ def setupUi(self, mainWindow):
self.convertButton.setObjectName(u"convertButton")
self.convertButton.setMinimumSize(QSize(0, 30))
self.convertButton.setFont(font)
icon4 = QIcon()
icon4.addFile(u":/Other/icons/convert.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.convertButton.setIcon(icon4)
icon5 = QIcon()
icon5.addFile(u":/Other/icons/convert.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.convertButton.setIcon(icon5)

self.gridLayout_4.addWidget(self.convertButton, 1, 3, 1, 1)

self.clearButton = QPushButton(self.buttonWidget)
self.clearButton.setObjectName(u"clearButton")
self.clearButton.setMinimumSize(QSize(0, 30))
icon5 = QIcon()
icon5.addFile(u":/Other/icons/clear.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.clearButton.setIcon(icon5)
icon6 = QIcon()
icon6.addFile(u":/Other/icons/clear.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.clearButton.setIcon(icon6)

self.gridLayout_4.addWidget(self.clearButton, 0, 3, 1, 1)

Expand All @@ -198,9 +207,9 @@ def setupUi(self, mainWindow):
self.fileButton = QPushButton(self.buttonWidget)
self.fileButton.setObjectName(u"fileButton")
self.fileButton.setMinimumSize(QSize(0, 30))
icon6 = QIcon()
icon6.addFile(u":/Other/icons/document_new.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.fileButton.setIcon(icon6)
icon7 = QIcon()
icon7.addFile(u":/Other/icons/document_new.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.fileButton.setIcon(icon7)

self.gridLayout_4.addWidget(self.fileButton, 0, 1, 1, 1)

Expand All @@ -211,9 +220,9 @@ def setupUi(self, mainWindow):
sizePolicy3.setVerticalStretch(0)
sizePolicy3.setHeightForWidth(self.directoryButton.sizePolicy().hasHeightForWidth())
self.directoryButton.setSizePolicy(sizePolicy3)
icon7 = QIcon()
icon7.addFile(u":/Other/icons/folder_new.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.directoryButton.setIcon(icon7)
icon8 = QIcon()
icon8.addFile(u":/Other/icons/folder_new.png", QSize(), QIcon.Mode.Normal, QIcon.State.Off)
self.directoryButton.setIcon(icon8)

self.gridLayout_4.addWidget(self.directoryButton, 0, 4, 1, 1)

Expand Down Expand Up @@ -374,7 +383,7 @@ def setupUi(self, mainWindow):
self.defaultOutputFolderButton = QPushButton(self.outputFolderWidget)
self.defaultOutputFolderButton.setObjectName(u"defaultOutputFolderButton")
self.defaultOutputFolderButton.setMinimumSize(QSize(0, 30))
self.defaultOutputFolderButton.setIcon(icon7)
self.defaultOutputFolderButton.setIcon(icon8)

self.horizontalLayout_3.addWidget(self.defaultOutputFolderButton)

Expand Down Expand Up @@ -603,6 +612,7 @@ def retranslateUi(self, mainWindow):
self.editorButton.setText(QCoreApplication.translate("mainWindow", u"Metadata Editor", None))
self.kofiButton.setText(QCoreApplication.translate("mainWindow", u"Support me on Ko-fi", None))
self.wikiButton.setText(QCoreApplication.translate("mainWindow", u"Wiki", None))
self.langButton.setText(QCoreApplication.translate("mainWindow", u"Language", None))
#if QT_CONFIG(tooltip)
self.preserveMarginLabel.setToolTip(QCoreApplication.translate("mainWindow", u"<html><head/><body><p>After calculating the cropping boundaries, &quot;back up&quot; a specified percentage amount.</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
Expand Down
37 changes: 37 additions & 0 deletions kindlecomicconverter/i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
import os
from PySide6.QtCore import QTranslator, QSettings


class JsonTranslator(QTranslator):
def __init__(self, parent=None):
super().__init__(parent)
self.translations = {}
self.loadLocale()

def loadLocale(self, locale=None):
if locale is None:
# Read locale from QSettings, default to Spanish
settings = QSettings('ciromattia', 'kcc9')
locale = settings.value('locale', os.environ.get("KCC_LOCALE", "es"), type=str)

locales_dir = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "locales"
)
dict_file = os.path.join(locales_dir, f"kcc_{locale}.json")

if os.path.exists(dict_file):
try:
with open(dict_file, "r", encoding="utf-8") as f:
self.translations = json.load(f)
except Exception as e:
print(f"i18n: Failed to load translations for '{locale}': {e}")
else:
print(f"i18n: Translation file not found: {dict_file}")
self.translations = {}

def translate(self, context, sourceText, disambiguation=None, n=-1):
if not sourceText:
return ""
# Return translation if found, otherwise return the original text
return self.translations.get(sourceText, sourceText)
6 changes: 6 additions & 0 deletions kindlecomicconverter/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def start():
from . import KCC_gui
os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = "1"
KCCAplication = KCC_gui.QApplicationMessaging(sys.argv)

from .i18n import JsonTranslator
translator = JsonTranslator()
KCCAplication.installTranslator(translator)
KCCAplication._translator = translator

if KCCAplication.isRunning():
for i in range(1, len(sys.argv)):
KCCAplication.sendMessage(sys.argv[i])
Expand Down
Loading