Skip to content
Snippets Groups Projects
Commit 7a2fe946 authored by Kaj Koivunen's avatar Kaj Koivunen :coffee:
Browse files

rebrändäystä

parent c272e754
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,7 @@ tasks.withType<KotlinCompile> { ...@@ -37,7 +37,7 @@ tasks.withType<KotlinCompile> {
} }
application { application {
mainClass.set("guru.kake.yaku.MainKt") mainClass.set("guru.kake.ronove.MainKt")
} }
tasks { tasks {
......
package guru.kake.yaku package guru.kake.ronove
import tornadofx.* import tornadofx.*
class MyApp: App(MainView::class) class MyApp: App(MainView::class, RonoveStylesheet::class)
fun main(args: Array<String>) { fun main(args: Array<String>) {
launch<MyApp>(args) launch<MyApp>(args)
......
package guru.kake.yaku package guru.kake.ronove
import com.deepl.api.DeepLException import com.deepl.api.DeepLException
import com.deepl.api.Translator import com.deepl.api.Translator
...@@ -7,6 +7,7 @@ import com.google.cloud.translate.TranslateException ...@@ -7,6 +7,7 @@ import com.google.cloud.translate.TranslateException
import com.google.cloud.translate.TranslateOptions import com.google.cloud.translate.TranslateOptions
import com.google.cloud.translate.Translation import com.google.cloud.translate.Translation
import javafx.beans.property.SimpleDoubleProperty import javafx.beans.property.SimpleDoubleProperty
import javafx.beans.property.SimpleStringProperty
import tornadofx.getValue import tornadofx.getValue
import tornadofx.setValue import tornadofx.setValue
...@@ -14,6 +15,7 @@ import tornadofx.setValue ...@@ -14,6 +15,7 @@ import tornadofx.setValue
class TranslationBackend { class TranslationBackend {
companion object { companion object {
var service: TranslationService? = null var service: TranslationService? = null
var serviceName = SimpleStringProperty()
var quotaMax = 0L var quotaMax = 0L
var quotaUsed = 0L var quotaUsed = 0L
val quotaProperty = SimpleDoubleProperty() val quotaProperty = SimpleDoubleProperty()
...@@ -21,11 +23,11 @@ class TranslationBackend { ...@@ -21,11 +23,11 @@ class TranslationBackend {
var destinationLanguage: String = "" var destinationLanguage: String = ""
var sourceLanguage: String = "" var sourceLanguage: String = ""
operator fun invoke(text: String, sourceLang: String = sourceLanguage, destLang: String = destinationLanguage): String = operator fun invoke(text: String, sourceLang: String = sourceLanguage, destLang: String = destinationLanguage)
service!!.translate(text, sourceLang, destLang) : String = service!!.translate(text, sourceLang, destLang)
fun invoke(textList: List<String>, sourceLang: String = sourceLanguage, destLang: String = destinationLanguage): List<String> = fun invoke(textList: List<String>, sourceLang: String = sourceLanguage, destLang: String = destinationLanguage)
service?.translate(textList, sourceLang, destLang) ?: : List<String> = service?.translate(textList, sourceLang, destLang) ?:
throw TranslationServiceUnitializedException("Translation service uninitialized!") throw TranslationServiceUnitializedException("Translation service uninitialized!")
val provider: String = when (service) { val provider: String = when (service) {
...@@ -33,6 +35,11 @@ class TranslationBackend { ...@@ -33,6 +35,11 @@ class TranslationBackend {
is DeepLTranslator -> "DeepL" is DeepLTranslator -> "DeepL"
else -> "error" else -> "error"
} }
fun setService(service: TranslationService, name: String) {
this.service = service
serviceName.value = name
}
} }
} }
...@@ -74,7 +81,9 @@ class DeepLTranslator(APIkey: String) : TranslationService { ...@@ -74,7 +81,9 @@ class DeepLTranslator(APIkey: String) : TranslationService {
TranslationBackend.quotaMax = usage.character!!.limit TranslationBackend.quotaMax = usage.character!!.limit
TranslationBackend.quota = usage.character!!.count.toDouble() / usage.character!!.limit TranslationBackend.quota = usage.character!!.count.toDouble() / usage.character!!.limit
} catch (e: DeepLException) { } catch (e: DeepLException) {
throw TranslationServiceException("DeepL API initialization failed with message: ${e.message}", e) throw TranslationServiceException("Error: ${e.message}", e)
} catch (e: IllegalArgumentException) {
throw TranslationServiceException("API key must not be empty")
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment