1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Remove most instances of non-translatable strings

Oh goodness, this is going to painful to update to 1.13.

We now translate:
 - Computer/Disk ID tooltips
 - /computercraft descriptions, synopsises and usages. The last of these
   may not always be translated when in SMP, as it is sometimes done on
   the server, but the alternative would be more complex than I'm happy
   with.
 - Tracking field names. Might be worth adding descriptions too in the
   future.

Also cleanup a couple of other translation keys, so they're more
consistent with Minecraft.

Closes #141
This commit is contained in:
SquidDev 2019-03-16 10:26:40 +00:00
parent cbfd5aeeee
commit d12bdf50d8
27 changed files with 316 additions and 278 deletions

View File

@ -32,7 +32,8 @@ public interface ILuaContext
* intercepted, or the computer will leak memory and end up in a broken state.
*/
@Nonnull
default Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException {
default Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException
{
Object[] results = pullEventRaw( filter );
if( results.length >= 1 && results[0].equals( "terminate" ) ) throw new LuaException( "Terminated", 0 );
return results;
@ -51,7 +52,8 @@ public interface ILuaContext
* @see #pullEvent(String)
*/
@Nonnull
default Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException {
default Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException
{
return yield( new Object[] { filter } );
}

View File

@ -6,6 +6,8 @@
package dan200.computercraft.core.tracking;
import dan200.computercraft.shared.util.StringUtil;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -13,6 +15,8 @@ import java.util.function.LongFunction;
public class TrackingField
{
public static final String TRANSLATE_PREFIX = "tracking_field.computercraft.";
private static final Map<String, TrackingField> fields = new HashMap<>();
public static final TrackingField TASKS = TrackingField.of( "tasks", "Tasks", x -> String.format( "%4d", x ) );
@ -38,7 +42,7 @@ public class TrackingField
public static final TrackingField COROUTINES_DISPOSED = TrackingField.of( "coroutines_dead", "Coroutines disposed", x -> String.format( "%4d", x ) );
private final String id;
private final String displayName;
private final String translationKey;
private final LongFunction<String> format;
public String id()
@ -46,15 +50,21 @@ public class TrackingField
return id;
}
public String displayName()
public String translationKey()
{
return displayName;
return translationKey;
}
private TrackingField( String id, String displayName, LongFunction<String> format )
@Deprecated
public String displayName()
{
return StringUtil.translate( translationKey() );
}
private TrackingField( String id, LongFunction<String> format )
{
this.id = id;
this.displayName = displayName;
this.translationKey = "tracking_field.computercraft." + id + ".name";
this.format = format;
}
@ -65,7 +75,7 @@ public class TrackingField
public static TrackingField of( String id, String displayName, LongFunction<String> format )
{
TrackingField field = new TrackingField( id, displayName, format );
TrackingField field = new TrackingField( id, format );
fields.put( id, field );
return field;
}

View File

@ -52,17 +52,9 @@ public final class CommandComputerCraft extends CommandDelegate
private static ISubCommand create()
{
CommandRoot root = new CommandRoot(
"computercraft", "Various commands for controlling computers.",
"The /computercraft command provides various debugging and administrator tools for controlling and " +
"interacting with computers."
);
CommandRoot root = new CommandRoot( "computercraft" );
root.register( new SubCommandBase(
"dump", "[id]", "Display the status of computers.", UserLevel.OWNER_OP,
"Display the status of all computers or specific information about one computer. You can specify the " +
"computer's instance id (e.g. 123), computer id (e.g #123) or label (e.g. \"@My Computer\")."
)
root.register( new SubCommandBase( "dump", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -149,11 +141,7 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
root.register( new SubCommandBase(
"shutdown", "[ids...]", "Shutdown computers remotely.", UserLevel.OWNER_OP,
"Shutdown the listed computers or all if none are specified. You can specify the computer's instance id " +
"(e.g. 123), computer id (e.g #123) or label (e.g. \"@My Computer\")."
)
root.register( new SubCommandBase( "shutdown", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -165,7 +153,7 @@ public final class CommandComputerCraft extends CommandDelegate
if( computer.isOn() ) shutdown++;
computer.shutdown();
}
context.getSender().sendMessage( text( "Shutdown " + shutdown + " / " + computers.size() + " computers" ) );
context.getSender().sendMessage( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ) );
} );
}
@ -179,11 +167,7 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
root.register( new SubCommandBase(
"turn-on", "ids...", "Turn computers on remotely.", UserLevel.OWNER_OP,
"Turn on the listed computers. You can specify the computer's instance id (e.g. 123), computer id (e.g #123) " +
"or label (e.g. \"@My Computer\")."
)
root.register( new SubCommandBase( "turn-on", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -195,7 +179,7 @@ public final class CommandComputerCraft extends CommandDelegate
if( !computer.isOn() ) on++;
computer.turnOn();
}
context.getSender().sendMessage( text( "Turned on " + on + " / " + computers.size() + " computers" ) );
context.getSender().sendMessage( translate( "commands.computercraft.turn_on.done", on, computers.size() ) );
} );
}
@ -209,11 +193,7 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
root.register( new SubCommandBase(
"tp", "<id>", "Teleport to a specific computer.", UserLevel.OP,
"Teleport to the location of a computer. You can either specify the computer's instance " +
"id (e.g. 123) or computer id (e.g #123)."
)
root.register( new SubCommandBase( "tp", UserLevel.OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -224,10 +204,10 @@ public final class CommandComputerCraft extends CommandDelegate
World world = computer.getWorld();
BlockPos pos = computer.getPosition();
if( world == null || pos == null ) throw new CommandException( "Cannot locate computer in world" );
if( world == null || pos == null ) throw new CommandException( "commands.computercraft.tp.not_there" );
ICommandSender sender = context.getSender();
if( !(sender instanceof Entity) ) throw new CommandException( "Sender is not an entity" );
if( !(sender instanceof Entity) ) throw new CommandException( "commands.computercraft.tp.not_entity" );
if( sender instanceof EntityPlayerMP )
{
@ -264,11 +244,7 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
root.register( new SubCommandBase(
"view", "<id>", "View the terminal of a computer.", UserLevel.OP,
"Open the terminal of a computer, allowing remote control of a computer. This does not provide access to " +
"turtle's inventories. You can either specify the computer's instance id (e.g. 123) or computer id (e.g #123)."
)
root.register( new SubCommandBase( "view", UserLevel.OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -278,7 +254,7 @@ public final class CommandComputerCraft extends CommandDelegate
ICommandSender sender = context.getSender();
if( !(sender instanceof EntityPlayerMP) )
{
throw new CommandException( "Cannot open terminal for non-player" );
throw new CommandException( "commands.computercraft.view.not_player" );
}
ServerComputer computer = ComputerSelector.getComputer( arguments.get( 0 ) );
@ -295,15 +271,7 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
CommandRoot track = new CommandRoot( "track", "Track execution times for computers.",
"Track how long computers execute for, as well as how many events they handle. This presents information in " +
"a similar way to /forge track and can be useful for diagnosing lag." );
root.register( track );
track.register( new SubCommandBase(
"start", "Start tracking all computers", UserLevel.OWNER_OP,
"Start tracking all computers' execution times and event counts. This will discard the results of previous runs."
)
root.register( new CommandRoot( "track" ).register( new SubCommandBase( "start", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments )
@ -312,31 +280,20 @@ public final class CommandComputerCraft extends CommandDelegate
String stopCommand = "/" + context.parent().getFullPath() + " stop";
context.getSender().sendMessage( list(
text( "Run " ),
link( text( stopCommand ), stopCommand, "Click to stop tracking" ),
text( " to stop tracking and view the results" )
translate( "commands.computercraft.track.start.stop",
link( text( stopCommand ), stopCommand, translate( "commands.computercraft.track.stop.action" ) ) )
) );
}
} );
track.register( new SubCommandBase(
"stop", "Stop tracking all computers", UserLevel.OWNER_OP,
"Stop tracking all computers' events and execution times"
)
} ).register( new SubCommandBase( "stop", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
{
TrackingContext timings = getTimingContext( context );
if( !timings.stop() ) throw new CommandException( "Tracking not enabled" );
if( !timings.stop() ) throw new CommandException( "commands.computercraft.track.stop.not_enabled" );
displayTimings( context, timings.getImmutableTimings(), TrackingField.AVERAGE_TIME );
}
} );
track.register( new SubCommandBase(
"dump", "[kind]", "Dump the latest track results", UserLevel.OWNER_OP,
"Dump the latest results of computer tracking."
)
} ).register( new SubCommandBase( "dump", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -345,7 +302,10 @@ public final class CommandComputerCraft extends CommandDelegate
if( arguments.size() >= 1 )
{
field = TrackingField.fields().get( arguments.get( 0 ) );
if( field == null ) throw new CommandException( "Unknown field '" + arguments.get( 0 ) + "'" );
if( field == null )
{
throw new CommandException( "commands.computercraft.track.dump.no_field", arguments.get( 0 ) );
}
}
displayTimings( context, getTimingContext( context ).getImmutableTimings(), field );
@ -373,27 +333,19 @@ public final class CommandComputerCraft extends CommandDelegate
return super.getCompletion( context, arguments );
}
}
} );
} ) );
root.register( new SubCommandBase(
"reload", "Reload the ComputerCraft config file", UserLevel.OWNER_OP,
"Reload the ComputerCraft config file"
)
root.register( new SubCommandBase( "reload", UserLevel.OWNER_OP )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments )
{
Config.reload();
context.getSender().sendMessage( new TextComponentString( "Reloaded config" ) );
context.getSender().sendMessage( translate( "commands.computercraft.reload.done" ) );
}
} );
root.register( new SubCommandBase(
"queue", "<id> [args...]", "Send a computer_command event to a command computer", UserLevel.ANYONE,
"Send a computer_command event to a command computer, passing through the additional arguments. " +
"This is mostly designed for map makers, acting as a more computer-friendly version of /trigger. Any " +
"player can run the command, which would most likely be done through a text component's click event."
)
root.register( new SubCommandBase( "queue", UserLevel.ANYONE )
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
@ -413,7 +365,7 @@ public final class CommandComputerCraft extends CommandDelegate
if( !found )
{
throw new CommandException( "Could not find any command computers matching " + selector );
throw new CommandException( "commands.computercraft.argument.no_matching", selector );
}
}
} );
@ -435,7 +387,7 @@ public final class CommandComputerCraft extends CommandDelegate
out.appendSibling( link(
text( Integer.toString( serverComputer.getInstanceID() ) ),
"/computercraft dump " + serverComputer.getInstanceID(),
"View more info about this computer"
translate( "commands.computercraft.dump.action" )
) );
}
@ -450,13 +402,13 @@ public final class CommandComputerCraft extends CommandDelegate
.appendSibling( link(
text( "\u261b" ),
"/computercraft tp " + serverComputer.getInstanceID(),
"Teleport to this computer"
translate( "commands.computercraft.tp.action" )
) )
.appendText( " " )
.appendSibling( link(
text( "\u20e2" ),
"/computercraft view " + serverComputer.getInstanceID(),
"View this computer"
translate( "commands.computercraft.view.action" )
) );
}
@ -470,7 +422,7 @@ public final class CommandComputerCraft extends CommandDelegate
return link(
position( computer.getPosition() ),
"/computercraft tp " + computer.getInstanceID(),
"Teleport to this computer"
translate( "commands.computercraft.tp.action" )
);
}
else
@ -494,7 +446,7 @@ public final class CommandComputerCraft extends CommandDelegate
private static void displayTimings( CommandContext context, List<ComputerTracker> timings, TrackingField field ) throws CommandException
{
if( timings.isEmpty() ) throw new CommandException( "No timings available" );
if( timings.isEmpty() ) throw new CommandException( "commands.computercraft.track.dump.no_timings" );
Map<Computer, ServerComputer> lookup = new HashMap<>();
int maxId = 0, maxInstance = 0;
@ -512,9 +464,18 @@ public final class CommandComputerCraft extends CommandDelegate
|| field == TrackingField.AVERAGE_TIME || field == TrackingField.MAX_TIME;
TableBuilder table = defaultLayout
? new TableBuilder( TRACK_ID, "Computer", "Tasks", "Total", "Average", "Maximum" )
: new TableBuilder( TRACK_ID, "Computer", field.displayName() );
TableBuilder table = defaultLayout ? new TableBuilder(
TRACK_ID,
translate( "commands.computercraft.track.dump.computer" ),
translate( TrackingField.TASKS.translationKey() ),
translate( TrackingField.TOTAL_TIME.translationKey() ),
translate( TrackingField.AVERAGE_TIME.translationKey() ),
translate( TrackingField.MAX_TIME.translationKey() )
) : new TableBuilder(
TRACK_ID,
translate( "commands.computercraft.track.dump.computer" ),
translate( field.translationKey() )
);
for( ComputerTracker entry : timings )
{
@ -564,7 +525,7 @@ public final class CommandComputerCraft extends CommandDelegate
if( !failed.isEmpty() )
{
throw new CommandException( "Could not find computers matching " + String.join( ", ", failed ) );
throw new CommandException( "commands.computercraft.argument.no_matching", String.join( ", ", failed ) );
}
}
}

View File

@ -73,7 +73,7 @@ public class CommandCopy extends CommandBase implements IClientCommand
TextComponentString name = new TextComponentString( text );
name.getStyle()
.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/" + NAME + " " + text ) )
.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TextComponentTranslation( "gui.computercraft:tooltip.copy" ) ) );
.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TextComponentTranslation( "gui.computercraft.tooltip.copy" ) ) );
return name;
}
}

View File

@ -16,9 +16,9 @@ import net.minecraft.command.CommandException;
import java.util.*;
import java.util.function.Predicate;
public final class ComputerSelector
final class ComputerSelector
{
private static List<ServerComputer> getComputers( Predicate<ServerComputer> predicate ) throws CommandException
private static List<ServerComputer> getComputers( Predicate<ServerComputer> predicate )
{
// We copy it to prevent concurrent modifications.
ArrayList<ServerComputer> computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() );
@ -26,12 +26,12 @@ public final class ComputerSelector
return computers;
}
public static ServerComputer getComputer( String selector ) throws CommandException
static ServerComputer getComputer( String selector ) throws CommandException
{
List<ServerComputer> computers = getComputers( selector );
if( computers.size() == 0 )
{
throw new CommandException( "No computer matching " + selector );
throw new CommandException( "commands.computercraft.argument.no_matching", selector );
}
else if( computers.size() == 1 )
{
@ -39,21 +39,19 @@ public final class ComputerSelector
}
else
{
StringBuilder builder = new StringBuilder( "Multiple computers matching " )
.append( selector ).append( " (instances " );
StringBuilder builder = new StringBuilder();
for( int i = 0; i < computers.size(); i++ )
{
if( i > 0 ) builder.append( ", " );
builder.append( computers.get( i ).getInstanceID() );
}
builder.append( ")" );
throw new CommandException( builder.toString() );
throw new CommandException( "commands.computercraft.argument.many_matching", selector, builder.toString() );
}
}
public static List<ServerComputer> getComputers( String selector ) throws CommandException
static List<ServerComputer> getComputers( String selector ) throws CommandException
{
if( selector.length() > 0 && selector.charAt( 0 ) == '#' )
{
@ -66,7 +64,7 @@ public final class ComputerSelector
}
catch( NumberFormatException e )
{
throw new CommandException( "'" + selector + "' is not a valid number" );
throw new CommandException( "commands.computercraft.argument.not_number", selector );
}
return getComputers( x -> x.getID() == id );
@ -90,7 +88,7 @@ public final class ComputerSelector
}
catch( NumberFormatException e )
{
throw new CommandException( "'" + selector + "' is not a valid number" );
throw new CommandException( "commands.computercraft.argument.not_number", selector );
}
ServerComputer computer = ComputerCraft.serverComputerRegistry.get( instance );
@ -98,7 +96,7 @@ public final class ComputerSelector
}
}
public static List<String> completeComputer( String selector )
static List<String> completeComputer( String selector )
{
TreeSet<String> options = Sets.newTreeSet();

View File

@ -7,6 +7,7 @@
package dan200.computercraft.shared.command.framework;
import com.google.common.collect.Lists;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
@ -76,7 +77,7 @@ public final class CommandContext
public String getFullUsage()
{
return "/" + getFullPath() + " " + path.get( path.size() - 1 ).getUsage( this );
return "/" + getFullPath() + " " + StringUtil.translate( path.get( path.size() - 1 ).getUsage( this ) );
}
public List<ISubCommand> getPath()

View File

@ -66,7 +66,7 @@ public class CommandDelegate implements ICommand
catch( Throwable e )
{
ComputerCraft.log.error( "Unhandled exception in command", e );
throw new CommandException( "Unhandled exception: " + e.toString() );
throw new CommandException( "commands.computercraft.generic.exception", e.toString() );
}
}

View File

@ -23,22 +23,28 @@ import java.util.Map;
public class CommandRoot implements ISubCommand
{
private final String name;
private final String synopsis;
private final String description;
private ISubCommand parent;
private final Map<String, ISubCommand> subCommands = Maps.newHashMap();
public CommandRoot( String name, String synopsis, String description )
public CommandRoot( String name )
{
this.name = name;
this.synopsis = synopsis;
this.description = description;
register( new SubCommandHelp( this ) );
}
public void register( ISubCommand command )
public CommandRoot register( ISubCommand command )
{
subCommands.put( command.getName(), command );
if( command instanceof SubCommandBase )
{
((SubCommandBase) command).setParent( this );
}
else if( command instanceof CommandRoot )
{
((CommandRoot) command).setParent( this );
}
return this;
}
@Nonnull
@ -48,6 +54,13 @@ public class CommandRoot implements ISubCommand
return name;
}
@Nonnull
@Override
public String getFullName()
{
return parent == null ? name : parent.getFullName() + "." + name;
}
@Nonnull
@Override
public String getUsage( CommandContext context )
@ -74,20 +87,6 @@ public class CommandRoot implements ISubCommand
return out.append( ">" ).toString();
}
@Nonnull
@Override
public String getSynopsis()
{
return synopsis;
}
@Nonnull
@Override
public String getDescription()
{
return description;
}
@Override
public boolean checkPermission( @Nonnull CommandContext context )
{
@ -153,4 +152,10 @@ public class CommandRoot implements ISubCommand
return command.getCompletion( context, arguments.subList( 1, arguments.size() ) );
}
}
void setParent( @Nonnull ISubCommand parent )
{
if( this.parent != null ) throw new IllegalStateException( "Cannot have multiple parents" );
this.parent = parent;
}
}

View File

@ -13,6 +13,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
/**
@ -29,6 +30,15 @@ public interface ISubCommand
@Nonnull
String getName();
/**
* Get the full name of this command. This is equal to the command parent's full name, plus this command's name.
*
* @return The full name of this command
* @see ISubCommand#getName()
*/
@Nonnull
String getFullName();
/**
* Get the usage of this command
*
@ -37,23 +47,10 @@ public interface ISubCommand
* @see ICommand#getUsage(ICommandSender)
*/
@Nonnull
String getUsage( CommandContext context );
/**
* Get a short description of this command, including its usage.
*
* @return The command's synopsis
*/
@Nonnull
String getSynopsis();
/**
* Get the lengthy description of this command. This synopsis is prepended to this.
*
* @return The command's description
*/
@Nonnull
String getDescription();
default String getUsage( CommandContext context )
{
return "commands." + getFullName() + ".usage";
}
/**
* Determine whether a given command sender has permission to execute this command.
@ -82,5 +79,8 @@ public interface ISubCommand
* @see ICommand#getTabCompletions(MinecraftServer, ICommandSender, String[], BlockPos)
*/
@Nonnull
List<String> getCompletion( @Nonnull CommandContext context, @Nonnull List<String> arguments );
default List<String> getCompletion( @Nonnull CommandContext context, @Nonnull List<String> arguments )
{
return Collections.emptyList();
}
}

View File

@ -9,31 +9,21 @@ package dan200.computercraft.shared.command.framework;
import dan200.computercraft.shared.command.UserLevel;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
public abstract class SubCommandBase implements ISubCommand
{
private final String name;
private final String usage;
private final String synopsis;
private final String description;
private final String id;
private final UserLevel level;
private ISubCommand parent;
public SubCommandBase( String name, String usage, String synopsis, UserLevel level, String description )
protected SubCommandBase( String name, UserLevel level )
{
this.name = name;
this.usage = usage;
this.synopsis = synopsis;
this.description = description;
this.id = name.replace( '-', '_' );
this.level = level;
}
public SubCommandBase( String name, String synopsis, UserLevel level, String description )
{
this( name, "", synopsis, level, description );
}
@Nonnull
@Override
public String getName()
@ -43,23 +33,9 @@ public abstract class SubCommandBase implements ISubCommand
@Nonnull
@Override
public String getUsage( CommandContext context )
public String getFullName()
{
return usage;
}
@Nonnull
@Override
public String getSynopsis()
{
return synopsis;
}
@Nonnull
@Override
public String getDescription()
{
return description;
return parent == null ? id : parent.getFullName() + "." + id;
}
@Override
@ -68,10 +44,9 @@ public abstract class SubCommandBase implements ISubCommand
return level.canExecute( context );
}
@Nonnull
@Override
public List<String> getCompletion( @Nonnull CommandContext context, @Nonnull List<String> arguments )
void setParent( ISubCommand parent )
{
return Collections.emptyList();
if( this.parent != null ) throw new IllegalStateException( "Cannot have multiple parents" );
this.parent = parent;
}
}

View File

@ -16,11 +16,11 @@ import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
public class SubCommandHelp implements ISubCommand
class SubCommandHelp implements ISubCommand
{
private final CommandRoot branchCommand;
public SubCommandHelp( CommandRoot branchCommand )
SubCommandHelp( CommandRoot branchCommand )
{
this.branchCommand = branchCommand;
}
@ -34,23 +34,9 @@ public class SubCommandHelp implements ISubCommand
@Nonnull
@Override
public String getUsage( CommandContext context )
public String getFullName()
{
return "[command]";
}
@Nonnull
@Override
public String getSynopsis()
{
return "Provide help for a specific command";
}
@Nonnull
@Override
public String getDescription()
{
return "";
return "computercraft.help";
}
@Override
@ -73,12 +59,12 @@ public class SubCommandHelp implements ISubCommand
}
else
{
throw new CommandException( Strings.join( arguments.subList( 0, i ), " " ) + " has no sub-commands" );
throw new CommandException( "commands.computercraft.help.no_children", Strings.join( arguments.subList( 0, i ), " " ) );
}
if( command == null )
{
throw new CommandException( "No such command " + Strings.join( arguments.subList( 0, i + 1 ), " " ) );
throw new CommandException( "commands.computercraft.help.no_command", Strings.join( arguments.subList( 0, i + 1 ), " " ) );
}
}

View File

@ -6,15 +6,11 @@
package dan200.computercraft.shared.command.text;
import com.google.common.base.Strings;
import dan200.computercraft.shared.command.framework.CommandContext;
import dan200.computercraft.shared.command.framework.CommandRoot;
import dan200.computercraft.shared.command.framework.ISubCommand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.*;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
@ -34,11 +30,27 @@ public final class ChatHelpers
return component;
}
public static <T extends ITextComponent> T coloured( T component, TextFormatting colour )
{
component.getStyle().setColor( colour );
return component;
}
public static ITextComponent text( String text )
{
return new TextComponentString( text == null ? "" : text );
}
public static ITextComponent translate( String text )
{
return new TextComponentTranslation( text == null ? "" : text );
}
public static ITextComponent translate( String text, Object... args )
{
return new TextComponentTranslation( text == null ? "" : text, args );
}
public static ITextComponent list( ITextComponent... children )
{
ITextComponent component = new TextComponentString( "" );
@ -51,13 +63,16 @@ public final class ChatHelpers
public static ITextComponent getHelp( CommandContext context, ISubCommand command, String prefix )
{
ITextComponent output = new TextComponentString( "" )
.appendSibling( coloured( "/" + prefix + " " + command.getUsage( context ), HEADER ) )
.appendText( " " )
.appendSibling( coloured( command.getSynopsis(), SYNOPSIS ) );
String desc = command.getDescription();
if( !Strings.isNullOrEmpty( desc ) ) output.appendText( "\n" + desc );
ITextComponent output = new TextComponentString( "" )
.appendSibling(
coloured( "/" + prefix, HEADER )
.appendSibling( translate( command.getUsage( context ) ) )
)
.appendText( " " )
.appendSibling( coloured( translate( "commands." + command.getFullName() + ".synopsis" ), SYNOPSIS ) )
.appendText( "\n" )
.appendSibling( translate( "commands." + command.getFullName() + ".desc" ) );
if( command instanceof CommandRoot )
{
@ -74,7 +89,7 @@ public final class ChatHelpers
) );
output.appendSibling( component );
output.appendText( " - " + subCommand.getSynopsis() );
output.appendText( " - " ).appendSibling( translate( "commands." + subCommand.getFullName() + ".synopsis" ) );
}
}
@ -83,38 +98,24 @@ public final class ChatHelpers
public static ITextComponent position( BlockPos pos )
{
if( pos == null ) return text( "<no pos>" );
return formatted( "%d, %d, %d", pos.getX(), pos.getY(), pos.getZ() );
if( pos == null ) return translate( "commands.computercraft.generic.no_position" );
return translate( "commands.computercraft.generic.position", pos.getX(), pos.getY(), pos.getZ() );
}
public static ITextComponent bool( boolean value )
{
if( value )
{
ITextComponent component = new TextComponentString( "Y" );
component.getStyle().setColor( TextFormatting.GREEN );
return component;
}
else
{
ITextComponent component = new TextComponentString( "N" );
component.getStyle().setColor( TextFormatting.RED );
return component;
}
return value
? coloured( translate( "commands.computercraft.generic.yes" ), TextFormatting.GREEN )
: coloured( translate( "commands.computercraft.generic.no" ), TextFormatting.RED );
}
public static ITextComponent formatted( String format, Object... args )
{
return new TextComponentString( String.format( format, args ) );
}
public static ITextComponent link( ITextComponent component, String command, String toolTip )
public static ITextComponent link( ITextComponent component, String command, ITextComponent toolTip )
{
Style style = component.getStyle();
if( style.getColor() == null ) style.setColor( TextFormatting.YELLOW );
style.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, command ) );
style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TextComponentString( toolTip ) ) );
style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) );
return component;
}

View File

@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils;
import javax.annotation.Nullable;
import static dan200.computercraft.shared.command.text.ChatHelpers.coloured;
import static dan200.computercraft.shared.command.text.ChatHelpers.translate;
public interface TableFormatter
{
@ -111,7 +112,7 @@ public interface TableFormatter
if( table.getAdditional() > 0 )
{
writeLine( rowId++, coloured( table.getAdditional() + " additional rows...", TextFormatting.AQUA ) );
writeLine( rowId++, coloured( translate( "commands.computercraft.generic.additional_rows", table.getAdditional() ), TextFormatting.AQUA ) );
}
return rowId - table.getId();

View File

@ -6,7 +6,6 @@
package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.apis.CommandAPI;
import dan200.computercraft.shared.computer.core.ServerComputer;
import io.netty.buffer.ByteBuf;

View File

@ -11,6 +11,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemBlock;
@ -42,10 +43,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
if( flag.isAdvanced() )
{
int id = getComputerID( stack );
if( id >= 0 )
{
list.add( "(Computer ID: " + id + ")" );
}
if( id >= 0 ) list.add( StringUtil.translateFormatted( "gui.computercraft.tooltip.computer_id", id ) );
}
}

View File

@ -12,6 +12,7 @@ import dan200.computercraft.api.filesystem.IMount;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.StringUtil;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@ -84,10 +85,7 @@ public class ItemDiskLegacy extends Item
if( flag.isAdvanced() )
{
int id = getDiskID( stack );
if( id >= 0 )
{
list.add( "(Disk ID: " + id + ")" );
}
if( id >= 0 ) list.add( StringUtil.translateFormatted( "gui.computercraft.tooltip.disk_id", id ) );
}
}

View File

@ -242,14 +242,14 @@ public class TileCable extends TileGeneric implements IPeripheralTile
if( oldPeriphName != null )
{
player.sendMessage(
new TextComponentTranslation( "gui.computercraft:wired_modem.peripheral_disconnected",
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_disconnected",
CommandCopy.createCopyText( oldPeriphName ) )
);
}
if( periphName != null )
{
player.sendMessage(
new TextComponentTranslation( "gui.computercraft:wired_modem.peripheral_connected",
new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected",
CommandCopy.createCopyText( periphName ) )
);
}

View File

@ -166,8 +166,8 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
if( !Objects.equal( periphNames, oldPeriphNames ) )
{
sendPeripheralChanges( player, "gui.computercraft:wired_modem.peripheral_disconnected", oldPeriphNames );
sendPeripheralChanges( player, "gui.computercraft:wired_modem.peripheral_connected", periphNames );
sendPeripheralChanges( player, "chat.computercraft.wired_modem.peripheral_disconnected", oldPeriphNames );
sendPeripheralChanges( player, "chat.computercraft.wired_modem.peripheral_connected", periphNames );
}
return true;

View File

@ -219,14 +219,14 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
IPocketUpgrade upgrade = getUpgrade( stack );
if( upgrade != null )
{
return StringUtil.translateToLocalFormatted(
return StringUtil.translateFormatted(
baseString + ".upgraded.name",
StringUtil.translateToLocal( upgrade.getUnlocalisedAdjective() )
StringUtil.translate( upgrade.getUnlocalisedAdjective() )
);
}
else
{
return StringUtil.translateToLocal( baseString + ".name" );
return StringUtil.translate( baseString + ".name" );
}
}
@ -236,10 +236,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
if( flag.isAdvanced() )
{
int id = getComputerID( stack );
if( id >= 0 )
{
list.add( "(Computer ID: " + id + ")" );
}
if( id >= 0 ) list.add( StringUtil.translateFormatted( "gui.computercraft.tooltip.computer_id", id ) );
}
}

View File

@ -147,29 +147,29 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right );
if( left != null && right != null )
{
return StringUtil.translateToLocalFormatted(
return StringUtil.translateFormatted(
baseString + ".upgraded_twice.name",
StringUtil.translateToLocal( right.getUnlocalisedAdjective() ),
StringUtil.translateToLocal( left.getUnlocalisedAdjective() )
StringUtil.translate( right.getUnlocalisedAdjective() ),
StringUtil.translate( left.getUnlocalisedAdjective() )
);
}
else if( left != null )
{
return StringUtil.translateToLocalFormatted(
return StringUtil.translateFormatted(
baseString + ".upgraded.name",
StringUtil.translateToLocal( left.getUnlocalisedAdjective() )
StringUtil.translate( left.getUnlocalisedAdjective() )
);
}
else if( right != null )
{
return StringUtil.translateToLocalFormatted(
return StringUtil.translateFormatted(
baseString + ".upgraded.name",
StringUtil.translateToLocal( right.getUnlocalisedAdjective() )
StringUtil.translate( right.getUnlocalisedAdjective() )
);
}
else
{
return StringUtil.translateToLocal( baseString + ".name" );
return StringUtil.translate( baseString + ".name" );
}
}

View File

@ -35,6 +35,6 @@ public class RecordUtil
if( !(item instanceof ItemRecord) ) return null;
ItemRecord record = (ItemRecord) item;
return StringUtil.translateToLocal( record.displayName );
return StringUtil.translate( record.displayName );
}
}

View File

@ -34,7 +34,7 @@ public class StringUtil
* Translates a Stat name
*/
@SuppressWarnings( "deprecation" )
public static String translateToLocal( String key )
public static String translate( String key )
{
return net.minecraft.util.text.translation.I18n.translateToLocal( key );
}
@ -43,7 +43,7 @@ public class StringUtil
* Translates a Stat name with format args
*/
@SuppressWarnings( "deprecation" )
public static String translateToLocalFormatted( String key, Object... format )
public static String translateFormatted( String key, Object... format )
{
return net.minecraft.util.text.translation.I18n.translateToLocalFormatted( key, format );
}

View File

@ -39,8 +39,8 @@ upgrade.minecraft:crafting_table.adjective=Fabrizierung
upgrade.computercraft:advanced_modem.adjective=Ender
upgrade.computercraft:speaker.adjective=Laut
gui.computercraft:wired_modem.peripheral_connected=Peripheriegerät "%s" mit dem Netzwerk verbunden
gui.computercraft:wired_modem.peripheral_disconnected=Peripheriegerät "%s" vom Netzwerk getrennt
chat.computercraft.wired_modem.peripheral_connected=Peripheriegerät "%s" mit dem Netzwerk verbunden
chat.computercraft.wired_modem.peripheral_disconnected=Peripheriegerät "%s" vom Netzwerk getrennt
gui.computercraft:config.http_enable=HTTP-API aktivieren
gui.computercraft:config.http_websocket_enable=HTTP-Websockets aktivieren

View File

@ -39,11 +39,117 @@ upgrade.minecraft:crafting_table.adjective=Crafty
upgrade.computercraft:advanced_modem.adjective=Ender
upgrade.computercraft:speaker.adjective=Noisy
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
chat.computercraft.wired_modem.peripheral_connected=Peripheral "%s" connected to network
chat.computercraft.wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
gui.computercraft:tooltip.copy=Copy to clipboard
# Command descriptions, usage and any additional messages.
commands.computercraft.synopsis=Various commands for controlling computers.
commands.computercraft.desc=The /computercraft command provides various debugging and administrator tools for controlling and interacting with computers.
commands.computercraft.help.synopsis=Provide help for a specific command
commands.computercraft.help.desc=
commands.computercraft.help.usage=[command]
commands.computercraft.help.no_children=%s has no sub-commands
commands.computercraft.help.no_command=No such command '%s'
commands.computercraft.dump.synopsis=Display the status of computers.
commands.computercraft.dump.desc=Display the status of all computers or specific information about one computer. You can specify the computer's instance id (e.g. 123), computer id (e.g #123) or label (e.g. "@My Computer").
commands.computercraft.dump.usage=[id]
commands.computercraft.dump.action=View more info about this computer
commands.computercraft.shutdown.synopsis=Shutdown computers remotely.
commands.computercraft.shutdown.desc=Shutdown the listed computers or all if none are specified. You can specify the computer's instance id (e.g. 123), computer id (e.g #123) or label (e.g. "@My Computer").
commands.computercraft.shutdown.usage=[ids...]
commands.computercraft.turn_on.done=Shutdown %s/%s computers
commands.computercraft.turn_on.synopsis=Turn computers on remotely.
commands.computercraft.turn_on.desc=Turn on the listed computers. You can specify the computer's instance id (e.g. 123), computer id (e.g #123) or label (e.g. "@My Computer").
commands.computercraft.turn_on.usage=[ids...]
commands.computercraft.turn_on.done=Turned on %s/%s computers
commands.computercraft.tp.synopsis=Teleport to a specific computer.
commands.computercraft.tp.desc=Teleport to the location of a computer. You can either specify the computer's instance id (e.g. 123) or computer id (e.g #123).
commands.computercraft.tp.usage=<id>
commands.computercraft.tp.action=Teleport to this computer
commands.computercraft.tp.not_entity=Cannot open terminal for non-player
commands.computercraft.tp.not_there=Cannot locate computer in the world
commands.computercraft.view.synopsis=View the terminal of a computer.
commands.computercraft.view.desc=Open the terminal of a computer, allowing remote control of a computer. This does not provide access to turtle's inventories. You can either specify the computer's instance id (e.g. 123) or computer id (e.g #123).
commands.computercraft.view.usage=<id>
commands.computercraft.view.action=View this computer
commands.computercraft.view.not_player=Cannot open terminal for non-player
commands.computercraft.track.synopsis=Track execution times for computers.
commands.computercraft.track.desc=Track how long computers execute for, as well as how many events they handle. This presents information in a similar way to /forge track and can be useful for diagnosing lag.
commands.computercraft.track.start.synopsis=Start tracking all computers
commands.computercraft.track.start.desc=Start tracking all computers' execution times and event counts. This will discard the results of previous runs.
commands.computercraft.track.start.usage=
commands.computercraft.track.start.stop=Run %s to stop tracking and view the results
commands.computercraft.track.stop.synopsis=Stop tracking all computers
commands.computercraft.track.stop.desc=Stop tracking all computers' events and execution times
commands.computercraft.track.stop.usage=
commands.computercraft.track.stop.action=Click to stop tracking
commands.computercraft.track.stop.not_enabled=Not currently tracking computers
commands.computercraft.track.dump.synopsis=Dump the latest track results
commands.computercraft.track.dump.desc=Dump the latest results of computer tracking.
commands.computercraft.track.dump.usage=[kind]
commands.computercraft.track.dump.no_timings=No timings available
commands.computercraft.track.dump.no_field=Unknown field '%s'
commands.computercraft.track.dump.computer=Computer
commands.computercraft.reload.synopsis=Reload the ComputerCraft config file
commands.computercraft.reload.desc=Reload the ComputerCraft config file
commands.computercraft.reload.usage=
commands.computercraft.reload.done=Reloaded config
commands.computercraft.queue.synopsis=Send a computer_command event to a command computer
commands.computercraft.queue.desc=Send a computer_command event to a command computer, passing through the additional arguments. This is mostly designed for map makers, acting as a more computer-friendly version of /trigger. Any player can run the command, which would most likely be done through a text component's click event.
commands.computercraft.queue.usage=<id> [args...]
commands.computercraft.generic.no_position=<no pos>
commands.computercraft.generic.position=%s, %s, %s
commands.computercraft.generic.yes=Y
commands.computercraft.generic.no=N
commands.computercraft.generic.exception=Unhandled exception (%s)
commands.computercraft.generic.additional_rows=%d additional rows…
commands.computercraft.argument.no_matching=No computers matching '%s'
commands.computercraft.argument.many_matching=Multiple computers matching '%s' (instances %s)
commands.computercraft.argument.not_number='%s' is not a number
# Names for the various tracking fields.
tracking_field.computercraft.tasks.name=Tasks
tracking_field.computercraft.total.name=Total time
tracking_field.computercraft.average.name=Average time
tracking_field.computercraft.max.name=Max time
tracking_field.computercraft.server_count.name=Server task count
tracking_field.computercraft.server_time.name=Server task time
tracking_field.computercraft.peripheral.name=Peripheral calls
tracking_field.computercraft.fs.name=Filesystem operations
tracking_field.computercraft.turtle.name=Turtle operations
tracking_field.computercraft.http.name=HTTP requests
tracking_field.computercraft.http_upload.name=HTTP upload
tracking_field.computercraft.http_download.name=HTTT download
tracking_field.computercraft.websocket_incoming.name=Websocket incoming
tracking_field.computercraft.websocket_outgoing.name=Websocket outgoing
tracking_field.computercraft.coroutines_created.name=Coroutines created
tracking_field.computercraft.coroutines_dead.name=Coroutines disposed
# Misc tooltips
gui.computercraft.tooltip.copy=Copy to clipboard
gui.computercraft.tooltip.computer_id=(Computer ID: %s)
gui.computercraft.tooltip.disk_id=(Disk ID: %s)
# Config options
gui.computercraft:config.computer_space_limit=Computer space limit (bytes)
gui.computercraft:config.floppy_space_limit=Floppy Disk space limit (bytes)
gui.computercraft:config.maximum_open_files=Maximum files open per computer

View File

@ -39,10 +39,10 @@ upgrade.minecraft:crafting_table.adjective=Artigiano
upgrade.computercraft:advanced_modem.adjective=Ender
upgrade.computercraft:speaker.adjective=Rumoroso
gui.computercraft:wired_modem.peripheral_connected=Periferica "%s" connessa alla rete
gui.computercraft:wired_modem.peripheral_disconnected=Periferica "%s" disconessa dalla rete
gui.computercraft.wired_modem.peripheral_connected=Periferica "%s" connessa alla rete
gui.computercraft.wired_modem.peripheral_disconnected=Periferica "%s" disconessa dalla rete
gui.computercraft:tooltip.copy=Copia negli appunti
gui.computercraft.tooltip.copy=Copia negli appunti
gui.computercraft:config.computer_space_limit=Limite spazio Computer (bytes)
gui.computercraft:config.floppy_space_limit=Limite spazio Disco Floppy (bytes)

View File

@ -39,10 +39,10 @@ upgrade.minecraft:crafting_table.adjective=Artesã
upgrade.computercraft:advanced_modem.adjective=Ender
upgrade.computercraft:speaker.adjective=(Alto-Falante)
gui.computercraft:wired_modem.peripheral_connected=Periférico "%s" conectado à rede
gui.computercraft:wired_modem.peripheral_disconnected=Periférico "%s" desconectado da rede
chat.computercraft.wired_modem.peripheral_connected=Periférico "%s" conectado à rede
chat.computercraft.wired_modem.peripheral_disconnected=Periférico "%s" desconectado da rede
gui.computercraft:tooltip.copy=Copiar para a área de transferência
gui.computercraft.tooltip.copy=Copiar para a área de transferência
gui.computercraft:config.computer_space_limit=Limite de espaço dos Computadores (bytes)
gui.computercraft:config.floppy_space_limit=Limite de espaço dos Disquetes (bytes)

View File

@ -39,10 +39,10 @@ upgrade.minecraft:crafting_table.adjective=Händig
upgrade.computercraft:advanced_modem.adjective=Ender
upgrade.computercraft:speaker.adjective=Högljudd
gui.computercraft:wired_modem.peripheral_connected=Kringutrustning "%s" är kopplad till nätverket
gui.computercraft:wired_modem.peripheral_disconnected=Kringutrustning "%s" är frånkopplad från nätverket
chat.computercraft.wired_modem.peripheral_connected=Kringutrustning "%s" är kopplad till nätverket
chat.computercraft.wired_modem.peripheral_disconnected=Kringutrustning "%s" är frånkopplad från nätverket
gui.computercraft:tooltip.copy=Kopiera till urklipp
gui.computercraft.tooltip.copy=Kopiera till urklipp
gui.computercraft:config.computer_space_limit=Dator maximalt utrymme (bytes)
gui.computercraft:config.floppy_space_limit=Diskett maximalt utrymme (bytes)