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

dokumentaatiota & testiä

parent b41f300a
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ import tornadofx.*
*/
class ReaderTab : View("Reader") {
private val cbobject: WebViewCallback = WebViewCallback()
/** TornadoFX root */
override val root = vbox {
webview {
style {
......@@ -65,6 +66,7 @@ class DictionaryTab : View("Kanji Dictionary") {
private val ret = DictionaryParser.parseKanjidic2("C:\\repos\\kanjisho\\kanjidic2.xml")
private val tree = BST(ret)
/** TornadoFX root */
override val root = vbox {
(app as Ronove).cellSelection!!.addListener(fun(_, _, newSelection) {
......@@ -102,12 +104,20 @@ class DictionaryTab : View("Kanji Dictionary") {
}
}
/**
* TornadoFX fragment to display information on a Kanji
* @param kanji the kanji
* @param kun kunyomi reading
* @param on onyomi reading
* @param meaning English meaning of the kanji
*/
class DictionaryEntry(
private val kanji: String,
private val kun: String,
private val on: String,
private val meaning: String
) : Fragment("") {
/** TornadoFX root */
override val root = hbox {
label(kanji) {
addClass(RonoveStylesheet.bigLabel)
......@@ -124,6 +134,7 @@ class DictionaryEntry(
* Tab class for displaying original material in image form
*/
class ImageTab : View("Image") {
/** TornadoFX root */
override val root = vbox {
imageview("/yopage.jpg") {
fitWidth = 300.0
......@@ -141,6 +152,7 @@ class TranslatorTab : View("Machine translation") {
private var toField: TextField by singleAssign()
//TODO allow switching languages on the fly
/** TornadoFX root */
override val root = vbox {
vbox {
label("Japanese")
......
......@@ -6,6 +6,7 @@ import kotlin.reflect.KProperty1
* Class for holding the data of the entire translation project, which consists of pages consisting of lines.
*/
class Project {
/** Pages of the project */
var pages: MutableList<Page> = mutableListOf(Page(listOf(Line())))
}
......@@ -13,6 +14,7 @@ class Project {
* Class for holding the data of a single translation page
*/
class Page(lines: Collection<Line> = listOf()) {
/** Lines on a page */
var lines: MutableList<Line> = lines.toMutableList()
/**
......@@ -20,7 +22,7 @@ class Page(lines: Collection<Line> = listOf()) {
* @param column the column to get, for example [Line::original]
* @return list containing the elements of the column
*/
fun getColumn(column: KProperty1<Line, String>) : List<String> = buildList { for (line in lines) add(column.get(line)) }
private fun getColumn(column: KProperty1<Line, String>) : List<String> = buildList { for (line in lines) add(column.get(line)) }
/**
* Translates all lines on page
......@@ -46,8 +48,12 @@ class Page(lines: Collection<Line> = listOf()) {
* Class for holding the data of a single line of translation
*/
data class Line(
/** Original, untranslated text */
var original: String = "",
/** Machine translation of the original */
var machineTranslation: String = "",
/** Manual, finalized translation*/
var finalTranslation: String = "",
/** Translator notes for the line */
var notes: String = ""
)
\ No newline at end of file
......@@ -8,7 +8,9 @@ import tornadofx.*
*/
class RonoveStylesheet: Stylesheet() {
companion object {
/** Centers alignment */
val vcenter by cssclass()
/** Increases font size of a label */
val bigLabel by cssclass()
}
......
......@@ -33,7 +33,8 @@ class TranslationBackend {
* @return Translated string
*/
operator fun invoke(text: String, sourceLang: String = sourceLanguage, destLang: String = destinationLanguage)
: String = service!!.translate(text, sourceLang, destLang)
: String = service?.translate(text, sourceLang, destLang) ?:
throw TranslationServiceUnitializedException("Translation service uninitialized!")
/**
* Translate a list of strings
......@@ -53,6 +54,11 @@ class TranslationBackend {
else -> "error"
}
/**
* Sets the translation service to be used
* @param service Object implementing [TranslationService] interface
* @param name name of service
*/
fun setService(service: TranslationService, name: String) {
this.service = service
serviceName.value = name
......@@ -173,5 +179,7 @@ class GoogleTranslator(key: String) : TranslationService {
}
}
/** Exception thrown when translation fails, usually due to errors accessing the online service providing translation.*/
class TranslationServiceException(message: String? = null, cause: Throwable? = null) : Exception(message, cause)
/** Exception thrown when trying to translate without a service set. */
class TranslationServiceUnitializedException(message: String? = null) : Exception(message)
\ No newline at end of file
import guru.kake.ronove.TranslationBackend
import guru.kake.ronove.TranslationService
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class MockTranslationService : TranslationService {
override fun translate(text: String, sourceLang: String, destLang: String): String {
return when (destLang) {
......@@ -17,7 +17,7 @@ class MockTranslationService : TranslationService {
class TranslationBackendTest {
@BeforeEach fun setUp() {
@BeforeEach fun init() {
TranslationBackend.setService(MockTranslationService(), "Mock")
}
......
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