chore: Update translations for English and Icelandic languages
This commit is contained in:
93
app.py
93
app.py
@ -5,17 +5,19 @@ from PyQt5.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QLineEdit, QPushButton, QTextEdit, QComboBox,
|
||||
QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem,
|
||||
QHeaderView, QDateTimeEdit
|
||||
QHeaderView
|
||||
)
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
from PyQt5.QtCore import Qt, QDateTime, QUrl
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtCore import Qt, QDateTime
|
||||
from PyQt5.QtSvg import QSvgWidget
|
||||
|
||||
class URLManager(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle('tabRemember - URL Manager')
|
||||
self.translations = {}
|
||||
self.load_translations('lang/translations_en.json')
|
||||
self.setWindowTitle(self.translations['title'])
|
||||
self.setGeometry(100, 100, 600, 800)
|
||||
|
||||
self.setWindowIcon(QIcon('assets/logo.png'))
|
||||
@ -25,7 +27,7 @@ class URLManager(QWidget):
|
||||
# URL input and settings button layout
|
||||
self.url_layout = QHBoxLayout()
|
||||
self.url_input = QLineEdit()
|
||||
self.url_input.setPlaceholderText("URL")
|
||||
self.url_input.setPlaceholderText(self.translations['url_placeholder'])
|
||||
self.url_layout.addWidget(self.url_input)
|
||||
|
||||
self.settings_button = QPushButton()
|
||||
@ -43,15 +45,15 @@ class URLManager(QWidget):
|
||||
self.update_icon_color()
|
||||
|
||||
self.description_input = QTextEdit()
|
||||
self.description_input.setPlaceholderText("Enter Description or Thoughts")
|
||||
self.description_input.setPlaceholderText(self.translations['description_placeholder'])
|
||||
self.description_input.setMaximumHeight(100)
|
||||
self.layout.addWidget(self.description_input)
|
||||
|
||||
self.group_layout = QHBoxLayout()
|
||||
|
||||
self.group_combobox = QComboBox()
|
||||
self.group_combobox.addItem("All Categories")
|
||||
self.group_combobox.addItem("Default Category")
|
||||
self.group_combobox.addItem(self.translations['all_categories'])
|
||||
self.group_combobox.addItem(self.translations['default_category'])
|
||||
self.group_combobox.currentTextChanged.connect(self.filter_urls_by_category)
|
||||
self.group_layout.addWidget(self.group_combobox)
|
||||
|
||||
@ -60,14 +62,14 @@ class URLManager(QWidget):
|
||||
self.category_input.setFixedWidth(3 * 100) # Fixed width for the text input box, assuming "Save" button width is 100
|
||||
self.group_layout.addWidget(self.category_input)
|
||||
|
||||
self.save_category_button = QPushButton("Save Category")
|
||||
self.save_category_button = QPushButton(self.translations['save_category_button'])
|
||||
self.save_category_button.setFixedWidth(100) # Fixed width for the "Save" button
|
||||
self.save_category_button.clicked.connect(self.save_category)
|
||||
self.group_layout.addWidget(self.save_category_button)
|
||||
|
||||
self.layout.addLayout(self.group_layout)
|
||||
|
||||
self.add_button = QPushButton("Save URL")
|
||||
self.add_button = QPushButton(self.translations['save_url_button'])
|
||||
self.add_button.clicked.connect(self.add_url)
|
||||
self.layout.addWidget(self.add_button)
|
||||
|
||||
@ -75,7 +77,7 @@ class URLManager(QWidget):
|
||||
|
||||
self.search_layout = QHBoxLayout()
|
||||
self.search_input = QLineEdit()
|
||||
self.search_input.setPlaceholderText("Search ...")
|
||||
self.search_input.setPlaceholderText(self.translations['search_placeholder'])
|
||||
self.search_input.textChanged.connect(self.filter_urls)
|
||||
self.search_layout.addWidget(self.search_input)
|
||||
self.layout.addLayout(self.search_layout)
|
||||
@ -110,6 +112,12 @@ class URLManager(QWidget):
|
||||
"Swisscows": "https://swisscows.com/web?query="
|
||||
}
|
||||
|
||||
def load_translations(self, file_path):
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
self.translations = data['translations']
|
||||
|
||||
def update_icon_color(self):
|
||||
palette = self.palette()
|
||||
if palette.color(palette.Window).value() < 128:
|
||||
@ -172,7 +180,7 @@ class URLManager(QWidget):
|
||||
self.description_input.clear()
|
||||
|
||||
def delete_url(self, row):
|
||||
reply = QMessageBox.question(self, 'Delete URL', 'Are you sure you want to delete this URL?',
|
||||
reply = QMessageBox.question(self, self.translations['delete_confirmation_title'], self.translations['delete_confirmation'],
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
del self.urls[row]
|
||||
@ -190,30 +198,19 @@ class URLManager(QWidget):
|
||||
|
||||
def filter_urls_by_category(self):
|
||||
selected_category = self.group_combobox.currentText()
|
||||
if selected_category == "All Categories":
|
||||
self.update_url_list(sorted(self.urls, key=lambda x: x['date'], reverse=True))
|
||||
if selected_category == self.translations['all_categories']:
|
||||
self.update_url_list(self.urls)
|
||||
else:
|
||||
filtered_urls = [url for url in self.urls if url['group'] == selected_category]
|
||||
self.update_url_list(filtered_urls)
|
||||
|
||||
def update_url_list(self, urls=None):
|
||||
if urls is None:
|
||||
urls = self.urls
|
||||
|
||||
date_format = self.date_format
|
||||
|
||||
self.url_list.setRowCount(len(urls))
|
||||
for row, url in enumerate(urls):
|
||||
self.url_list.setRowCount(0)
|
||||
urls_to_display = urls if urls else self.urls
|
||||
for row, url in enumerate(urls_to_display):
|
||||
self.url_list.insertRow(row)
|
||||
self.url_list.setItem(row, 0, QTableWidgetItem(url['url']))
|
||||
|
||||
if date_format == "Nerdy":
|
||||
date_str = url['date']
|
||||
elif date_format == "Normal":
|
||||
date_str = QDateTime.fromString(url['date'], Qt.ISODate).toString("dd/MM/yy - hh:mm")
|
||||
elif date_format == "Murica!":
|
||||
date_str = QDateTime.fromString(url['date'], Qt.ISODate).toString("MM/dd/yy - hh:mmap")
|
||||
|
||||
self.url_list.setItem(row, 1, QTableWidgetItem(date_str))
|
||||
self.url_list.setItem(row, 1, QTableWidgetItem(url['date']))
|
||||
|
||||
actions_layout = QHBoxLayout()
|
||||
|
||||
@ -253,10 +250,13 @@ class URLManager(QWidget):
|
||||
self.data_directory = settings['data_directory']
|
||||
self.search_engine = settings['search_engine']
|
||||
self.date_format = settings.get('date_format', 'Nerdy')
|
||||
self.language = settings.get('language', 'English')
|
||||
self.load_translations(f'translations_{self.language.lower()[:2]}.json')
|
||||
else:
|
||||
self.data_directory = 'data/'
|
||||
self.search_engine = 'Google'
|
||||
self.date_format = 'Nerdy'
|
||||
self.language = 'English'
|
||||
self.save_settings()
|
||||
|
||||
def save_settings(self):
|
||||
@ -266,7 +266,8 @@ class URLManager(QWidget):
|
||||
settings = {
|
||||
'data_directory': self.data_directory,
|
||||
'search_engine': self.search_engine,
|
||||
'date_format': self.date_format
|
||||
'date_format': self.date_format,
|
||||
'language': self.language
|
||||
}
|
||||
json.dump(settings, file)
|
||||
|
||||
@ -277,7 +278,7 @@ class URLManager(QWidget):
|
||||
with open(categories_path, 'r') as file:
|
||||
self.groups = set(json.load(file))
|
||||
self.update_group_combobox()
|
||||
self.group_combobox.setCurrentText("Default Category")
|
||||
self.group_combobox.setCurrentText(self.translations['default_category'])
|
||||
|
||||
def save_categories(self):
|
||||
categories_path = os.path.join(self.data_directory, 'categories.json')
|
||||
@ -287,8 +288,8 @@ class URLManager(QWidget):
|
||||
|
||||
def update_group_combobox(self):
|
||||
self.group_combobox.clear()
|
||||
self.group_combobox.addItem("All Categories")
|
||||
self.group_combobox.addItem("Default Category")
|
||||
self.group_combobox.addItem(self.translations['all_categories'])
|
||||
self.group_combobox.addItem(self.translations['default_category'])
|
||||
for group in sorted(self.groups):
|
||||
self.group_combobox.addItem(group)
|
||||
|
||||
@ -326,7 +327,7 @@ class URLManager(QWidget):
|
||||
|
||||
def show_info_dialog(self):
|
||||
dialog = QDialog(self)
|
||||
dialog.setWindowTitle("About tabRemember")
|
||||
dialog.setWindowTitle(self.translations['about_title'])
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
@ -334,11 +335,11 @@ class URLManager(QWidget):
|
||||
svg_widget.setFixedSize(256, 256)
|
||||
layout.addWidget(svg_widget, alignment=Qt.AlignCenter)
|
||||
|
||||
written_by_label = QLabel("Developed by Axel Rafn")
|
||||
written_by_label = QLabel(self.translations['developed_by'])
|
||||
layout.addWidget(written_by_label, alignment=Qt.AlignCenter)
|
||||
|
||||
link_label = QLabel()
|
||||
link_label.setText('<a href="https://git.axelrafn.is/axelrafn/tabRemember">git.axelrafn.is</a>')
|
||||
link_label.setText(f'<a href="{self.translations["repository_link"]}">{self.translations["repository_link"]}</a>')
|
||||
link_label.setOpenExternalLinks(True)
|
||||
layout.addWidget(link_label, alignment=Qt.AlignCenter)
|
||||
|
||||
@ -354,19 +355,19 @@ class URLManager(QWidget):
|
||||
class SettingsDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setWindowTitle("Settings")
|
||||
self.setWindowTitle(parent.translations['settings_title'])
|
||||
self.setFixedWidth(360)
|
||||
|
||||
self.parent = parent
|
||||
|
||||
layout = QVBoxLayout()
|
||||
|
||||
directory_label = QLabel("Data Directory:")
|
||||
directory_label = QLabel(parent.translations['data_directory_label'])
|
||||
layout.addWidget(directory_label)
|
||||
|
||||
directory_layout = QHBoxLayout()
|
||||
self.directory_input = QLineEdit(self.parent.data_directory)
|
||||
self.browse_button = QPushButton("Browse...")
|
||||
self.browse_button = QPushButton(self.parent.translations['browse_button'])
|
||||
self.browse_button.clicked.connect(self.browse_directory)
|
||||
directory_layout.addWidget(self.directory_input)
|
||||
directory_layout.addWidget(self.browse_button)
|
||||
@ -379,16 +380,21 @@ class SettingsDialog(QDialog):
|
||||
search_engines = sorted(self.parent.search_engines.keys())
|
||||
self.search_engine_combobox.addItems(search_engines)
|
||||
self.search_engine_combobox.setCurrentText(self.parent.search_engine)
|
||||
form_layout.addRow("Search Engine:", self.search_engine_combobox)
|
||||
form_layout.addRow(self.parent.translations['search_engine_label'], self.search_engine_combobox)
|
||||
|
||||
self.date_format_combobox = QComboBox()
|
||||
self.date_format_combobox.addItems(["Nerdy", "Normal", "Murica!"])
|
||||
self.date_format_combobox.setCurrentText(self.parent.date_format)
|
||||
form_layout.addRow("Date Format:", self.date_format_combobox)
|
||||
form_layout.addRow(self.parent.translations['date_format_label'], self.date_format_combobox)
|
||||
|
||||
self.language_combobox = QComboBox()
|
||||
self.language_combobox.addItems(["English"]) # Add other languages as needed
|
||||
self.language_combobox.setCurrentText(self.parent.language)
|
||||
form_layout.addRow(self.parent.translations['language_label'], self.language_combobox)
|
||||
|
||||
layout.addLayout(form_layout)
|
||||
|
||||
self.save_button = QPushButton("Save")
|
||||
self.save_button = QPushButton(self.parent.translations['save_button'])
|
||||
self.save_button.clicked.connect(self.save_settings)
|
||||
layout.addWidget(self.save_button)
|
||||
|
||||
@ -403,6 +409,7 @@ class SettingsDialog(QDialog):
|
||||
self.parent.data_directory = self.directory_input.text()
|
||||
self.parent.search_engine = self.search_engine_combobox.currentText()
|
||||
self.parent.date_format = self.date_format_combobox.currentText()
|
||||
self.parent.language = self.language_combobox.currentText()
|
||||
self.parent.save_settings()
|
||||
self.accept()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user