From 5ea7d49c34c7d5dd456ef017b469a1370d74ea40 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sun, 5 Sep 2010 16:25:18 +0200 Subject: [PATCH] I18N: All handlers now read their string from resources --- src/org/yaaic/command/handler/HelpHandler.java | 11 +++++++---- src/org/yaaic/command/handler/JoinHandler.java | 2 +- src/org/yaaic/command/handler/KickHandler.java | 4 ++-- src/org/yaaic/command/handler/MeHandler.java | 4 ++-- src/org/yaaic/command/handler/ModeHandler.java | 2 +- src/org/yaaic/command/handler/MsgHandler.java | 2 +- src/org/yaaic/command/handler/NamesHandler.java | 3 ++- src/org/yaaic/command/handler/NickHandler.java | 2 +- src/org/yaaic/command/handler/NoticeHandler.java | 2 +- src/org/yaaic/command/handler/OpHandler.java | 4 ++-- src/org/yaaic/command/handler/PartHandler.java | 4 ++-- src/org/yaaic/command/handler/QueryHandler.java | 6 +++--- src/org/yaaic/command/handler/RawHandler.java | 2 +- src/org/yaaic/command/handler/TopicHandler.java | 2 +- src/org/yaaic/command/handler/VoiceHandler.java | 4 ++-- src/org/yaaic/command/handler/WhoisHandler.java | 2 +- 16 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/org/yaaic/command/handler/HelpHandler.java b/src/org/yaaic/command/handler/HelpHandler.java index 2a177a4..a18c368 100644 --- a/src/org/yaaic/command/handler/HelpHandler.java +++ b/src/org/yaaic/command/handler/HelpHandler.java @@ -55,7 +55,7 @@ public class HelpHandler extends BaseHandler } else if (params.length == 1) { showAllCommands(service, server, conversation); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } @@ -70,7 +70,9 @@ public class HelpHandler extends BaseHandler { CommandParser cp = CommandParser.getInstance(); - StringBuffer commandList = new StringBuffer("Available commands: \n"); + StringBuffer commandList = new StringBuffer(service.getString(R.string.available_commands)); + commandList.append("\n"); + HashMap commands = cp.getCommands(); HashMap aliases = cp.getAliases(); @@ -81,7 +83,7 @@ public class HelpHandler extends BaseHandler String alias = ""; for (Object aliasCommand : aliasesKeys) { if (command.equals(aliases.get(aliasCommand))) { - alias = " or /" + aliasCommand; + alias = " " + service.getString(R.string.logical_or) + " /" + aliasCommand; break; } } @@ -116,6 +118,7 @@ public class HelpHandler extends BaseHandler HashMap commands = cp.getCommands(); if (commands.containsKey(command)) { + // XXX:I18N - String building salad :) Message message = new Message("Help of /" + command + "\n" + commands.get(command).getUsage() + "\n" + commands.get(command).getDescription(service) + "\n"); message.setColor(Message.COLOR_YELLOW); conversation.addMessage(message); @@ -128,7 +131,7 @@ public class HelpHandler extends BaseHandler service.sendBroadcast(intent); } else { - throw new CommandException("Unknown command: " + command); + throw new CommandException(service.getString(R.string.unknown_command, command)); } } diff --git a/src/org/yaaic/command/handler/JoinHandler.java b/src/org/yaaic/command/handler/JoinHandler.java index f1c9fd2..59867e1 100644 --- a/src/org/yaaic/command/handler/JoinHandler.java +++ b/src/org/yaaic/command/handler/JoinHandler.java @@ -47,7 +47,7 @@ public class JoinHandler extends BaseHandler } else if (params.length == 3) { service.getConnection(server.getId()).joinChannel(params[1], params[2]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/KickHandler.java b/src/org/yaaic/command/handler/KickHandler.java index 533e538..0c52a32 100644 --- a/src/org/yaaic/command/handler/KickHandler.java +++ b/src/org/yaaic/command/handler/KickHandler.java @@ -45,13 +45,13 @@ public class KickHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } if (params.length == 2) { service.getConnection(server.getId()).kick(conversation.getName(), params[1]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/MeHandler.java b/src/org/yaaic/command/handler/MeHandler.java index ea41531..ecaac22 100644 --- a/src/org/yaaic/command/handler/MeHandler.java +++ b/src/org/yaaic/command/handler/MeHandler.java @@ -46,7 +46,7 @@ public class MeHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() == Conversation.TYPE_SERVER) { - throw new CommandException("Only usable from within a channel or a query"); + throw new CommandException(service.getString(R.string.only_usable_from_channel_or_query)); } if (params.length > 1) { @@ -66,7 +66,7 @@ public class MeHandler extends BaseHandler service.getConnection(server.getId()).sendAction(conversation.getName(), action); } else { - throw new CommandException("Text is missing"); + throw new CommandException(service.getString(R.string.text_missing)); } } diff --git a/src/org/yaaic/command/handler/ModeHandler.java b/src/org/yaaic/command/handler/ModeHandler.java index 3e2f9c4..c3fe7a3 100644 --- a/src/org/yaaic/command/handler/ModeHandler.java +++ b/src/org/yaaic/command/handler/ModeHandler.java @@ -49,7 +49,7 @@ public class ModeHandler extends BaseHandler service.getConnection(server.getId()).setMode(params[1], modes); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/MsgHandler.java b/src/org/yaaic/command/handler/MsgHandler.java index fbf7c75..68d4aaa 100644 --- a/src/org/yaaic/command/handler/MsgHandler.java +++ b/src/org/yaaic/command/handler/MsgHandler.java @@ -66,7 +66,7 @@ public class MsgHandler extends BaseHandler service.sendBroadcast(intent); } } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/NamesHandler.java b/src/org/yaaic/command/handler/NamesHandler.java index 03c6c80..f3c5241 100644 --- a/src/org/yaaic/command/handler/NamesHandler.java +++ b/src/org/yaaic/command/handler/NamesHandler.java @@ -48,9 +48,10 @@ public class NamesHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } + // XXX:I18N - Translation needed! StringBuffer userList = new StringBuffer("Users " + conversation.getName() + ":"); User[] mUsers = service.getConnection(server.getId()).getUsers(conversation.getName()); diff --git a/src/org/yaaic/command/handler/NickHandler.java b/src/org/yaaic/command/handler/NickHandler.java index 99860b8..8bebab9 100644 --- a/src/org/yaaic/command/handler/NickHandler.java +++ b/src/org/yaaic/command/handler/NickHandler.java @@ -45,7 +45,7 @@ public class NickHandler extends BaseHandler if (params.length == 2) { service.getConnection(server.getId()).changeNick(params[1]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/NoticeHandler.java b/src/org/yaaic/command/handler/NoticeHandler.java index 507bb0b..eb00197 100644 --- a/src/org/yaaic/command/handler/NoticeHandler.java +++ b/src/org/yaaic/command/handler/NoticeHandler.java @@ -63,7 +63,7 @@ public class NoticeHandler extends BaseHandler service.getConnection(server.getId()).sendNotice(params[1], text); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/OpHandler.java b/src/org/yaaic/command/handler/OpHandler.java index 94810cd..b16e975 100644 --- a/src/org/yaaic/command/handler/OpHandler.java +++ b/src/org/yaaic/command/handler/OpHandler.java @@ -43,13 +43,13 @@ public class OpHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } if (params.length == 2) { service.getConnection(server.getId()).op(conversation.getName(), params[1]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/PartHandler.java b/src/org/yaaic/command/handler/PartHandler.java index 3e211b3..cbadbc8 100644 --- a/src/org/yaaic/command/handler/PartHandler.java +++ b/src/org/yaaic/command/handler/PartHandler.java @@ -46,14 +46,14 @@ public class PartHandler extends BaseHandler { if (params.length == 1) { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } service.getConnection(server.getId()).partChannel(conversation.getName()); } else if (params.length == 2) { service.getConnection(server.getId()).partChannel(params[1]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/QueryHandler.java b/src/org/yaaic/command/handler/QueryHandler.java index 7355b65..0023817 100644 --- a/src/org/yaaic/command/handler/QueryHandler.java +++ b/src/org/yaaic/command/handler/QueryHandler.java @@ -50,13 +50,13 @@ public class QueryHandler extends BaseHandler if (params.length == 2) { // Simple validation if (params[1].startsWith("#")) { - throw new CommandException("You cannot open queries to channels"); + throw new CommandException(service.getString(R.string.query_to_channel)); } Conversation query = server.getConversation(params[1]); if (query != null) { - throw new CommandException("Query already exists"); + throw new CommandException(service.getString(R.string.query_exists)); } query = new Query(params[1]); @@ -69,7 +69,7 @@ public class QueryHandler extends BaseHandler ); service.sendBroadcast(intent); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/RawHandler.java b/src/org/yaaic/command/handler/RawHandler.java index 520a425..9c1f4b2 100644 --- a/src/org/yaaic/command/handler/RawHandler.java +++ b/src/org/yaaic/command/handler/RawHandler.java @@ -48,7 +48,7 @@ public class RawHandler extends BaseHandler String line = BaseHandler.mergeParams(params); service.getConnection(server.getId()).sendRawLineViaQueue(line); } else { - throw new CommandException("Line is missing"); + throw new CommandException(service.getString(R.string.line_missing)); } } diff --git a/src/org/yaaic/command/handler/TopicHandler.java b/src/org/yaaic/command/handler/TopicHandler.java index 91a232e..608667f 100644 --- a/src/org/yaaic/command/handler/TopicHandler.java +++ b/src/org/yaaic/command/handler/TopicHandler.java @@ -46,7 +46,7 @@ public class TopicHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } Channel channel = (Channel) conversation; diff --git a/src/org/yaaic/command/handler/VoiceHandler.java b/src/org/yaaic/command/handler/VoiceHandler.java index a4cb872..bc96a29 100644 --- a/src/org/yaaic/command/handler/VoiceHandler.java +++ b/src/org/yaaic/command/handler/VoiceHandler.java @@ -43,13 +43,13 @@ public class VoiceHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (conversation.getType() != Conversation.TYPE_CHANNEL) { - throw new CommandException("Only usable from within a channel"); + throw new CommandException(service.getString(R.string.only_usable_from_channel)); } if (params.length == 2) { service.getConnection(server.getId()).voice(conversation.getName(), params[1]); } else { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } } diff --git a/src/org/yaaic/command/handler/WhoisHandler.java b/src/org/yaaic/command/handler/WhoisHandler.java index 50d0a89..7308299 100644 --- a/src/org/yaaic/command/handler/WhoisHandler.java +++ b/src/org/yaaic/command/handler/WhoisHandler.java @@ -45,7 +45,7 @@ public class WhoisHandler extends BaseHandler public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException { if (params.length != 2) { - throw new CommandException("Invalid number of params"); + throw new CommandException(service.getString(R.string.invalid_number_of_params)); } service.getConnection(server.getId()).sendRawLineViaQueue("WHOIS " + params[1]);