package team.unstudio.udpl.util;

import java.io.File;

import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.YamlConfiguration;

public class I18n {
	
	private final File path;
	private String language = "en_US";
	private Configuration cache = null;
	
	public I18n(File path) {
		if(path==null||!path.exists()) throw new IllegalArgumentException("The path is empty.");
		this.path = path;
	}

	public File getPath() {
		return path;
	}
	
	public String getSecretLanguage(){
		return language;
	}
	
	public void setSecretLanguage(String language) {
		this.language = language;
		reload();
	}
	
	private void reload(){
		File file = new File(path, language+".yml");
		if(file.exists())
			cache = YamlConfiguration.loadConfiguration(file);
		else
			loadDefault();
	}
	
	private void loadDefault(){
		File defaultFile = new File(path, "en_US.yml");
		if(defaultFile.exists())
			cache = YamlConfiguration.loadConfiguration(defaultFile);
		else
			cache = null;
	}
	
	public String format(String key, Object... args){
		if(cache==null)
			return String.format(key, args);
		else
			return String.format(cache.getString(key,key), args);
	}
}

@@ -50,16 +50,42 @@
 o.File;%0D
+%0Aimport java.util.Locale;%0D
 %0A%0D%0Aimpor
@@ -138,42 +138,34 @@
 ort 
-org.bukkit.configuration.file.Yaml
+team.unstudio.udpl.config.
 Conf
@@ -173,16 +173,22 @@
 guration
+Helper
 ;%0D%0A%0D%0Apub
@@ -204,24 +204,149 @@
  I18n %7B%0D%0A%09%0D%0A
+%09public static final Locale LOCAL_LOCALE = Locale.getDefault();%0D%0A%09public static final Locale DEFAULT_LOCALE = Locale.US;%0D%0A%09%0D%0A
 %09private fin
@@ -373,33 +373,36 @@
 ate 
-String language = %22en_US%22
+Locale locale = LOCAL_LOCALE
 ;%0D%0A%09
@@ -487,10 +487,76 @@
 null
-%7C%7C
+)%0D%0A%09%09%09throw new IllegalArgumentException(%22Path can't Null.%22);%0D%0A%09%09if(
 !pat
@@ -566,17 +566,21 @@
 xists())
- 
+%0D%0A%09%09%09
 throw ne
@@ -611,31 +611,126 @@
 on(%22
-The path is empt
+Path isn't exist.%22);%0D%0A%09%09if(!path.isDirectory())%0D%0A%09%09%09throw new IllegalArgumentException(%22Path isn't director
 y.%22);%0D%0A
+%09%09%0D%0A
 %09%09th
@@ -793,32 +793,94 @@
 n path;%0D%0A%09%7D%0D%0A%09%0D%0A
+%09public Locale getSecretLanguage()%7B%0D%0A%09%09return locale;%0D%0A%09%7D%0D%0A%09%0D%0A
 %09public String g
@@ -887,32 +887,35 @@
 etSecretLanguage
+Tag
 ()%7B%0D%0A%09%09return la
@@ -913,23 +913,37 @@
 return l
+ocale.toL
 anguage
+Tag()
 ;%0D%0A%09%7D%0D%0A%09
@@ -1001,20 +1001,130 @@
 %0D%0A%09%09
-this.languag
+locale = Locale.forLanguageTag(language); %0D%0A%09%09reload();%0D%0A%09%7D%0D%0A%09%0D%0A%09public void setSecretLanguage(Locale language) %7B%0D%0A%09%09local
 e = 
@@ -1132,16 +1132,17 @@
 anguage;
+ 
 %0D%0A%09%09relo
@@ -1209,24 +1209,38 @@
 e(path, 
-l
+getSecretL
 anguage
+Tag()
 +%22.yml%22)
@@ -1266,36 +1266,32 @@
 ())%0D%0A%09%09%09cache = 
-Yaml
 Configuration.lo
@@ -1279,32 +1279,38 @@
  = Configuration
+Helper
 .loadConfigurati
@@ -1424,14 +1424,40 @@
 th, 
-%22en_US
+DEFAULT_LOCALE.toLanguageTag()+%22
 .yml
@@ -1504,12 +1504,8 @@
 e = 
-Yaml
 Conf
@@ -1513,16 +1513,22 @@
 guration
+Helper
 .loadCon
@@ -1648,18 +1648,20 @@
 if(cache
+ 
 ==
+ 
 null)%0D%0A%09
@@ -1748,16 +1748,17 @@
 ing(key,
+ 
 key), ar

Update I18n