#1467 Implement messages file migration

- Create messages updater called when a messages YML file is loaded
  - Work in progress
- Does not yet include changes to any message keys
This commit is contained in:
ljacqu
2018-01-24 22:19:25 +01:00
parent b3a191d7e2
commit 820e443b81
9 changed files with 405 additions and 180 deletions
@@ -1,5 +1,8 @@
package fr.xephi.authme.message;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.message.updater.MessageUpdater;
import javax.inject.Inject;
/**
@@ -7,10 +10,35 @@ import javax.inject.Inject;
*/
public class MessagesFileHandler extends AbstractMessageFileHandler {
@Inject // Trigger injection in the superclass
// TODO #1467: With the migration the messages handler has become so different that it would be worth
// to remove the extension and extract common features into a helper class instead
@Inject
private MessageUpdater messageUpdater;
MessagesFileHandler() {
}
@Override
public void reload() {
reloadInternal(false);
}
private void reloadInternal(boolean isFromReload) {
super.reload();
String language = getLanguage();
boolean hasChange = messageUpdater.migrateAndSave(
getUserLanguageFile(), createFilePath(language), createFilePath(DEFAULT_LANGUAGE));
if (hasChange) {
if (isFromReload) {
ConsoleLogger.warning("Migration after reload attempt");
} else {
reloadInternal(true);
}
}
}
@Override
protected String createFilePath(String language) {
return "messages/messages_" + language + ".yml";