Skip to content

Commit

Permalink
Merge pull request #1482 from otseng/main
Browse files Browse the repository at this point in the history
Translation changes, add overrideCompareToUseAllTexts, fix UI language selection
  • Loading branch information
eliranwong authored Dec 1, 2024
2 parents f94c634 + 88e494e commit b83999c
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 294 deletions.
2 changes: 1 addition & 1 deletion uniquebible/db/BiblesSqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ def readTextVerse(self, b, c, v, noAudioTag=False):
else:
return (b, c, v, f"{FileUtil.getVerseAudioTag(self.text, b, c, v)}{textVerse}")
else:
print("Verse table does not exist")
print(f"Verse table does not exist in {self.text}")
return (b, c, v, "")

def readFormattedChapter(self, verse, source):
Expand Down
2 changes: 1 addition & 1 deletion uniquebible/db/BiblesSqlite_nogui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def readTextVerse(self, b, c, v):
# return a tuple
return textVerse
else:
print("Verse table does not exist")
print(f"Verse table does not exist in {self.text}")
return (b, c, v, "")

def readFormattedChapter(self, verse, source):
Expand Down
2 changes: 0 additions & 2 deletions uniquebible/docker_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ gTTS==2.2.3
html-text==0.5.2
html5lib==1.1
htmldocx==0.0.6
ibm-cloud-sdk-core==3.14.0
ibm-watson==5.3.1
idna==3.7
importlib-metadata==4.8.1
Jinja2==3.1.4
Expand Down
8 changes: 0 additions & 8 deletions uniquebible/gui/AlephMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,6 @@ def create_menu(self):
("setup", self.setupGist),
("menu_gist", self.showGistWindow),
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
subMenu = addSubMenu(menu1_defaults, "watsonTranslator")
items = (
("setup", self.setupWatsonTranslator),
("enterCredentials", self.showWatsonCredentialWindow),
("menu1_setMyLanguage", self.openTranslationLanguageDialog),
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
if ("OfflineTts" in config.enabled):
Expand Down
4 changes: 4 additions & 0 deletions uniquebible/gui/ConfigFlagsWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def getOptions(self):
("refreshWindowsAfterSavingNote", config.refreshWindowsAfterSavingNote, self.refreshWindowsAfterSavingNoteChanged, True, config.thisTranslation["refreshWindowsAfterSavingNote"]),
("limitWorkspaceFilenameLength", config.limitWorkspaceFilenameLength, self.limitWorkspaceFilenameLengthChanged, True, config.thisTranslation["limitWorkspaceFilenameLength"]),
("enableHttpRemoteErrorRedirection", config.enableHttpRemoteErrorRedirection, self.enableHttpRemoteErrorRedirection, False, config.thisTranslation["enableHttpRemoteErrorRedirection"]),
("overrideCompareToUseAllTexts", config.overrideCompareToUseAllTexts, self.overrideCompareToUseAllTexts, False, config.thisTranslation["overrideCompareToUseAllTexts"]),
]
if ("OfflineTts" in config.enabled):
options += [
Expand Down Expand Up @@ -604,3 +605,6 @@ def limitWorkspaceFilenameLengthChanged(self):

def enableHttpRemoteErrorRedirection(self):
config.enableHttpRemoteErrorRedirection = not config.enableHttpRemoteErrorRedirection

def overrideCompareToUseAllTexts(self):
config.overrideCompareToUseAllTexts = not config.overrideCompareToUseAllTexts
8 changes: 0 additions & 8 deletions uniquebible/gui/FocusMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ def create_menu(self):
subMenu = addSubMenu(subMenu0, "menu1_programInterface")
for language in LanguageUtil.getNamesSupportedLanguages():
addMenuItem(subMenu, language, self, partial(self.changeInterfaceLanguage, language), translation=False)
subMenu = addSubMenu(subMenu0, "watsonTranslator")
items = (
("setup", self.setupWatsonTranslator),
("enterCredentials", self.showWatsonCredentialWindow),
("menu1_setMyLanguage", self.openTranslationLanguageDialog),
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
if ("OfflineTts" in config.enabled):
languages = self.getTtsLanguages()
languageCodes = list(languages.keys())
Expand Down
29 changes: 7 additions & 22 deletions uniquebible/gui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
from uniquebible.gui.GistWindow import GistWindow
from uniquebible.gui.Downloader import Downloader, DownloadProcess
from uniquebible.gui.ModifyDatabaseDialog import ModifyDatabaseDialog
from uniquebible.gui.WatsonCredentialWindow import WatsonCredentialWindow
from uniquebible.gui.LanguageItemWindow import LanguageItemWindow
from uniquebible.gui.ImportSettings import ImportSettings
#from uniquebible.gui.NoteEditor import NoteEditor
Expand Down Expand Up @@ -3170,9 +3169,6 @@ def setupYouTube(self):
def setupGist(self):
self.openWebsite("https://github.com/eliranwong/UniqueBible/wiki/Gist-synching")

def setupWatsonTranslator(self):
self.openWebsite("https://github.com/eliranwong/UniqueBible/wiki/IBM-Watson-Language-Translator")

def openUbaWiki(self):
self.openWebsite("https://github.com/eliranwong/UniqueBible/wiki")

Expand Down Expand Up @@ -4846,7 +4842,7 @@ def openInterfaceLanguageDialog(self):
self.setupMenuLayout(config.menuLayout)
self.reloadControlPanel(False)

def changeInterfaceLanguage(self, language):
def changeInterfaceLanguage(self, language, dummy=None):
config.displayLanguage = Languages.code[language]
self.setTranslation()
self.setupMenuLayout(config.menuLayout)
Expand All @@ -4857,19 +4853,13 @@ def changeInterfaceLanguage(self, language):
# userLanguage is used when user translate a selected word with right-click menu or use TRANSLATE::: command
# For example, a user can use English menu but he can translate a word into Chinese.
def openTranslationLanguageDialog(self):
# Use IBM Watson service to translate text
translator = Translator()
if translator.language_translator is not None:
if not config.userLanguage or not config.userLanguage in Translator.toLanguageNames:
userLanguage = "English"
else:
userLanguage = config.userLanguage
item, ok = QInputDialog.getItem(self, "UniqueBible", config.thisTranslation["menu1_setMyLanguage"], Translator.toLanguageNames, Translator.toLanguageNames.index(userLanguage), False)
if ok and item:
config.userLanguage = item
if not config.userLanguage or not config.userLanguage in Translator.toLanguageNames:
userLanguage = "English"
else:
self.displayMessage(config.thisTranslation["ibmWatsonNotEnalbed"])
self.openWebsite("https://github.com/eliranwong/UniqueBible/wiki/IBM-Watson-Language-Translator")
userLanguage = config.userLanguage
item, ok = QInputDialog.getItem(self, "UniqueBible", config.thisTranslation["menu1_setMyLanguage"], Translator.toLanguageNames, Translator.toLanguageNames.index(userLanguage), False)
if ok and item:
config.userLanguage = item

# Set verse number single-click action (config.verseNoSingleClickAction)
def selectSingleClickActionDialog(self):
Expand Down Expand Up @@ -5386,11 +5376,6 @@ def showGistWindow(self):
config.gistToken = gw.gistTokenInput.text()
self.reloadCurrentRecord()

def showWatsonCredentialWindow(self):
window = WatsonCredentialWindow()
if window.exec():
config.myIBMWatsonApikey, config.myIBMWatsonUrl, config.myIBMWatsonVersion = window.inputApiKey.text(), window.inputURL.text(), window.inputVersion.text()

def showAddLanguageItemWindow(self):
window = LanguageItemWindow(config.thisTranslation["addLanguageFiles"])
if window.exec() and window.key.text():
Expand Down
8 changes: 0 additions & 8 deletions uniquebible/gui/MaterialMainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,6 @@ def setMarkdownExportHeadingStyleSubmenu():
subMenu = addSubMenu(subMenu01, "menu1_programInterface")
for language in LanguageUtil.getNamesSupportedLanguages():
addCheckableMenuItem(subMenu, language, self, partial(self.changeInterfaceLanguage, language), config.displayLanguage, Languages.code[language], translation=False)
subMenu = addSubMenu(subMenu01, "watsonTranslator")
items = (
("setup", self.setupWatsonTranslator),
("enterCredentials", self.showWatsonCredentialWindow),
("menu1_setMyLanguage", self.openTranslationLanguageDialog),
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
if ("OfflineTts" in config.enabled):
languages = self.getTtsLanguages()
languageCodes = list(languages.keys())
Expand Down
12 changes: 4 additions & 8 deletions uniquebible/gui/NoteEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,14 +1315,10 @@ def translateText(self):
text = self.editor.textCursor().selectedText()
if text:
translator = Translator()
if translator.language_translator is not None:
fromLanguage = Translator.fromLanguageCodes[self.fromLanguageCombo.currentIndex() - 1] if self.fromLanguageCombo.currentIndex() != 0 else translator.identify(text)
toLanguage = Translator.toLanguageCodes[self.toLanguageCombo.currentIndex()]
result = translator.translate(text, fromLanguage, toLanguage)
self.editor.insertPlainText(result)
else:
self.displayMessage(config.thisTranslation["ibmWatsonNotEnalbed"])
webbrowser.open("https://github.com/eliranwong/UniqueBible/wiki/IBM-Watson-Language-Translator")
fromLanguage = Translator.fromLanguageCodes[self.fromLanguageCombo.currentIndex() - 1] if self.fromLanguageCombo.currentIndex() != 0 else translator.identify(text)
toLanguage = Translator.toLanguageCodes[self.toLanguageCombo.currentIndex()]
result = translator.translate(text, fromLanguage, toLanguage)
self.editor.insertPlainText(result)
else:
self.selectTextFirst()

Expand Down
58 changes: 0 additions & 58 deletions uniquebible/gui/WatsonCredentialWindow.py

This file was deleted.

36 changes: 9 additions & 27 deletions uniquebible/gui/WebEngineView.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,6 @@ def addMenuActions(self):
separator.setSeparator(True)
self.addAction(separator)

# IBM-Watson Translation Service

# Translate into User-defined Language
userLanguage = config.userLanguage
translateText = QAction(self)
Expand All @@ -909,10 +907,6 @@ def addMenuActions(self):
action.triggered.connect(partial(self.selectedTextToSelectedLanguage, languageCode))
translateMenu.addAction(action)

watsonTranslate = QAction(self)
watsonTranslate.setText(config.thisTranslation["watsonTranslator"])
watsonTranslate.setMenu(translateMenu)

translateMenu = QMenu()
for language, languageCode in Languages.googleTranslateCodes.items():
action = QAction(self)
Expand All @@ -927,7 +921,6 @@ def addMenuActions(self):
translateWrapper = QAction(self)
translateWrapper.setText(config.thisTranslation["translate"])
translateWrapperMenu = QMenu()
translateWrapperMenu.addAction(watsonTranslate)
translateWrapperMenu.addAction(googleTranslate)
translateWrapper.setMenu(translateWrapperMenu)
self.addAction(translateWrapper)
Expand Down Expand Up @@ -1150,7 +1143,6 @@ def googleTranslate(self, language):
url = "https://translate.google.com/?sl=origin_language_or_auto&tl={0}&text={1}&op=translate".format(language, selectedText)
self.openSimpleBrowser(url)

# Translate selected words into Selected Language (Watson Translator)
def selectedTextToSelectedLanguage(self, language):
selectedText = self.selectedTextProcessed()
if not selectedText:
Expand All @@ -1160,32 +1152,22 @@ def selectedTextToSelectedLanguage(self, language):

# Check if config.userLanguage is set
def checkUserLanguage(self):
# Use IBM Watson service to translate text
translator = Translator()
if translator.language_translator is not None:
if config.userLanguage and config.userLanguage in Translator.toLanguageNames:
selectedText = self.selectedTextProcessed()
if not selectedText:
self.messageNoSelection()
else:
userLanguage = Translator.toLanguageCodes[Translator.toLanguageNames.index(config.userLanguage)]
self.translateTextIntoUserLanguage(selectedText, userLanguage)
if config.userLanguage and config.userLanguage in Translator.toLanguageNames:
selectedText = self.selectedTextProcessed()
if not selectedText:
self.messageNoSelection()
else:
self.parent.parent.openTranslationLanguageDialog()
userLanguage = Translator.toLanguageCodes[Translator.toLanguageNames.index(config.userLanguage)]
self.translateTextIntoUserLanguage(selectedText, userLanguage)
else:
self.parent.parent.displayMessage(config.thisTranslation["ibmWatsonNotEnalbed"])
config.mainWindow.openWebsite("https://github.com/eliranwong/UniqueBible/wiki/IBM-Watson-Language-Translator")
self.parent.parent.openTranslationLanguageDialog()

# Translate selected words into user-defined language
def translateTextIntoUserLanguage(self, text, userLanguage="en"):
# Use IBM Watson service to translate text
translator = Translator()
if translator.language_translator is not None:
translation = translator.translate(text, None, userLanguage)
self.openPopover(html=translation)
else:
self.parent.parent.displayMessage(config.thisTranslation["ibmWatsonNotEnalbed"])
config.mainWindow.openWebsite("https://github.com/eliranwong/UniqueBible/wiki/IBM-Watson-Language-Translator")
translation = translator.translate(text, "auto", userLanguage)
self.openPopover(html=translation)

# TEXT-TO-SPEECH feature
def textToSpeech(self, activeSelection=False):
Expand Down
1 change: 1 addition & 0 deletions uniquebible/lang/language_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Spenden",
"about": "Informationen zu",
"githubStatistics": "GitHub-Statistik",
"overrideCompareToUseAllTexts": "Überschreiben Vers Vergleich, um alle Bibeltexte anstelle von Lieblingstexten zu vergleichen",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_el.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Δότη!",
"about": "-Ναι.",
"githubStatistics": "Στατιστικά στοιχεία GitHub",
"overrideCompareToUseAllTexts": "Παράκαμψε τη σύγκριση των εδαφίων για να συγκρίνεις όλα τα Γραφικά εδάφια αντί των αγαπημένων κειμένων",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_en_GB.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donate",
"about": "About",
"githubStatistics": "GitHub Statistics",
"overrideCompareToUseAllTexts": "Override verse comparison to compare all Bible texts instead of favourite texts",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_en_US.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donate",
"about": "About",
"githubStatistics": "GitHub Statistics",
"overrideCompareToUseAllTexts": "Override verse comparison to compare all Bible texts instead of favorite texts",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donar",
"about": "Acerca de",
"githubStatistics": "Estadísticas de GitHub",
"overrideCompareToUseAllTexts": "Superar la comparación de versículos para comparar todos los textos bíblicos en lugar de los textos favoritos",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donate",
"about": "A propos",
"githubStatistics": "Statistiques GitHub",
"overrideCompareToUseAllTexts": "Comparativement aux versets pour comparer tous les textes bibliques au lieu des textes préférés",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_hi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "दान",
"about": "लगभग",
"githubStatistics": "Githb सांख्यिकी",
"overrideCompareToUseAllTexts": "पसंदीदा ग्रंथों के बजाय सभी बाइबिल ग्रंथों की तुलना करने के लिए ओवरराइड कविता तुलना",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donato",
"about": "Informazioni su",
"githubStatistics": "Statistiche GitHub",
"overrideCompareToUseAllTexts": "Confronto dei versetti override per confrontare tutti i testi della Bibbia invece di testi preferiti",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_ja.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "ドナーテ",
"about": "アバウト",
"githubStatistics": "GitHub 統計",
"overrideCompareToUseAllTexts": "お気に入りテキストの代わりに、すべての聖書のテキストを比較するための重複比較をオーバーライド",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_ko.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "기부하다",
"about": "정보",
"githubStatistics": "깃허브 통계",
"overrideCompareToUseAllTexts": "가장 좋아하는 텍스트 대신 모든 성경 텍스트를 비교하는 배율 비교",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "ഡോണെറ്റ്",
"about": "ഏകദേശം",
"githubStatistics": "ഗിറ്റ്ഹബ് സ്ഥിതിവിവരംName",
"overrideCompareToUseAllTexts": "Override verse comparison to compare all Bible texts instead of favourite texts",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Donează",
"about": "Despre",
"githubStatistics": "Statistici GitHub",
"overrideCompareToUseAllTexts": "Compară versetul cu toate textele biblice în locul textelor favorite",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "Пожертвовать",
"about": "О",
"githubStatistics": "Статистика GitHub",
"overrideCompareToUseAllTexts": "Сравнение стихов для сравнения всех библейских текстов вместо любимых",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_zh_HANS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "捐赠",
"about": "关于",
"githubStatistics": "GitHub 统计信息",
"overrideCompareToUseAllTexts": "取代反比来比较所有圣经文本而不是最爱的文本",
}
1 change: 1 addition & 0 deletions uniquebible/lang/language_zh_HANT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,4 +1093,5 @@
"donate": "多納特",
"about": "關於",
"githubStatistics": "GitHub 統計資料",
"overrideCompareToUseAllTexts": "在比對所有聖經取而代之的取而代之的取而代之",
}
Loading

0 comments on commit b83999c

Please sign in to comment.