Class BundledTranslations

java.lang.Object
dev.ua.theroer.magicutils.lang.BundledTranslations

public final class BundledTranslations extends Object
Loads bundled MagicUtils translations from /lang/<code>.json classpath resources.

Files use flat dot-delimited keys and support JSON with comments (including trailing commas). Keys starting with _ are treated as translator-facing comments and dropped at load time.

Parsed resources are cached per language code since classpath resources are immutable during a JVM lifetime.

  • Method Details

    • getNamespacedTranslations

      public static Map<String,String> getNamespacedTranslations(String namespace, String languageCode)
      Loads translations from /lang/<namespace>/<code>.json inside the calling plugin's classpath. Useful for plugins that want to ship their own bundled translations alongside the MagicUtils core ones without polluting /lang/<code>.json.
      Parameters:
      namespace - plugin namespace (e.g. "leavepulse")
      languageCode - language code
      Returns:
      flat translation map, or empty when not found
    • availableNamespacedCodes

      public static Set<String> availableNamespacedCodes(String namespace)
      Scans the classpath under /lang/<namespace>/ and returns every available language code.
      Parameters:
      namespace - plugin namespace
      Returns:
      language codes available for that namespace
    • getTranslations

      public static Map<String,String> getTranslations(String languageCode)
      Returns the flat key -> value translation map for the given language code, loading from classpath on first access.
      Parameters:
      languageCode - language code (e.g. "en")
      Returns:
      unmodifiable flat translations, or an empty map when no bundled resource exists
    • getSections

      public static Map<String, Map<String,String>> getSections(String languageCode)
      Returns the translations grouped by section (the part before the first dot in each key). Compatible with LanguageConfig.applyTranslations().

      For example, the flat key "magicutils.commands.no_permission" is stored under section "magicutils.commands" with relative key "no_permission".

      The language section maps language.name, language.code, etc. directly since it has no nested structure.

      Parameters:
      languageCode - language code
      Returns:
      unmodifiable sectioned translations
    • exists

      public static boolean exists(String languageCode)
      Parameters:
      languageCode - language code
      Returns:
      true when a bundled resource exists for this code
    • availableCodes

      public static Set<String> availableCodes()
      Scans the classpath for bundled lang/*.json files and returns their language codes. Scans both plain directories (local development) and jars (production).
      Returns:
      language codes available as bundled resources