Die ToolsAPI, muss natürlich in euer Projekt eingebunden sein!
Dann kann die Klasse mit den Sprach Informationen, so aussehen:
import java.util.HashMap;
public class PlaceGameObjectLang {
public PlaceGameObjectLang() {
this.radial = new RadialClass();
setDefaultLanguage("en");
HashMap<String, String> mExit = new HashMap<>();
mExit.put("de", "Beenden");
getUi3D().setExit(mExit);
HashMap<String, String> mConfirm = new HashMap<>();
mConfirm.put("de", "Erstellen");
mConfirm.put("en", "Create");
getUi3D().setConfirm(mConfirm);
HashMap<String, String> mInfoCenterList= new HashMap<>();
mInfoCenterList.put("de", " Wähle ein Bundel aus! ");
mInfoCenterList.put("en", " Pick a bundle! ");
getUi3D().setInfoCenterList(mInfoCenterList);
HashMap<String, String> scaleMap = new HashMap<>();
scaleMap.put("de", "Größe");
scaleMap.put("en", "Scale");
getRadial().setScale(scaleMap);
HashMap<String, String> rotatMap = new HashMap<>();
rotatMap.put("de", "Drehung");
rotatMap.put("en", "Rotation");
getRadial().setRotation(rotatMap);
HashMap<String, String> moveMap = new HashMap<>();
moveMap.put("de", "Bewegen");
moveMap.put("en", "Move");
getRadial().setMove(moveMap);
HashMap<String, String> mBack = new HashMap<>();
mBack.put("de", "Zurück");
getRadial().setBack(mBack);
private String defaultLanguage;
public String getDefaultLanguage() {return defaultLanguage;}
public void setDefaultLanguage(String defaultLanguage) {this.defaultLanguage = defaultLanguage;}
public UI3D getUi3D() {return ui3D;}
private RadialClass radial;
public RadialClass getRadial() {return radial;}
this.confirm = new HashMap<>();
this.exit = new HashMap<>();
this.infoCenterList = new HashMap<>();
private HashMap<String,String> exit;
public HashMap<String, String> getExit() {return exit;}
public String getExit(String lang){return exit.get(lang)!=null?exit.get(lang):exit.get(defaultLanguage);}
public void setExit(HashMap<String, String> back) {this.exit = back;}
private HashMap<String,String> confirm;
public HashMap<String, String> getConfirm() {return confirm;}
public String getConfirm(String lang){return confirm.get(lang)!=null?confirm.get(lang):confirm.get(defaultLanguage);}
public void setConfirm(HashMap<String, String> confirm) {this.confirm = confirm;}
private HashMap<String,String> infoCenterList;
public HashMap<String, String> getInfoCenterList() {return infoCenterList;}
public String getInfoCenterList(String lang){return infoCenterList.get(lang)!=null?infoCenterList.get(lang):infoCenterList.get(defaultLanguage);}
public void setInfoCenterList(HashMap<String, String> infoCenterList) {this.infoCenterList = infoCenterList;}
public class RadialClass{
this.move = new HashMap<>();
this.rotation = new HashMap<>();
this.scale = new HashMap<>();
private HashMap<String,String> scale;
public HashMap<String, String> getScale() {return scale;}
public String getScale(String lang){return scale.get(lang)!=null?scale.get(lang):scale.get(defaultLanguage);}
public void setScale(HashMap<String, String> scale) {this.scale = scale;}
private HashMap<String,String> rotation;
public HashMap<String, String> getRotation() {return rotation;}
public String getRotation(String lang){return rotation.get(lang)!=null?rotation.get(lang):rotation.get(defaultLanguage);}
public void setRotation(HashMap<String, String> rotation) {this.rotation = rotation;}
private HashMap<String,String> move;
public HashMap<String, String> getMove() {return move;}
public String getMove(String lang){return move.get(lang)!=null?move.get(lang):move.get(defaultLanguage);}
public void setMove(HashMap<String, String> move) {this.move = move;}
private HashMap<String,String> back;
public HashMap<String, String> getBack() {return back;}
public String getBack(String lang){return back.get(lang)!=null?back.get(lang):back.get(defaultLanguage);}
public void setBack(HashMap<String, String> back) {this.back = back;}
Display More
Um die Daten zu laden oder zu erstellen, wird:
model3DLang = new PlaceGameObjectLang();
File fileCongigPhat = new File(getPath()+System.getProperty("file.separator")+"Asset");
if ( fileCongigPhat.mkdirs() )
System.out.println("Erstelle: " + fileCongigPhat.getAbsolutePath() );
ClassPluginJSONManager jm = new ClassPluginJSONManager();
jm.banList.add("defaultLanguage");
String configFile = getPath()+System.getProperty("file.separator")+"Asset"+System.getProperty("file.separator")+"Language.json";
model3DLang = (PlaceGameObjectLang) jm.update(model3DLang,configFile);
Display More
In den Zeilen:
4. - wird die Dynamische Sprach Klasse erstellt.
6-9. - hier wird ein Unterverzeichnis angelegt, wenn es nicht vorhanden ist.
11. - hier wird der JASO-Manager initialisiert.
12. - mit der banListe, können die Variablen eingetragen werden, die beim Erstellen der Datei nicht angelegt werden. Sind diese Parameter in der Datei vorhanden, werden sie auch geladen.
13. - ein String des Speicherorts.
14. - hier wird die in Zeile 4. erstellte Klasse mit den aktualisierten Daten überschrieben.
Da unsere Sprach Klasse schon eine Prüfung des Ländercodes hat, können die Texte einfach mit:
System.out.println( model3DLang.getUi3D().getExit(player.getLanguage()) );
System.out.println( lang.getRadial().getBack(player.getLanguage()) );
ausgelesen werden.
"de" : " Wähle ein Bundel aus! ",
"en" : " Pick a bundle! "
Display More