LoginSystem/src/test/java/tools/messages/translation/WriteAllExportsTask.java
ljacqu b7a7d5b3bd #989 Create configuration docs page
- Create tool task to generate a doc page with the generated config.yml
- Rename tools.utils.FileUtils to FileIoUtils to avoid naming conflict with fr.xephi.authme.utils.FileUtils
- Make all doc tasks output a success message at the end
- Update all docs pages that have changed
2016-10-23 18:29:42 +02:00

38 lines
1.3 KiB
Java

package tools.messages.translation;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import tools.utils.FileIoUtils;
import tools.utils.ToolsConstants;
import java.io.File;
import java.util.Scanner;
/**
* Task which exports all messages to a local folder.
*/
public class WriteAllExportsTask extends ExportMessagesTask {
private static final String OUTPUT_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "messages/translation/export/";
@Override
public String getTaskName() {
return "writeAllExports";
}
@Override
public void execute(Scanner scanner) {
File[] messageFiles = new File(MESSAGES_FOLDER).listFiles();
if (messageFiles == null || messageFiles.length == 0) {
throw new IllegalStateException("Could not read messages folder");
}
final FileConfiguration defaultMessages = loadDefaultMessages();
for (File file : messageFiles) {
String code = file.getName().substring("messages_".length(), file.getName().length() - ".yml".length());
String json = convertToJson(code, defaultMessages, YamlConfiguration.loadConfiguration(file));
FileIoUtils.writeToFile(OUTPUT_FOLDER + "messages_" + code + ".json", json);
}
}
}