#797 Make two messages translatable

This commit is contained in:
ljacqu 2016-07-02 21:49:01 +02:00
parent 9a5c432509
commit 3984208548
8 changed files with 25 additions and 9 deletions

View File

@ -53,6 +53,16 @@ public class CommandService {
return messages.retrieve(key); return messages.retrieve(key);
} }
/**
* Retrieve a message as a single String by its message key.
*
* @param key The message to retrieve
* @return The message
*/
public String retrieveSingle(MessageKey key) {
return messages.retrieveSingle(key);
}
/** /**
* Retrieve the given property's value. * Retrieve the given property's value.
* *

View File

@ -79,7 +79,7 @@ public class RegisterAdminCommand implements ExecutableCommand {
bukkitService.scheduleSyncDelayedTask(new Runnable() { bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override @Override
public void run() { public void run() {
player.kickPlayer("An admin just registered you, please log in again"); player.kickPlayer(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER));
} }
}); });
} }

View File

@ -42,7 +42,7 @@ public class RecoverEmailCommand extends PlayerCommand {
if (!sendMailSsl.hasAllInformation()) { if (!sendMailSsl.hasAllInformation()) {
ConsoleLogger.showError("Mail API is not set"); ConsoleLogger.showError("Mail API is not set");
commandService.send(player, MessageKey.ERROR); commandService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
return; return;
} }
if (dataSource.isAuthAvailable(playerName)) { if (dataSource.isAuthAvailable(playerName)) {

View File

@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.List; import java.util.List;
import static fr.xephi.authme.output.MessageKey.INCOMPLETE_EMAIL_SETTINGS;
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH; import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
import static fr.xephi.authme.settings.properties.RegistrationSettings.ENABLE_CONFIRM_EMAIL; import static fr.xephi.authme.settings.properties.RegistrationSettings.ENABLE_CONFIRM_EMAIL;
import static fr.xephi.authme.settings.properties.RegistrationSettings.USE_EMAIL_REGISTRATION; import static fr.xephi.authme.settings.properties.RegistrationSettings.USE_EMAIL_REGISTRATION;
@ -68,8 +69,7 @@ public class RegisterCommand extends PlayerCommand {
private void handleEmailRegistration(Player player, List<String> arguments) { private void handleEmailRegistration(Player player, List<String> arguments) {
if (!sendMailSsl.hasAllInformation()) { if (!sendMailSsl.hasAllInformation()) {
player.sendMessage("Cannot register: not all required settings are set for sending emails. " commandService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
+ "Please contact an administrator");
ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email or password is set " ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email or password is set "
+ "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath()); + "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath());
return; return;

View File

@ -143,7 +143,11 @@ public enum MessageKey {
ACCOUNTS_OWNED_SELF("accounts_owned_self", "%count"), ACCOUNTS_OWNED_SELF("accounts_owned_self", "%count"),
ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"); ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"),
KICK_FOR_ADMIN_REGISTER("kicked_admin_registered"),
INCOMPLETE_EMAIL_SETTINGS("incomplete_email_settings");
private String key; private String key;
private String[] tags; private String[] tags;

View File

@ -68,3 +68,5 @@ invalid_name_case: 'You should join using username %valid, not %invalid.'
tempban_max_logins: '&cYou have been temporarily banned for failing to log in too many times.' tempban_max_logins: '&cYou have been temporarily banned for failing to log in too many times.'
accounts_owned_self: 'You own %count accounts:' accounts_owned_self: 'You own %count accounts:'
accounts_owned_other: 'The player %name has %count accounts:' accounts_owned_other: 'The player %name has %count accounts:'
kicked_admin_registered: 'An admin just registered you; please log in again'
incomplete_email_settings: 'Error: not all required settings are set for sending emails. Please contact an admin.'

View File

@ -22,12 +22,10 @@ import org.mockito.runners.MockitoJUnitRunner;
import java.util.Arrays; import java.util.Arrays;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -160,6 +158,8 @@ public class RegisterAdminCommandTest {
given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword); given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
Player player = mock(Player.class); Player player = mock(Player.class);
given(bukkitService.getPlayerExact(user)).willReturn(player); given(bukkitService.getPlayerExact(user)).willReturn(player);
String kickForAdminRegister = "Admin registered you -- log in again";
given(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister);
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
// when // when
@ -174,7 +174,7 @@ public class RegisterAdminCommandTest {
verify(dataSource).saveAuth(captor.capture()); verify(dataSource).saveAuth(captor.capture());
assertAuthHasInfo(captor.getValue(), user, hashedPassword); assertAuthHasInfo(captor.getValue(), user, hashedPassword);
verify(dataSource).setUnlogged(user); verify(dataSource).setUnlogged(user);
verify(player).kickPlayer(argThat(containsString("please log in again"))); verify(player).kickPlayer(kickForAdminRegister);
} }
private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) { private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) {

View File

@ -146,7 +146,7 @@ public class RegisterCommandTest {
command.executeCommand(player, Collections.singletonList("myMail@example.tld")); command.executeCommand(player, Collections.singletonList("myMail@example.tld"));
// then // then
verify(player).sendMessage(argThat(containsString("not all required settings are set for sending emails"))); verify(commandService).send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
verify(sendMailSsl).hasAllInformation(); verify(sendMailSsl).hasAllInformation();
verifyZeroInteractions(management); verifyZeroInteractions(management);
} }