From 0e0cfbb15b0ea0ae922e5be26494cad5c3cfed3c Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 15 May 2011 13:18:38 +0000 Subject: [PATCH] More translation stuff. Check if the version of a translation file is up to date with essentials version. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1480 e251c2fe-e539-e718-e476-b85c1f46cddb --- Essentials/src/com/earth2me/essentials/Util.java | 12 +++++++++++- .../com/earth2me/essentials/commands/Commandmsg.java | 8 ++++---- .../com/earth2me/essentials/commands/Commandr.java | 4 ++-- Essentials/src/messages.properties | 5 ++++- Essentials/src/messages_de.properties | 5 ++++- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index ed1ea2d0b..064103934 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -1,8 +1,10 @@ package com.earth2me.essentials; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -15,6 +17,8 @@ import java.util.Enumeration; import java.util.GregorianCalendar; import java.util.Locale; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.bukkit.Location; @@ -331,9 +335,15 @@ public class Util { try { + BufferedReader br = new BufferedReader(new FileReader(file)); + String version = br.readLine(); + if (version == null || !version.equals("#version: "+Essentials.getStatic().getDescription().getVersion())) { + Logger.getLogger("Minecraft").log(Level.WARNING, "Translation file "+file+" is not updated for Essentials version. Will use default."); + return cl.getResourceAsStream(string); + } return new FileInputStream(file); } - catch (FileNotFoundException ex) + catch (IOException ex) { return cl.getResourceAsStream(string); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 13ad11441..60fa04e97 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -32,9 +32,9 @@ public class Commandmsg extends EssentialsCommand if (args[0].equalsIgnoreCase(Console.NAME)) { - sender.sendMessage("[" + translatedMe + " -> " + Console.NAME + "§f] " + message); + sender.sendMessage(Util.format("msgFormat", translatedMe, Console.NAME, message)); CommandSender cs = Console.getCommandSender(server); - cs.sendMessage("[" + senderName + " -> " + translatedMe + "§f] " + message); + cs.sendMessage(Util.format("msgFormat", senderName, translatedMe, message)); replyTo.setReplyTo(cs); Console.getConsoleReplyTo().setReplyTo(sender); return; @@ -55,8 +55,8 @@ public class Commandmsg extends EssentialsCommand { continue; } - sender.sendMessage("[" + translatedMe + " -> " + p.getDisplayName() + "§f] " + message); - p.sendMessage("[" + senderName + " -> " + translatedMe + "§f] " + message); + sender.sendMessage(Util.format("msgFormat", translatedMe, p.getDisplayName(), message)); + p.sendMessage(Util.format("msgFormat", senderName, translatedMe, message)); replyTo.setReplyTo(ess.getUser(p)); ess.getUser(p).setReplyTo(sender); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index bc83ca82d..0d68fda1f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -36,7 +36,7 @@ public class Commandr extends EssentialsCommand } charge(sender); - sender.sendMessage("[" + Util.i18n("me")+ " -> " + targetName + "] " + message); + sender.sendMessage(Util.format("msgFormat", Util.i18n("me"), targetName, message)); if (target instanceof Player) { User u = ess.getUser(target); @@ -45,7 +45,7 @@ public class Commandr extends EssentialsCommand return; } } - target.sendMessage("[" + senderName + " -> " + Util.i18n("me") +"] " + message); + target.sendMessage(Util.format("msgFormat", senderName, Util.i18n("me"), message)); replyTo.setReplyTo(target); if (target != sender) { diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index f460553f9..4bbd66f8d 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -1,3 +1,5 @@ +#version: TeamCity +# Translations start here loadinfo = Loaded {0} build {1} by {2} markedAsNotAway = \u00a77You are no longer marked as away. markedAsAway = \u00a77You are now marked as away. @@ -303,4 +305,5 @@ onlyPlayers = Only in-game players can use {0}. unignorePlayer = You are not ignoring player {0} anymore. ignorePlayer = You ignore player {0} from now on. illegalDate = Illegal date format. -timePattern = (?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)? \ No newline at end of file +timePattern = (?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)? +msgFormat = [{0} -> {1}\u00a7f] {2} \ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 016aa95e1..9f19d5173 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -1,3 +1,5 @@ +#version: TeamCity +# Translations start here loadinfo = Plugin {0} Version {1} geladen, erstellt von {2}, \u00fcbersetzt von snowleo markedAsNotAway = \u00a77Du wirst nicht mehr als abwesend angezeigt. markedAsAway = \u00a77Du wirst als abwesend angezeigt. @@ -303,4 +305,5 @@ onlyPlayers = Only in-game players can use {0}. unignorePlayer = You are not ignoring player {0} anymore. ignorePlayer = You ignore player {0} from now on. illegalDate = Illegal date format. -timePattern = (?:([0-9]+)\\s*[yj][a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*[dt][a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:h|st)[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)? \ No newline at end of file +timePattern = (?:([0-9]+)\\s*[yj][a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*[dt][a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:h|st)[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)? +msgFormat = [{0} -> {1}\u00a7f] {2} \ No newline at end of file