package team.unstudio.udpl.i18n;

import java.util.Locale;

import org.bukkit.entity.Player;

import team.unstudio.udpl.util.PlayerUtils;

public interface I18n {
	Locale DEFAULT_LOCALE = Locale.US;
	
	String localize(Locale locale, String key);
	
	default String localize(String key){
		return localize(Locale.getDefault(), key);
	}
	
	default String localize(String locale, String key){
		return localize(Locale.forLanguageTag(locale), key);
	}
	
	default String localize(Player player, String key){
		return localize(PlayerUtils.getLanguageLocale(player), key);
	}
	
	default String format(Locale locale, String key, Object... args){
		Object[] localizedArgs = new Object[args.length];
		for (int i = 0, size = args.length; i < size; i++) {
			Object arg = args[i];
			if(arg instanceof String)
				localizedArgs[i] = localize(locale, (String) arg);
			else
				localizedArgs[i] = arg;
		}
		return String.format(localize(locale, key), localizedArgs);
	}
	
	default String format(String key, Object... args){
		return format(Locale.getDefault(), key, args);
	}
	
	default String format(String locale, String key, Object... args){
		return format(Locale.forLanguageTag(locale), key, args);
	}
	
	default String format(Player player, String key, Object... args){
		return format(PlayerUtils.getLanguageLocale(player), key, args);
	}
}

@@ -311,23 +311,16 @@
 ocalize(
-Locale.
 getDefau
@@ -317,24 +317,30 @@
 e(getDefault
+Locale
 (), key);%0D%0A%09
@@ -1058,23 +1058,16 @@
  format(
-Locale.
 getDefau
@@ -1068,16 +1068,22 @@
 tDefault
+Locale
 (), key,
@@ -1373,11 +1373,245 @@
 );%0D%0A%09%7D%0D%0A
+%09%0D%0A%09default Locale getDefaultLocale()%7B%0D%0A%09%09return Locale.getDefault();%0D%0A%09%7D%0D%0A%09%0D%0A%09default void setDefaultLocale(Locale locale)%7B%7D%0D%0A%09%0D%0A%09default void setDefaultLocale(String locale)%7B%0D%0A%09%09setDefaultLocale(Locale.forLanguageTag(locale));%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Update I18n