/* * search-doc-service * Copyright (C) 2020 Memoriav * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package org.memobase.model import com.fasterxml.jackson.annotation.JsonInclude import org.memobase.helpers.KEYS @JsonInclude(JsonInclude.Include.NON_NULL) data class LanguageContainer( val de: List, val fr: List, val it: List, val un: List // if the language is not known ) { companion object { val EMPTY = LanguageContainer( emptyList(), emptyList(), emptyList(), emptyList() ) val DEFAULT = LanguageContainer( listOf(KEYS.missingLabelDe), listOf(KEYS.missingLabelFr), listOf(KEYS.missingLabelIt), listOf(KEYS.missingLabelEn) ) fun placeholder(placeholder: String): LanguageContainer { return LanguageContainer(listOf(placeholder), listOf(placeholder), listOf(placeholder), listOf(placeholder)) } } fun toList(): List { return de + fr + it + un } fun merge(container: LanguageContainer): LanguageContainer { return LanguageContainer( de + container.de, fr + container.fr, it + container.it, un + container.un ) } fun any(): String { return when { un.isNotEmpty() -> un[0] de.isNotEmpty() -> de[0] fr.isNotEmpty() -> fr[0] it.isNotEmpty() -> it[0] else -> "" } } fun fillInEmpty(): LanguageContainer { return LanguageContainer( if (de.isEmpty()) listOf(KEYS.missingLabelDe) else de, if (fr.isEmpty()) listOf(KEYS.missingLabelFr) else fr, if (it.isEmpty()) listOf(KEYS.missingLabelIt) else it, un ) } }