Translate the last of the strings

This commit is contained in:
fullwall 2012-10-08 10:16:19 +08:00
parent 03bcb9f4cf
commit 5b380cf96e
12 changed files with 232 additions and 165 deletions

View File

@ -234,7 +234,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
scheduleSaveTask(Setting.SAVE_TASK_DELAY.asInt());
Bukkit.getPluginManager().callEvent(new CitizensEnableEvent());
}
}) == -1) {
}, 1) == -1) {
Messaging.severeTr(Messages.LOAD_TASK_NOT_SCHEDULED);
getServer().getPluginManager().disablePlugin(this);
}
@ -325,7 +325,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
default:
break;
}
Translator.setInstance(new File(getDataFolder(), "i18n"), locale);
Translator.setInstance(new File(getDataFolder(), "lang"), locale);
Messaging.logTr(Messages.LOCALE_NOTIFICATION, locale);
}

View File

@ -15,6 +15,7 @@ import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.CitizensNPCRegistry;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Util;
import org.bukkit.entity.EntityType;
@ -34,14 +35,10 @@ public class NPCDataStore {
continue;
}
String unparsedEntityType = key.getString("traits.type", "PLAYER");
EntityType type = EntityType.fromName(unparsedEntityType);
EntityType type = Util.matchEntityType(unparsedEntityType);
if (type == null) {
try {
type = EntityType.valueOf(unparsedEntityType);
} catch (IllegalArgumentException ex) {
Messaging.logTr(Messages.LOAD_UNKNOWN_NPC_TYPE, unparsedEntityType);
continue;
}
Messaging.logTr(Messages.LOAD_UNKNOWN_NPC_TYPE, unparsedEntityType);
continue;
}
NPC npc = registry.createNPC(type, id, key.getString("name"));
((CitizensNPC) npc).load(key);

View File

@ -11,6 +11,8 @@ public @interface Command {
String flags() default "";
String help() default "";
int max() default -1;
int min() default 0;

View File

@ -30,7 +30,7 @@ public class HelpCommands {
@Command(
aliases = { "citizens" },
usage = "help (page)",
usage = "help (page|command)",
desc = "Citizens help menu",
modifiers = { "help" },
min = 1,
@ -38,7 +38,12 @@ public class HelpCommands {
permission = "help")
@Requirements
public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
int page = 1;
try {
page = args.argsLength() == 2 ? args.getInteger(1) : page;
} catch (NumberFormatException e) {
sendSpecificHelp(sender, "citizens", args.getString(1));
}
sendHelp(sender, "citizens", page);
}
@ -63,7 +68,7 @@ public class HelpCommands {
@Command(
aliases = { "npc" },
usage = "help (page)",
usage = "help (page|command)",
desc = "NPC help menu",
modifiers = { "help" },
min = 1,
@ -71,13 +76,18 @@ public class HelpCommands {
permission = "npc.help")
@Requirements
public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
int page = 1;
try {
page = args.argsLength() == 2 ? args.getInteger(1) : page;
} catch (NumberFormatException e) {
sendSpecificHelp(sender, "npc", args.getString(1));
}
sendHelp(sender, "NPC", page);
}
@Command(
aliases = { "script" },
usage = "help (page)",
usage = "help (page|command)",
desc = "Script help menu",
modifiers = { "help" },
min = 1,
@ -85,7 +95,12 @@ public class HelpCommands {
permission = "script.help")
@Requirements
public void scriptHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
int page = 1;
try {
page = args.argsLength() == 2 ? args.getInteger(1) : page;
} catch (NumberFormatException e) {
sendSpecificHelp(sender, "script", args.getString(1));
}
sendHelp(sender, "script", page);
}
@ -98,9 +113,14 @@ public class HelpCommands {
throw new CommandException(Messages.COMMAND_PAGE_MISSING, page);
}
private void sendSpecificHelp(CommandSender sender, String string, String string2) {
// TODO Auto-generated method stub
}
@Command(
aliases = { "template", "tpl" },
usage = "help (page)",
usage = "help (page|command)",
desc = "Template help menu",
modifiers = { "help" },
min = 1,
@ -108,13 +128,18 @@ public class HelpCommands {
permission = "templates.help")
@Requirements
public void templatesHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
int page = 1;
try {
page = args.argsLength() == 2 ? args.getInteger(1) : page;
} catch (NumberFormatException e) {
sendSpecificHelp(sender, "templates", args.getString(1));
}
sendHelp(sender, "templates", page);
}
@Command(
aliases = { "waypoint", "waypoint", "wp" },
usage = "help (page)",
usage = "help (page|command)",
desc = "Waypoints help menu",
modifiers = { "help" },
min = 1,
@ -122,7 +147,12 @@ public class HelpCommands {
permission = "waypoints.help")
@Requirements
public void waypointsHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
int page = 1;
try {
page = args.argsLength() == 2 ? args.getInteger(1) : page;
} catch (NumberFormatException e) {
sendSpecificHelp(sender, "waypoints", args.getString(1));
}
sendHelp(sender, "waypoints", page);
}
}

View File

@ -79,29 +79,32 @@ public class NPCCommands {
Age trait = npc.getTrait(Age.class);
boolean toggleLock = args.hasFlag('l');
if (toggleLock)
Messaging.send(sender, "<a>Age " + (trait.toggle() ? "locked" : "unlocked") + ".");
if (toggleLock) {
Messaging.sendTr(sender, trait.toggle() ? Messages.AGE_LOCKED : Messages.AGE_UNLOCKED);
}
if (args.argsLength() <= 1) {
if (!toggleLock)
trait.describe(sender);
return;
}
int age = 0;
try {
age = args.getInteger(1);
if (age < -24000 || age > 0)
throw new CommandException(Messages.INVALID_AGE);
Messaging.sendTr(sender, Messages.AGE_SET_NORMAL, npc.getName(), age);
} catch (NumberFormatException ex) {
if (args.getString(1).equalsIgnoreCase("baby")) {
age = -24000;
Messaging.sendTr(sender, Messages.AGE_SET_BABY, npc.getName());
} else if (args.getString(1).equalsIgnoreCase("adult")) {
age = 0;
Messaging.sendTr(sender, Messages.AGE_SET_ADULT, npc.getName());
} else
throw new CommandException(Messages.INVALID_AGE);
}
if (args.argsLength() > 1) {
int age = 0;
String ageStr = "an adult";
try {
age = args.getInteger(1);
if (age < -24000 || age > 0)
throw new CommandException(Messages.INVALID_AGE);
ageStr = "age " + StringHelper.wrap(age);
} catch (NumberFormatException ex) {
if (args.getString(1).equalsIgnoreCase("baby")) {
age = -24000;
ageStr = "a baby";
} else if (!args.getString(1).equalsIgnoreCase("adult"))
throw new CommandException(Messages.INVALID_AGE);
}
trait.setAge(age);
Messaging.sendTr(sender, Messages.AGE_SET, npc.getName(), ageStr);
} else if (!toggleLock)
trait.describe(sender);
trait.setAge(age);
}
@Command(
@ -358,9 +361,8 @@ public class NPCCommands {
max = 1,
permission = "npc.lookclose")
public void lookClose(CommandContext args, CommandSender sender, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will "
+ (npc.getTrait(LookClose.class).toggle() ? "now rotate" : "no longer rotate");
Messaging.send(sender, msg + " when a player is nearby.");
Messaging.sendTr(sender, npc.getTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET
: Messages.LOOKCLOSE_STOPPED, npc.getName());
}
@Command(
@ -399,13 +401,13 @@ public class NPCCommands {
String[] parts = Iterables.toArray(Splitter.on(':').split(args.getJoinedStrings(1, ':')),
String.class);
if (parts.length != 4 && parts.length != 3)
throw new CommandException("Format is x:y:z(:world) or x y z( world)");
throw new CommandException(Messages.MOVETO_FORMAT);
double x = Double.parseDouble(parts[0]);
double y = Double.parseDouble(parts[1]);
double z = Double.parseDouble(parts[2]);
World world = parts.length == 4 ? Bukkit.getWorld(parts[3]) : current.getWorld();
if (world == null)
throw new CommandException("world not found");
throw new CommandException(Messages.MOVETO_WORLD_NOT_FOUND);
to = new Location(world, x, y, z, current.getYaw(), current.getPitch());
} else {
to = current.clone();
@ -422,13 +424,14 @@ public class NPCCommands {
if (args.hasValueFlag("world")) {
World world = Bukkit.getWorld(args.getFlag("world"));
if (world == null)
throw new CommandException("Given world not found.");
throw new CommandException(Messages.MOVETO_WORLD_NOT_FOUND);
to.setWorld(world);
}
}
npc.getBukkitEntity().teleport(to, TeleportCause.COMMAND);
Messaging.send(sender, StringHelper.wrap(npc.getName()) + " was teleported to " + to + ".");
Messaging.sendTr(sender, Messages.MOVETO_TELEPORTED, npc.getName(), to);
}
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0)
@ -463,8 +466,8 @@ public class NPCCommands {
throw new CommandException(Messages.ALREADY_OWNER, name, npc.getName());
ownerTrait.setOwner(name);
boolean serverOwner = name.equalsIgnoreCase(Owner.SERVER);
Messaging.send(sender, (serverOwner ? "[[The server]]" : StringHelper.wrap(name))
+ " is now the owner of " + StringHelper.wrap(npc.getName()) + ".");
Messaging.sendTr(sender, serverOwner ? Messages.OWNER_SET_SERVER : Messages.OWNER_SET, npc.getName(),
name);
}
@Command(
@ -539,9 +542,8 @@ public class NPCCommands {
permission = "npc.power")
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, CommandSender sender, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will "
+ (npc.getTrait(Powered.class).toggle() ? "now" : "no longer");
Messaging.send(sender, msg += " be powered.");
Messaging.sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET
: Messages.POWERED_STOPPED);
}
@Command(
@ -571,7 +573,7 @@ public class NPCCommands {
public void remove(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.argsLength() == 2) {
if (!args.getString(1).equalsIgnoreCase("all"))
throw new CommandException("Incorrect syntax. /npc remove (all)");
throw new CommandException(Messages.REMOVE_INCORRECT_SYNTAX);
if (!sender.hasPermission("citizens.npc.remove.all") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
npcRegistry.deregisterAll();

View File

@ -7,9 +7,9 @@ import net.citizensnpcs.npc.CitizensMobNPC;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util;
import net.minecraft.server.EntityLightning;
import net.minecraft.server.EntityPig;
@ -33,13 +33,13 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable {
if (!getBukkitEntity().hasSaddle()) {
getTrait(Saddle.class).toggle();
hand.setAmount(0);
Messaging.send(equipper, StringHelper.wrap(getName()) + " is now saddled.");
Messaging.sendTr(equipper, Messages.SADDLED_SET, getName());
}
} else if (getBukkitEntity().hasSaddle()) {
equipper.getWorld().dropItemNaturally(getBukkitEntity().getLocation(),
new ItemStack(Material.SADDLE, 1));
getTrait(Saddle.class).toggle();
Messaging.send(equipper, StringHelper.wrap(getName()) + " is no longer saddled.");
Messaging.sendTr(equipper, Messages.SADDLED_STOPPED, getName());
}
}

View File

@ -11,7 +11,6 @@ import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.StringHelper;
import net.citizensnpcs.util.Util;
import net.minecraft.server.EntitySheep;
import net.minecraft.server.World;
@ -32,8 +31,8 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable {
@Override
public void equip(Player equipper, ItemStack hand) {
if (hand.getType() == Material.SHEARS) {
Messaging.send(equipper, StringHelper.wrap(getName()) + " is "
+ (getTrait(Sheared.class).toggle() ? "now" : "no longer") + " sheared.");
Messaging.sendTr(equipper, getTrait(Sheared.class).toggle() ? Messages.SHEARED_SET
: Messages.SHEARED_STOPPED, getName());
} else if (hand.getType() == Material.INK_SACK) {
if (getBukkitEntity().getColor() == DyeColor.getByData((byte) (15 - hand.getData().getData())))
return;

View File

@ -25,11 +25,12 @@ public class StartPrompt extends StringPrompt {
else if (input.equalsIgnoreCase("remove"))
return new TextRemovePrompt(text);
else if (input.equalsIgnoreCase("random"))
Messaging.send(sender, "[[Random talker]] set to [[" + text.toggleRandomTalker() + "]].");
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
else if (input.equalsIgnoreCase("realistic looking"))
Messaging.send(sender, "[[Realistic looking]] set to [[" + text.toggleRealisticLooking() + "]].");
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET,
text.toggleRealisticLooking());
else if (input.equalsIgnoreCase("close"))
Messaging.send(sender, "[[Close talker]] set to [[" + text.toggle() + "]].");
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
else if (input.equalsIgnoreCase("help")) {
context.setSessionData("said-text", false);
Messaging.send(sender, getPromptText(context));

View File

@ -1,22 +1,12 @@
package net.citizensnpcs.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ListResourceBundle;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import com.google.common.io.Closeables;
public class Messages {
public static final String AGE_SET = "citizens.commands.npc.age.set";
public static final String AGE_LOCKED = "citizens.commands.npc.age.locked";
public static final String AGE_SET_ADULT = "citizens.commands.npc.age.set-adult";
public static final String AGE_SET_BABY = "citizens.commands.npc.age.set-baby";
public static final String AGE_SET_NORMAL = "citizens.commands.npc.age.set-normal";
public static final String AGE_TRAIT_DESCRIPTION = "citizens.traits.age-description";
public static final String AGE_UNLOCKED = "citizens.commands.npc.age.unlocked";
public static final String ALREADY_IN_EDITOR = "citizens.editors.already-in-editor";
public static final String ALREADY_OWNER = "citizens.commands.npc.owner.already-owner";
public static final String AVAILABLE_WAYPOINT_PROVIDERS = "citizens.waypoints.available-providers-header";
@ -46,7 +36,6 @@ public class Messages {
public static final String CONTROLLABLE_SET = "citizens.commands.npc.controllable.set";
public static final String CURRENT_WAYPOINT_PROVIDER = "citizens.waypoints.current-provider";
public static final String DATABASE_CONNECTION_FAILED = "citizens.notifications.database-connection-failed";
private static ResourceBundle defaultBundle;
public static final String EQUIPMENT_EDITOR_ALL_ITEMS_REMOVED = "citizens.editors.equipment.all-items-removed";
public static final String EQUIPMENT_EDITOR_BEGIN = "citizens.editors.equipment.begin";
public static final String EQUIPMENT_EDITOR_END = "citizens.editors.equipment.end";
@ -82,12 +71,17 @@ public class Messages {
public static final String LOAD_UNKNOWN_NPC_TYPE = "citizens.notifications.unknown-npc-type";
public static final String LOADING_SUB_PLUGIN = "citizens.sub-plugins.load";
public static final String LOCALE_NOTIFICATION = "citizens.notifications.locale";
public static final String LOOKCLOSE_SET = "citizens.commands.npc.lookclose.set";
public static final String LOOKCLOSE_STOPPED = "citizens.commands.npc.lookclose.stopped";
public static final String METRICS_ERROR_NOTIFICATION = "citizens.notifications.metrics-load-error";
public static final String METRICS_NOTIFICATION = "citizens.notifications.metrics-started";
public static final String MINIMUM_COST_REQUIRED = "citizens.economy.minimum-cost-required";
public static final String MISSING_TRANSLATIONS = "citizens.notifications.missing-translations";
public static final String MOBTYPE_CANNOT_BE_AGED = "citizens.commands.npc.age.cannot-be-aged";
public static final String MONEY_WITHDRAWN = "citizens.economy.money-withdrawn";
public static final String MOVETO_FORMAT = "citizens.commands.npc.moveto.format";
public static final String MOVETO_TELEPORTED = "citizens.commands.npc.moveto.teleported";
public static final String MOVETO_WORLD_NOT_FOUND = "citizens.commands.npc.moveto.missing-world";
public static final String NO_NPC_WITH_ID_FOUND = "citizens.commands.npc.spawn.missing-npc-id";
public static final String NO_STORED_SPAWN_LOCATION = "citizens.commands.npc.spawn.no-location";
public static final String NOT_LIVING_MOBTYPE = "citizens.commands.npc.create.not-living-mobtype";
@ -106,16 +100,25 @@ public class Messages {
public static final String NPC_TELEPORTED = "citizens.commands.npc.tphere.teleported";
public static final String NUM_LOADED_NOTIFICATION = "citizens.notifications.npcs-loaded";
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
public static final String OWNER_SET = "citizens.commands.npc.owner.set";
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
public static final String POSE_ADDED = "citizens.commands.npc.pose.added";
public static final String POSE_ALREADY_EXISTS = "citizens.commands.npc.pose.already-exists";
public static final String POSE_MISSING = "citizens.commands.npc.pose.missing";
public static final String POSE_REMOVED = "citizens.commands.npc.pose.removed";
public static final String POWERED_SET = "citizens.commands.npc.powered.set";
public static final String POWERED_STOPPED = "citizens.commands.npc.powered.stopped";
public static final String PROFESSION_SET = "citizens.commands.npc.profession.set";
public static final String REMOVE_INCORRECT_SYNTAX = "citizens.commands.npc.remove.incorrect-syntax";
public static final String REMOVED_ALL_NPCS = "citizens.commands.npc.remove.removed-all";
public static final String SADDLED_SET = "citizens.editors.equipment.saddled-set";
public static final String SADDLED_STOPPED = "citizens.editors.equipment.saddled-stopped";
public static final String SAVE_METHOD_SET_NOTIFICATION = "citizens.notifications.save-method-set";
public static final String SCRIPT_COMPILED = "citizens.commands.script.compiled";
public static final String SCRIPT_COMPILING = "citizens.commands.script.compiling";
public static final String SCRIPT_FILE_MISSING = "citizens.commands.script.file-missing";
public static final String SHEARED_SET = "citizens.editors.equipment.sheared-set";
public static final String SHEARED_STOPPED = "citizens.editors.equipment.sheared-stopped";
public static final String SKIPPING_BROKEN_TRAIT = "citizens.notifications.skipping-broken-trait";
public static final String SKIPPING_INVALID_POSE = "citizens.notifications.skipping-invalid-pose";
public static final String SPEED_MODIFIER_ABOVE_LIMIT = "citizens.commands.npc.speed.modifier-above-limit";
@ -128,6 +131,7 @@ public class Messages {
public static final String TEXT_EDITOR_ADD_PROMPT = "citizens.editors.text.add-prompt";
public static final String TEXT_EDITOR_ADDED_ENTRY = "citizens.editors.text.added-entry";
public static final String TEXT_EDITOR_BEGIN = "citizens.editors.text.begin";
public static final String TEXT_EDITOR_CLOSE_TALKER_SET = "citizens.editors.text.close-talker-set";
public static final String TEXT_EDITOR_EDIT_BEGIN_PROMPT = "citizens.editors.text.edit-begin-prompt";
public static final String TEXT_EDITOR_EDIT_PROMPT = "citizens.editors.text.edit-prompt";
public static final String TEXT_EDITOR_EDITED_TEXT = "citizens.editors.text.edited-text";
@ -137,6 +141,8 @@ public class Messages {
public static final String TEXT_EDITOR_INVALID_INPUT = "citizens.editors.text.invalid-input";
public static final String TEXT_EDITOR_INVALID_PAGE = "citizens.editors.text.invalid-page";
public static final String TEXT_EDITOR_PAGE_PROMPT = "citizens.editors.text.change-page-prompt";
public static final String TEXT_EDITOR_RANDOM_TALKER_SET = "citizens.editors.text.random-talker-set";
public static final String TEXT_EDITOR_REALISTIC_LOOKING_SET = "citizens.editors.text.realistic-looking-set";
public static final String TEXT_EDITOR_REMOVE_PROMPT = "citizens.editors.text.remove-prompt";
public static final String TEXT_EDITOR_REMOVED_ENTRY = "citizens.editors.text.removed-entry";
public static final String TEXT_EDITOR_START_PROMPT = "citizens.editors.text.start-prompt";
@ -153,79 +159,4 @@ public class Messages {
public static final String VULNERABLE_STOPPED = "citizens.commands.npc.vulnerable.stopped";
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider";
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
private static Properties getDefaultBundleProperties() {
Properties defaults = new Properties();
InputStream in = null;
try {
in = Messages.class.getResourceAsStream("/" + Translator.PREFIX + "_en.properties");
defaults.load(in);
} catch (IOException e) {
} finally {
Closeables.closeQuietly(in);
}
return defaults;
}
public static ResourceBundle getDefaultResourceBundle(File resourceDirectory, String fileName) {
if (defaultBundle != null)
return defaultBundle;
resourceDirectory.mkdirs();
File bundleFile = new File(resourceDirectory, fileName);
if (!bundleFile.exists()) {
try {
bundleFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
populateDefaults(bundleFile);
FileInputStream stream = null;
try {
stream = new FileInputStream(bundleFile);
defaultBundle = new PropertyResourceBundle(stream);
} catch (Exception e) {
e.printStackTrace();
defaultBundle = getFallbackResourceBundle();
} finally {
Closeables.closeQuietly(stream);
}
return defaultBundle;
}
private static ResourceBundle getFallbackResourceBundle() {
return new ListResourceBundle() {
@Override
protected Object[][] getContents() {
return new Object[0][0];
}
};
}
private static void populateDefaults(File bundleFile) {
Properties properties = new Properties();
InputStream in = null;
try {
in = new FileInputStream(bundleFile);
properties.load(in);
} catch (IOException e) {
} finally {
Closeables.closeQuietly(in);
}
Properties defaults = getDefaultBundleProperties();
for (Entry<Object, Object> entry : defaults.entrySet()) {
if (!properties.containsKey(entry.getKey()))
properties.put(entry.getKey(), entry.getValue());
}
OutputStream stream = null;
try {
stream = new FileOutputStream(bundleFile);
properties.store(stream, "");
} catch (Exception e) {
e.printStackTrace();
} finally {
Closeables.closeQuietly(stream);
}
}
}

View File

@ -17,9 +17,7 @@ import com.google.common.base.Splitter;
public class Messaging {
private static final Pattern CHAT_NEWLINE = Pattern.compile("<br>|<n>|\\n", Pattern.MULTILINE);
private static final Splitter CHAT_NEWLINE_SPLITTER = Splitter.on(CHAT_NEWLINE);
private static final Joiner SPACE = Joiner.on(" ").useForNull("null");
public static void debug(Object... msg) {
@ -36,7 +34,7 @@ public class Messaging {
}
public static void logTr(String key, Object... msg) {
log(Level.INFO, Translator.tr(key, msg));
log(Level.INFO, Translator.translate(key, msg));
}
public static void send(CommandSender sender, Object... msg) {
@ -48,7 +46,7 @@ public class Messaging {
}
public static void sendErrorTr(CommandSender sender, String key, Object... msg) {
sendMessageTo(sender, ChatColor.RED + Translator.tr(key, msg));
sendMessageTo(sender, ChatColor.RED + Translator.translate(key, msg));
}
private static void sendMessageTo(CommandSender sender, String rawMessage) {
@ -69,7 +67,7 @@ public class Messaging {
}
public static void sendTr(CommandSender sender, String key, Object... msg) {
sendMessageTo(sender, Translator.tr(key, msg));
sendMessageTo(sender, Translator.translate(key, msg));
}
public static void sendWithNPC(CommandSender sender, Object msg, NPC npc) {
@ -92,11 +90,11 @@ public class Messaging {
}
public static void severeTr(String key, Object... messages) {
log(Level.SEVERE, Translator.tr(key, messages));
log(Level.SEVERE, Translator.translate(key, messages));
}
public static String tr(String key, Object... messages) {
return Translator.tr(key, messages);
return Translator.translate(key, messages);
}
public static String tryTranslate(Object possible) {

View File

@ -3,17 +3,24 @@ package net.citizensnpcs.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ListResourceBundle;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
@ -52,7 +59,7 @@ public class Translator {
}
private ResourceBundle getDefaultBundle() {
return Messages.getDefaultResourceBundle(resourceFile, PREFIX + "_en.properties");
return getDefaultResourceBundle(resourceFile, PREFIX + "_en.properties");
}
private MessageFormat getFormatter(String unreplaced) {
@ -158,19 +165,97 @@ public class Translator {
}
}
private static ResourceBundle defaultBundle;
private static Translator instance;
public static final String PREFIX = "messages";
private static Properties getDefaultBundleProperties() {
Properties defaults = new Properties();
InputStream in = null;
try {
in = Messages.class.getResourceAsStream("/" + PREFIX + "_en.properties");
defaults.load(in);
} catch (IOException e) {
} finally {
Closeables.closeQuietly(in);
}
return defaults;
}
private static ResourceBundle getDefaultResourceBundle(File resourceDirectory, String fileName) {
if (Translator.defaultBundle != null)
return Translator.defaultBundle;
resourceDirectory.mkdirs();
File bundleFile = new File(resourceDirectory, fileName);
if (!bundleFile.exists()) {
try {
bundleFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Translator.populateDefaults(bundleFile);
FileInputStream stream = null;
try {
stream = new FileInputStream(bundleFile);
Translator.defaultBundle = new PropertyResourceBundle(stream);
} catch (Exception e) {
e.printStackTrace();
Translator.defaultBundle = Translator.getFallbackResourceBundle();
} finally {
Closeables.closeQuietly(stream);
}
return Translator.defaultBundle;
}
private static ResourceBundle getFallbackResourceBundle() {
return new ListResourceBundle() {
@Override
protected Object[][] getContents() {
return new Object[0][0];
}
};
}
private static void populateDefaults(File bundleFile) {
Properties properties = new Properties();
InputStream in = null;
try {
in = new FileInputStream(bundleFile);
properties.load(in);
} catch (IOException e) {
} finally {
Closeables.closeQuietly(in);
}
Properties defaults = getDefaultBundleProperties();
for (Entry<Object, Object> entry : defaults.entrySet()) {
if (!properties.containsKey(entry.getKey()))
properties.put(entry.getKey(), entry.getValue());
}
OutputStream stream = null;
try {
stream = new FileOutputStream(bundleFile);
properties.store(stream, "");
} catch (Exception e) {
e.printStackTrace();
} finally {
Closeables.closeQuietly(stream);
}
}
public static void setInstance(File resourceFile, Locale locale) {
instance = new Translator(resourceFile, locale);
}
static String tr(String key, Locale preferredLocale, Object... msg) {
public static String translate(String key, Locale preferredLocale, Object... msg) {
return StringHelper.parseColors(msg.length == 0 ? instance.translate(key, preferredLocale) : instance
.format(key, preferredLocale, msg));
}
static String tr(String key, Object... msg) {
return tr(key, instance.defaultLocale, msg);
public static String translate(String key, Object... msg) {
return translate(key, instance.defaultLocale, msg);
}
}

View File

@ -6,7 +6,12 @@ citizens.commands.invalid-mobtype={0} is not a valid mobtype.
citizens.commands.invalid-number=That is not a valid number.
citizens.commands.npc.age.cannot-be-aged=The mob type '{0}' cannot be aged.
citizens.commands.npc.age.invalid-age=Invalid age. Valid ages are adult, baby, number between -24000 and 0
citizens.commands.npc.age.locked=Age locked.
citizens.commands.npc.age.set-adult=[[{0}]] is now an adult.
citizens.commands.npc.age.set-baby=[[{0}]] is now a baby.
citizens.commands.npc.age.set-normal=[[{0}]] is now age [[{1}]].
citizens.commands.npc.age.set=[[{0}]] is now [[{1}]].
citizens.commands.npc.age.unlocked=Age unlocked.
citizens.commands.npc.behaviour.added=Behaviours added.
citizens.commands.npc.behaviour.removed=Behaviours removed.
citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable.
@ -17,16 +22,26 @@ citizens.commands.npc.create.invalid-mobtype='{0}' is not a valid mob type. Usin
citizens.commands.npc.create.not-living-mobtype='{0}' is not a living entity type. Using default type.
citizens.commands.npc.create.npc-name-too-long=NPC names cannot be longer than 16 characters. The name has been shortened.
citizens.commands.npc.despawn.despawned=You despawned [[{0}]].
citizens.commands.npc.lookclose.set=[[{0}]] will now rotate when players are nearby.
citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when players are nearby.
citizens.commands.npc.mount.failed=Couldn't mount [[{0}]].
citizens.commands.npc.moveto.format=Format is x:y:z(:world) or x y z( world).
citizens.commands.npc.moveto.missing-world=World not found.
citizens.commands.npc.moveto.teleported=[[{0}]] teleported to {1}.
citizens.commands.npc.owner.already-owner='{0}' is already the owner of {1}.
citizens.commands.npc.owner.owner=[[{0}]]'s owner is [[{1}]].
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of {0}.
citizens.commands.npc.owner.set=[[{1}]] is now the owner of {0}.
citizens.commands.npc.pose.added=Pose added.
citizens.commands.npc.pose.already-exists=The pose '{0}' already exists.
citizens.commands.npc.pose.invalid-name=Invalid pose name.
citizens.commands.npc.pose.missing=The pose '{1}' does not exist.
citizens.commands.npc.pose.removed=Pose removed.
citizens.commands.npc.powered.set=[[{0}]] will now be powered.
citizens.commands.npc.powered.stopped=[[{0}]] will no longer be powered.
citizens.commands.npc.profession.invalid-profession='{0}' is not a valid profession.
citizens.commands.npc.profession.set=[[{0}]] is now a [[{1}]].
citizens.commands.npc.remove.incorrect-syntax=Incorrect syntax. /npc remove (all)
citizens.commands.npc.remove.removed-all=You permanently removed all NPCs.
citizens.commands.npc.remove.removed=You permanently removed [[{0}]].
citizens.commands.npc.rename.renamed=You renamed [[{0}]] to [[{1}]].
@ -71,11 +86,16 @@ citizens.editors.equipment.all-items-removed=[[{0}]] had all of its items remove
citizens.editors.equipment.begin=<b>Entered the equipment editor!<br>[[Right click]] to equip the NPC!
citizens.editors.equipment.end=Exited the equipment editor.
citizens.editors.equipment.invalid-block=Invalid block!
citizens.editors.equipment.saddled-set=[[{0}]] is now saddled.
citizens.editors.equipment.saddled-stopped=[[{0}]] is no longer saddled.
citizens.editors.equipment.sheared-set=[[{0}]] is now sheared.
citizens.editors.equipment.sheared-stopped=[[{0}]] is no longer sheared.
citizens.editors.equipment.sheep-coloured=[[{0}]] is now coloured [[{1}]].
citizens.editors.text.add-prompt=Enter text to add to the NPC.
citizens.editors.text.added-entry=[[Added]] the entry [[{0}]].
citizens.editors.text.begin=<b>Entered the text editor!
citizens.editors.text.change-page-prompt=Enter a page number to view more text entries.
citizens.editors.text.close-talker-set=[[Close talker]] set to [[{0}]].
citizens.editors.text.edit-begin-prompt=Enter the index of the entry you wish to edit or [[page]] to view more pages.
citizens.editors.text.edit-prompt=Enter text to edit the entry.
citizens.editors.text.edited-text=Changed entry at index [[{0}]]to [[{1}]].
@ -84,6 +104,8 @@ citizens.editors.text.invalid-edit-type=Invalid edit type.
citizens.editors.text.invalid-index='{0}' is not a valid index!
citizens.editors.text.invalid-input=Invalid input.
citizens.editors.text.invalid-page=Invalid page number.
citizens.editors.text.random-talker-set=[[Random talking]] set to [[{0}]].
citizens.editors.text.realistic-looking-set=[[Realistic looking]] set to [[{0}]].
citizens.editors.text.remove-prompt=Enter the index of the entry you wish to remove or [[page]] to view more pages.
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.