Skip to content

Commit

Permalink
fix: language file duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 7e3be04 commit 8dd1094
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public LangUpdateSubCommand() {

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("translatedata.replaced"));
//this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
if(args.length > 1 && args[1].equalsIgnoreCase("overwrite")) {
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", true);
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("translatedata.replaced"));
} else {
this.portalsCore.getDataStorage().copyDefaultFile("lang/en_GB.lang", "lang/en_GB-new.lang", true);
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("translatedata.replaced") + Lang.translate("translatedata.overwrite"));
}
}

@Override
public boolean hasPermission(CommandSenderContainer sender) {
return sender.isOp() || sender.hasPermission("advancedportals.transupdate");
return sender.isOp() || sender.hasPermission("advancedportals.langupdate");
}

@Override
Expand All @@ -34,11 +40,11 @@ public List<String> onTabComplete(CommandSenderContainer sender, String[] args)

@Override
public String getBasicHelpText() {
return Lang.translate("command.trans.help");
return Lang.translate("command.lang.help");
}

@Override
public String getDetailedHelpText() {
return Lang.translate("command.trans.help");
return Lang.translate("command.lang.help");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
// TODO re-add or figure out a replacement.
//portalsCore.getPortalServices().loadPortals();
//portalsCore.getDestinationServices().loadDestinations();
// TODO also reload stuff like translations.
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.reload.reloaded"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,24 @@ public void storeJson(Object dataHolder, String location) {
* @return if the file is copied, will be false if override is false and the file already existed.
*/
public boolean copyDefaultFile(String fileLoc, boolean overwrite) {
return this.copyDefaultFile(fileLoc, fileLoc, overwrite);
}

/**
* Copies the specified file out of the plugin and into the plugins folder.
*
* @param sourceLoc - location of the file in the jar
* @param fileLoc - location to save the file
* @return if the file is copied, will be false if override is false and the file already existed.
*/
public boolean copyDefaultFile(String sourceLoc, String fileLoc, boolean overwrite) {
File outFile = new File(this.dataFolder, fileLoc);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
if (!outFile.exists() || overwrite) {
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(fileLoc);
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(sourceLoc);
if(inputStream == null) {
return false;
}
Expand All @@ -105,15 +116,15 @@ public boolean copyDefaultFile(String fileLoc, boolean overwrite) {
outStream.close();
} catch (NullPointerException e) {
e.printStackTrace();
this.infoLogger.logWarning("Could not load " + fileLoc + ". The file does" +
this.infoLogger.logWarning("Could not load " + sourceLoc + ". The file does" +
"not exist or there has been an error reading the file.");
return false;
} catch (FileNotFoundException e) {
e.printStackTrace();
this.infoLogger.logWarning("Could not create " + fileLoc);
this.infoLogger.logWarning("Could not create " + sourceLoc);
} catch (IOException e) {
e.printStackTrace();
this.infoLogger.logWarning("File error reading " + fileLoc);
this.infoLogger.logWarning("File error reading " + sourceLoc);
}
}
return true;
Expand Down
91 changes: 0 additions & 91 deletions core/src/resources/lang/de_DE.lang

This file was deleted.

89 changes: 0 additions & 89 deletions core/src/resources/lang/en_GB.lang

This file was deleted.

88 changes: 0 additions & 88 deletions core/src/resources/lang/fr_FR.lang

This file was deleted.

Loading

0 comments on commit 8dd1094

Please sign in to comment.