EN · DE · RU · FR · ES

#304: I18nKeyUsageEntry.kt

projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt Класс Kotlin, projectforge-application/src/main/kotlin/org/projectforge/i18n/I18nKeyUsageEntry.kt 122 строки · 76 кода · 34 комментария · 12 пустых
Назначение: Пакет интернационализации ресурсов: I18nKeyUsageEntry.kt. I18nKeyUsageEntry.kt является частью приложения управления проектами с открытым исходным кодом ProjectForge.

Исходный код (первые 100 строк)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition 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 General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see 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()

  /**
   * If file represents a Java or Kotlin class, the class will be get byName and the class will be added instead of
   * the file.
   */
  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()
      }
    }
  }

  /**
   * Adds the class to the list of used classes.
   * The list will be sorted by class name.
   * @param clazz The class to add.
   * @return true if the class was added, false if the class was already in the list.
   * @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

868d6abb7 2025 -> 2026
63081666f Заголовки исходных файлов: 2024-> 2025.
16b6494b4 Миграция в процессе...
b6092df09 Авторские права 2023 -> 2024
ab45d51fa Авторские права 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 is dual-licensed.
 //

63081666f

Заголовки исходных файлов: 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 is dual-licensed.
 //

16b6494b4

Миграция в процессе...
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) {
     }
   }
 
+  /**
+   * Adds the class to the list of used classes.
+   * The list will be sorted by class name.
+   * @param clazz The class to add.
+   * @return true if the class was added, false if the class was already in the list.
+   * @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

Авторские права 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 is dual-licensed.
 //

ab45d51fa

Авторские права 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 is dual-licensed.
 //