Skip to content

Commit

Permalink
Fix missing translation warning being printed multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytm committed Sep 7, 2024
1 parent c5f139e commit 5100b69
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- Variable containing the distance between a player and waypoint for the cost formula (`distance`)
- Option to hide waypoints that are in different worlds as the player

### Fixed
- Warning that a world name has not been translated is printed multiple times

## 4.5.3

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.md5lukas.waypoints.lang

import de.md5lukas.commons.paper.registerEvents
import de.md5lukas.waypoints.events.ConfigReloadEvent
import java.util.*
import net.kyori.adventure.text.Component
import org.bukkit.World
import org.bukkit.event.EventHandler
Expand All @@ -13,18 +14,18 @@ class WorldTranslations(private val tl: YmlTranslationLoader) : Listener {
tl.plugin.registerEvents(this)
}

private val warned: MutableSet<World> = mutableSetOf()
private val warned: MutableSet<World> = Collections.synchronizedSet(mutableSetOf())

fun getWorldName(world: World): Component {
if (world in warned) return Component.text(world.name)

val key = "worlds.${world.name}"
return if (key in tl) {
return if (tl.contains(key, false)) {
Component.text(tl[key])
} else {
warned.add(world)
tl.plugin.slF4JLogger.warn(
"The world {} has no translation present. Using actual name as a fallback.", world.name)
"The world '{}' has no translation present. Using actual name as a fallback.", world.name)
Component.text(world.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import de.md5lukas.waypoints.WaypointsPlugin
import de.md5lukas.waypoints.events.ConfigReloadEvent
import java.io.File
import java.nio.charset.StandardCharsets
import java.util.*
import kotlin.collections.HashMap
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
Expand Down Expand Up @@ -121,11 +123,11 @@ class YmlTranslationLoader(
"The key $key is not present in the translation file for the language $loadedLanguage")
}

private val warned: MutableSet<String> = mutableSetOf()
private val warned: MutableSet<String> = Collections.synchronizedSet(mutableSetOf())

operator fun contains(key: String): Boolean {
fun contains(key: String, printWarning: Boolean): Boolean {
val contains = key in translations
if (!contains && key !in warned) {
if (printWarning && !contains && key !in warned) {
plugin.slF4JLogger.warn(
"The translation key {} is missing in the translation file for the language {}, but not required",
key,
Expand Down

0 comments on commit 5100b69

Please sign in to comment.