chore: Update translations for English and Icelandic languages

This commit is contained in:
2024-07-13 11:33:17 +02:00
parent 750b90a70e
commit af0a79ab42
3 changed files with 102 additions and 43 deletions

93
app.py
View File

@ -5,17 +5,19 @@ from PyQt5.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QLineEdit, QPushButton, QTextEdit, QComboBox, QLineEdit, QPushButton, QTextEdit, QComboBox,
QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem, QMessageBox, QSpacerItem, QSizePolicy, QLabel, QFileDialog, QDialog, QFormLayout, QTableWidget, QTableWidgetItem,
QHeaderView, QDateTimeEdit QHeaderView
) )
from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt, QDateTime, QUrl from PyQt5.QtCore import Qt, QDateTime
from PyQt5.QtSvg import QSvgWidget from PyQt5.QtSvg import QSvgWidget
class URLManager(QWidget): class URLManager(QWidget):
def __init__(self): def __init__(self):
super().__init__() 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.setGeometry(100, 100, 600, 800)
self.setWindowIcon(QIcon('assets/logo.png')) self.setWindowIcon(QIcon('assets/logo.png'))
@ -25,7 +27,7 @@ class URLManager(QWidget):
# URL input and settings button layout # URL input and settings button layout
self.url_layout = QHBoxLayout() self.url_layout = QHBoxLayout()
self.url_input = QLineEdit() 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.url_layout.addWidget(self.url_input)
self.settings_button = QPushButton() self.settings_button = QPushButton()
@ -43,15 +45,15 @@ class URLManager(QWidget):
self.update_icon_color() self.update_icon_color()
self.description_input = QTextEdit() 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.description_input.setMaximumHeight(100)
self.layout.addWidget(self.description_input) self.layout.addWidget(self.description_input)
self.group_layout = QHBoxLayout() self.group_layout = QHBoxLayout()
self.group_combobox = QComboBox() self.group_combobox = QComboBox()
self.group_combobox.addItem("All Categories") self.group_combobox.addItem(self.translations['all_categories'])
self.group_combobox.addItem("Default Category") self.group_combobox.addItem(self.translations['default_category'])
self.group_combobox.currentTextChanged.connect(self.filter_urls_by_category) self.group_combobox.currentTextChanged.connect(self.filter_urls_by_category)
self.group_layout.addWidget(self.group_combobox) 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.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.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.setFixedWidth(100) # Fixed width for the "Save" button
self.save_category_button.clicked.connect(self.save_category) self.save_category_button.clicked.connect(self.save_category)
self.group_layout.addWidget(self.save_category_button) self.group_layout.addWidget(self.save_category_button)
self.layout.addLayout(self.group_layout) 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.add_button.clicked.connect(self.add_url)
self.layout.addWidget(self.add_button) self.layout.addWidget(self.add_button)
@ -75,7 +77,7 @@ class URLManager(QWidget):
self.search_layout = QHBoxLayout() self.search_layout = QHBoxLayout()
self.search_input = QLineEdit() 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_input.textChanged.connect(self.filter_urls)
self.search_layout.addWidget(self.search_input) self.search_layout.addWidget(self.search_input)
self.layout.addLayout(self.search_layout) self.layout.addLayout(self.search_layout)
@ -110,6 +112,12 @@ class URLManager(QWidget):
"Swisscows": "https://swisscows.com/web?query=" "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): def update_icon_color(self):
palette = self.palette() palette = self.palette()
if palette.color(palette.Window).value() < 128: if palette.color(palette.Window).value() < 128:
@ -172,7 +180,7 @@ class URLManager(QWidget):
self.description_input.clear() self.description_input.clear()
def delete_url(self, row): 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) QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes: if reply == QMessageBox.Yes:
del self.urls[row] del self.urls[row]
@ -190,30 +198,19 @@ class URLManager(QWidget):
def filter_urls_by_category(self): def filter_urls_by_category(self):
selected_category = self.group_combobox.currentText() selected_category = self.group_combobox.currentText()
if selected_category == "All Categories": if selected_category == self.translations['all_categories']:
self.update_url_list(sorted(self.urls, key=lambda x: x['date'], reverse=True)) self.update_url_list(self.urls)
else: else:
filtered_urls = [url for url in self.urls if url['group'] == selected_category] filtered_urls = [url for url in self.urls if url['group'] == selected_category]
self.update_url_list(filtered_urls) self.update_url_list(filtered_urls)
def update_url_list(self, urls=None): def update_url_list(self, urls=None):
if urls is None: self.url_list.setRowCount(0)
urls = self.urls urls_to_display = urls if urls else self.urls
for row, url in enumerate(urls_to_display):
date_format = self.date_format self.url_list.insertRow(row)
self.url_list.setRowCount(len(urls))
for row, url in enumerate(urls):
self.url_list.setItem(row, 0, QTableWidgetItem(url['url'])) self.url_list.setItem(row, 0, QTableWidgetItem(url['url']))
self.url_list.setItem(row, 1, QTableWidgetItem(url['date']))
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))
actions_layout = QHBoxLayout() actions_layout = QHBoxLayout()
@ -253,10 +250,13 @@ class URLManager(QWidget):
self.data_directory = settings['data_directory'] self.data_directory = settings['data_directory']
self.search_engine = settings['search_engine'] self.search_engine = settings['search_engine']
self.date_format = settings.get('date_format', 'Nerdy') 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: else:
self.data_directory = 'data/' self.data_directory = 'data/'
self.search_engine = 'Google' self.search_engine = 'Google'
self.date_format = 'Nerdy' self.date_format = 'Nerdy'
self.language = 'English'
self.save_settings() self.save_settings()
def save_settings(self): def save_settings(self):
@ -266,7 +266,8 @@ class URLManager(QWidget):
settings = { settings = {
'data_directory': self.data_directory, 'data_directory': self.data_directory,
'search_engine': self.search_engine, 'search_engine': self.search_engine,
'date_format': self.date_format 'date_format': self.date_format,
'language': self.language
} }
json.dump(settings, file) json.dump(settings, file)
@ -277,7 +278,7 @@ class URLManager(QWidget):
with open(categories_path, 'r') as file: with open(categories_path, 'r') as file:
self.groups = set(json.load(file)) self.groups = set(json.load(file))
self.update_group_combobox() self.update_group_combobox()
self.group_combobox.setCurrentText("Default Category") self.group_combobox.setCurrentText(self.translations['default_category'])
def save_categories(self): def save_categories(self):
categories_path = os.path.join(self.data_directory, 'categories.json') categories_path = os.path.join(self.data_directory, 'categories.json')
@ -287,8 +288,8 @@ class URLManager(QWidget):
def update_group_combobox(self): def update_group_combobox(self):
self.group_combobox.clear() self.group_combobox.clear()
self.group_combobox.addItem("All Categories") self.group_combobox.addItem(self.translations['all_categories'])
self.group_combobox.addItem("Default Category") self.group_combobox.addItem(self.translations['default_category'])
for group in sorted(self.groups): for group in sorted(self.groups):
self.group_combobox.addItem(group) self.group_combobox.addItem(group)
@ -326,7 +327,7 @@ class URLManager(QWidget):
def show_info_dialog(self): def show_info_dialog(self):
dialog = QDialog(self) dialog = QDialog(self)
dialog.setWindowTitle("About tabRemember") dialog.setWindowTitle(self.translations['about_title'])
layout = QVBoxLayout() layout = QVBoxLayout()
@ -334,11 +335,11 @@ class URLManager(QWidget):
svg_widget.setFixedSize(256, 256) svg_widget.setFixedSize(256, 256)
layout.addWidget(svg_widget, alignment=Qt.AlignCenter) 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) layout.addWidget(written_by_label, alignment=Qt.AlignCenter)
link_label = QLabel() 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) link_label.setOpenExternalLinks(True)
layout.addWidget(link_label, alignment=Qt.AlignCenter) layout.addWidget(link_label, alignment=Qt.AlignCenter)
@ -354,19 +355,19 @@ class URLManager(QWidget):
class SettingsDialog(QDialog): class SettingsDialog(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
self.setWindowTitle("Settings") self.setWindowTitle(parent.translations['settings_title'])
self.setFixedWidth(360) self.setFixedWidth(360)
self.parent = parent self.parent = parent
layout = QVBoxLayout() layout = QVBoxLayout()
directory_label = QLabel("Data Directory:") directory_label = QLabel(parent.translations['data_directory_label'])
layout.addWidget(directory_label) layout.addWidget(directory_label)
directory_layout = QHBoxLayout() directory_layout = QHBoxLayout()
self.directory_input = QLineEdit(self.parent.data_directory) 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) self.browse_button.clicked.connect(self.browse_directory)
directory_layout.addWidget(self.directory_input) directory_layout.addWidget(self.directory_input)
directory_layout.addWidget(self.browse_button) directory_layout.addWidget(self.browse_button)
@ -379,16 +380,21 @@ class SettingsDialog(QDialog):
search_engines = sorted(self.parent.search_engines.keys()) search_engines = sorted(self.parent.search_engines.keys())
self.search_engine_combobox.addItems(search_engines) self.search_engine_combobox.addItems(search_engines)
self.search_engine_combobox.setCurrentText(self.parent.search_engine) 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 = QComboBox()
self.date_format_combobox.addItems(["Nerdy", "Normal", "Murica!"]) self.date_format_combobox.addItems(["Nerdy", "Normal", "Murica!"])
self.date_format_combobox.setCurrentText(self.parent.date_format) 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) 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) self.save_button.clicked.connect(self.save_settings)
layout.addWidget(self.save_button) layout.addWidget(self.save_button)
@ -403,6 +409,7 @@ class SettingsDialog(QDialog):
self.parent.data_directory = self.directory_input.text() self.parent.data_directory = self.directory_input.text()
self.parent.search_engine = self.search_engine_combobox.currentText() self.parent.search_engine = self.search_engine_combobox.currentText()
self.parent.date_format = self.date_format_combobox.currentText() self.parent.date_format = self.date_format_combobox.currentText()
self.parent.language = self.language_combobox.currentText()
self.parent.save_settings() self.parent.save_settings()
self.accept() self.accept()

26
lang/translations_en.json Normal file
View File

@ -0,0 +1,26 @@
{
"language": "English",
"contributors": ["Axel Rafn <axel@axelrafn.is>"],
"translations": {
"title": "tabRemember - URL Manager",
"url_placeholder": "URL",
"description_placeholder": "Enter Description or Thoughts",
"all_categories": "All Categories",
"default_category": "Default Category",
"save_category_button": "Save Category",
"save_url_button": "Save URL",
"search_placeholder": "Search ...",
"delete_confirmation": "Are you sure you want to delete this URL?",
"delete_confirmation_title": "Delete URL",
"settings_title": "Settings",
"about_title": "About tabRemember",
"developed_by": "Developed by Axel Rafn",
"repository_link": "https://git.axelrafn.is/axelrafn/tabRemember",
"data_directory_label": "Data Directory:",
"browse_button": "Browse...",
"search_engine_label": "Search Engine:",
"date_format_label": "Date Format:",
"save_button": "Save",
"language_label": "Language:"
}
}

26
lang/translations_is.json Normal file
View File

@ -0,0 +1,26 @@
{
"language": "Íslenska",
"contributors": ["Axel Rafn <axel@axelrafn.is>"],
"translations": {
"title": "tabRemember - URL Manager",
"url_placeholder": "URL",
"description_placeholder": "Skrifaðu lýsingu eða hvað þú ert að hugsa um",
"all_categories": "Allir Flokkar",
"default_category": "Sjálgefinn Flokkur",
"save_category_button": "Vista Flokk",
"save_url_button": "Vista URL",
"search_placeholder": "Leita ...",
"delete_confirmation": "Ertu viss um að þú viljir eyða þessu URLi?",
"delete_confirmation_title": "Eyða URLi",
"settings_title": "Stillingar",
"about_title": "Um tabRemember",
"developed_by": "Þróað af Axel Rafn",
"repository_link": "https://git.axelrafn.is/axelrafn/tabRemember",
"data_directory_label": "Gagna Mappa:",
"browse_button": "Skoða...",
"search_engine_label": "Leitarvél:",
"date_format_label": "Dagsetnigar form:",
"save_button": "Vista",
"language_label": "Tungumál:"
}
}