package eu.midnightdust.yaytris;

import eu.midnightdust.yaytris.util.NightJson;

import java.util.HashMap;
import java.util.Map;

public class Translation {
    public static Map<String, String> jsonMap = new HashMap<>();

    /**
     * Loads translation strings from the specified language via NightJSON.
     *
     * @param locale the language code (i.e. de_de, en_us)
     * @see          NightJson
     */
    public static void load(String locale) {
        NightJson json = new NightJson(Translation.class, String.format("translation/%s.json5", locale));
        json.readJson();
    }

    /**
     * Translates the given key to the active language.
     *
     * @param key   translation key
     * @return      the resolved translation in the current locale, if present. Otherwise, the key is returned.
     */
    public static String t(String key, Object... args) {
        return String.format(jsonMap.getOrDefault(key, key), args);
    }
}
