EN · DE · RU · FR · ES

#304: I18nKeyUsageEntry.kt

projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt Kotlin-Klasse, projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt 122 Zeilen · 76 Code · 34 Kommentare · 12 leer
Zweck: Internationalisierungs-Ressourcenbündel: I18nKeyUsageEntry.kt. I18nKeyUsageEntry.kt ist Teil der Open-Source-Projektmanagement-Anwendung ProjectForge.

Quellcode (erste 100 Zeilen)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge ist dual-lizenziert.
//
// Diese Community-Edition ist freie Software; Sie können es weiterverteilen und/oder
// modifizieren unter den Bedingungen der GNU General Public License, wie veröffentlicht
// von der Free Software Foundation; Version 3 der Lizenz.
//
// Diese Community-Edition wird in der Hoffnung verteilt, dass sie nützlich sein wird,
// aber OHNE JEGLICHE GEWÄHRLEISTUNG; ohne sogar die stillschweigende Garantie der
// MARKTGÄNGIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK. Siehe die GNU General
// Public License für weitere Details.
//
// Sie sollten eine Kopie der GNU General Public License zusammen mit
// diesem Programm erhalten haben; falls nicht, siehe http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.i18n

import com.fasterxml.jackson.annotation.JsonIgnore
import mu.KotlinLogging
import org.projectforge.framework.json.JsonUtils
import java.io.File

private val log = KotlinLogging.logger {}

internal class I18nKeyUsageEntry(val i18nKey: String) {
  var bundleName: String? = null
  var translation: String? = null
  var translationDE: String? = null
  var usedInClasses = mutableListOf<Class<*>>()
  var usedInFiles = mutableListOf<String>()

  val classes: String
    @JsonIgnore
    get() = usedInClasses.sortedBy { it.name }.joinToString { it.simpleName }

  val files: String
    @JsonIgnore
    get() = usedInFiles.sorted().joinToString()

  /**
   * Wenn die Datei eine Java- oder Kotlin-Klasse repräsentiert, wird die Klasse per Name geholt und die Klasse wird anstelle der
   * Datei hinzugefügt.
   */
  fun addUsage(file: File) {
    val clazz = getClassByFile(file)
    if (clazz != null) {
      addUsage(clazz)
    } else {
      val path = file.absolutePath.replace(basePath, ".")
      if (!usedInFiles.contains(path)) {
        usedInFiles.add(path)
        usedInFiles.sort()
      }
    }
  }

  /**
   * Fügt die Klasse zur Liste der verwendeten Klassen hinzu.
   * Die Liste wird nach Klassennamen sortiert.
   * @param clazz Die hinzuzufügende Klasse.
   * @return true, wenn die Klasse hinzugefügt wurde, false, wenn die Klasse bereits in der Liste war.
   * @see usedInClasses
   */
  fun addUsage(clazz: Class<*>) {
    if (!usedInClasses.contains(clazz)) {
      usedInClasses.add(clazz)
      usedInClasses.sortBy { it.name }
    }
  }

  override fun toString(): String {
    return JsonUtils.toJson(this)
  }

  companion object {
    private val classCacheMap = mutableMapOf<File, Class<*>>()
    private val basePath = I18nKeysSourceAnalyzer.basePath.toFile().absolutePath

    fun read(str: String): I18nKeyUsageEntry? {
      return JsonUtils.fromJson(str, I18nKeyUsageEntry::class.java)
    }

    internal fun getClassByFile(file: File, showError: Boolean = true): Class<*>? {
      classCacheMap[file]?.let { return it }
      val className = if (file.extension == "java") {
        file.absolutePath.substringAfter("/src/main/java/").removeSuffix(".java").replace('/', '.')
      } else if (file.extension == "kt") {
        file.absolutePath.substringAfter("/src/main/kotlin/").removeSuffix(".kt").replace('/', '.')
      } else {
        return null
      }
      if (

Git-Verlauf

868d6abb7 2025 -> 2026
63081666f Quellcode-Dateiköpfe: 2024-> 2025.
16b6494b4 Migration läuft...
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
index 75d73217c..443b2a9f8 100644
--- a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
+++ b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge ist dual-lizenziert.
 //

63081666f

Quellcode-Dateiköpfe: 2024-> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
index 281446e2d..75d73217c 100644
--- a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
+++ b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge ist dual-lizenziert.
 //

16b6494b4

Migration läuft...
16b6494b42ddee3749b299fb9f81a84647d711af
diff --git a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
index 1a429f70c..281446e2d 100644
--- a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
+++ b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
@@ -62,6 +62,13 @@ internal class I18nKeyUsageEntry(val i18nKey: String) {
     }
   }
 
+  /**
+   * Fügt die Klasse zur Liste der verwendeten Klassen hinzu.
+   * Die Liste wird nach Klassennamen sortiert.
+   * @param clazz Die hinzuzufügende Klasse.
+   * @return true, wenn die Klasse hinzugefügt wurde, false, wenn die Klasse bereits in der Liste war.
+   * @see usedInClasses
+   */
   fun addUsage(clazz: Class<*>) {
     if (!usedInClasses.contains(clazz)) {
       usedInClasses.add(clazz)
@@ -75,7 +82,7 @@ internal class I18nKeyUsageEntry(val i18nKey: String) {
 
   companion object {
     private val classCacheMap = mutableMapOf<File, Class<*>>()
-    private val basePath = I18nKeysSourceAnalyzer.basePath!!.toFile().absolutePath
+    private val basePath = I18nKeysSourceAnalyzer.basePath.toFile().absolutePath
 
     fun read(str: String): I18nKeyUsageEntry? {
       return JsonUtils.fromJson(str, I18nKeyUsageEntry::class.java)

b6092df09

Copyright 2023 -> 2024
b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
index f6b6fadf6..1a429f70c 100644
--- a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
+++ b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge ist dual-lizenziert.
 //

ab45d51fa

Copyright 2001-2022 -> 2001-2023.
ab45d51fa419ede6174b31d69987f96d4b841ff9
diff --git a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
index 1f811e3e8..f6b6fadf6 100644
--- a/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
+++ b/projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2022 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge ist dual-lizenziert.
 //