Class MessageFormatter

java.lang.Object
dev.vanengine.core.MessageFormatter

public final class MessageFormatter extends Object
Simple {key} placeholder replacement for i18n messages, with optional plural resolution and HTML-safe formatting.
  • Method Details

    • format

      public static String format(String message, Map<String,?> params)
      Replace {key} placeholders in the message with values from the params map. If the message contains pipe-separated plural forms and params contains "count", the appropriate form is selected first. Unmatched placeholders are left as-is.
    • formatSafe

      public static String formatSafe(String message, Map<String,?> params)
      Same as format(String, Map), but HTML-escapes parameter values before substitution. Use this when the output will be embedded in HTML to prevent XSS.
    • resolvePlural

      public static String resolvePlural(String message, int count)
      Resolve plural forms separated by | (pipe).

      Rules (vue-i18n compatible):

      • 2 forms: "singular | plural" — 0,1 → first; 2+ → second
      • 3 forms: "zero | singular | plural" — 0 → first; 1 → second; 2+ → third
      If count is negative, returns the first form.