Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/Localization/LocalizationTargetEditor/Commands/LocalizationTargetCommand.cs

111 lines
4.0 KiB
C#
Raw Normal View History

Localization: Introduced the experimental LocalizationTargetEditor UAT command. This command allows users to create, update, delete and query localization targets in the Engine or project. The LocalizationTargetEditor UAT command is set up to have a series of sub-commands which can be executed with different parameters. This allows the LocalizationTargetEditor to be extensible to users for specialized localization target operations. - Introduced the LocalizationTargetCommand abstract base class. This class is what all othe LocalizationTargetEditor sub-commands should be drived from. A scan of all sub-classes of LocalizationTargetCommand will be scanned for to determine all available localization target commands. - Introduced the PluginLocalizationTargetCommand abstract base class. All commands to be operated on plugins should derive from this class. - Introduced the NewPluginLocalizationTarget sub-command which will create localization config files for plugins and make the necessary updates to .uplugin files. All plugins under a provided directory can be operated on at a time to batch create the necessary localization config files. - The NewPluginLocalizationTarget sub-command has perforce integration and can automatically add/check out all files that have been created/edited. - Introduced a number of classes to encapsulate all the data in the various localization config files. This allows for generation of localization config files from code. - Introduced the LocalizationConfigFileBuilder and LocalizationConfigFileGenerator base classes. These classes and their sub-classes are used to generate localization config files in the correct format provided the config file data. Current support is only for modular localization config files. However, the LocalizationConfigFileBuilder can also be used to generate Monolithic localization config files if necessary.also #rb: Jamie.Dale #jira: UE-194872, UE-194873, UE-194874, #test Used the NewPluginLocalizationTarget sub-command to generate a number of plugins. The generated localization config files yield correct localization gather results and the plugin .locres file was successfully loaded at runtime to display the correct localized text. [CL 28424727 by leon huang in ue5-main branch]
2023-10-03 14:44:56 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
using AutomationTool;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
Localization: Introduced the experimental LocalizationTargetEditor UAT command. This command allows users to create, update, delete and query localization targets in the Engine or project. The LocalizationTargetEditor UAT command is set up to have a series of sub-commands which can be executed with different parameters. This allows the LocalizationTargetEditor to be extensible to users for specialized localization target operations. - Introduced the LocalizationTargetCommand abstract base class. This class is what all othe LocalizationTargetEditor sub-commands should be drived from. A scan of all sub-classes of LocalizationTargetCommand will be scanned for to determine all available localization target commands. - Introduced the PluginLocalizationTargetCommand abstract base class. All commands to be operated on plugins should derive from this class. - Introduced the NewPluginLocalizationTarget sub-command which will create localization config files for plugins and make the necessary updates to .uplugin files. All plugins under a provided directory can be operated on at a time to batch create the necessary localization config files. - The NewPluginLocalizationTarget sub-command has perforce integration and can automatically add/check out all files that have been created/edited. - Introduced a number of classes to encapsulate all the data in the various localization config files. This allows for generation of localization config files from code. - Introduced the LocalizationConfigFileBuilder and LocalizationConfigFileGenerator base classes. These classes and their sub-classes are used to generate localization config files in the correct format provided the config file data. Current support is only for modular localization config files. However, the LocalizationConfigFileBuilder can also be used to generate Monolithic localization config files if necessary.also #rb: Jamie.Dale #jira: UE-194872, UE-194873, UE-194874, #test Used the NewPluginLocalizationTarget sub-command to generate a number of plugins. The generated localization config files yield correct localization gather results and the plugin .locres file was successfully loaded at runtime to display the correct localized text. [CL 28424727 by leon huang in ue5-main branch]
2023-10-03 14:44:56 -04:00
using static AutomationTool.CommandUtils;
namespace EpicGames.Localization
{
public abstract class LocalizationTargetCommand
{
protected static BuildCommand _commandLineHelper;
private static Dictionary<string, LocalizationTargetCommand> _nameToLocalizationTargetCommandMap = new Dictionary<string, LocalizationTargetCommand>();
public string Name { get; protected set; } = "";
public string DisplayName { get; protected set; } = "";
public bool bIsExecutingInPreview { get; private set; } = false;
static LocalizationTargetCommand()
{
// look for all subclasses, and cache by their ProviderToken
foreach (Assembly assembly in ScriptManager.AllScriptAssemblies)
{
Type[] allTypesInAssembly = assembly.GetTypes();
foreach (Type typeInAssembly in allTypesInAssembly)
{
// we also guard against abstract classes as we can have abstract classes as children of LocalizationTargetEditorCommand e.g PluginLocalizationTargetCommand
if (typeof(LocalizationTargetCommand).IsAssignableFrom(typeInAssembly) && typeInAssembly != typeof(LocalizationTargetCommand) && !typeInAssembly.IsAbstract)
{
LocalizationTargetCommand provider = (LocalizationTargetCommand)Activator.CreateInstance(typeInAssembly);
_nameToLocalizationTargetCommandMap[provider.Name] = provider;
}
}
}
}
public static void Initialize(BuildCommand commandLineHelper)
{
_commandLineHelper = commandLineHelper;
}
public static LocalizationTargetCommand GetLocalizationTargetCommandFromName(string commandName)
{
LocalizationTargetCommand command = null;
_nameToLocalizationTargetCommandMap.TryGetValue(commandName, out command);
return command;
}
protected virtual bool ParseCommandLine()
{
bIsExecutingInPreview = _commandLineHelper.ParseParam("Preview");
return true;
}
public abstract bool Execute();
public void PrintHelpText()
{
Logger.LogInformation("Help:");
Logger.LogInformation($"{GetHelpText()}");
}
public virtual string GetHelpText()
{
StringBuilder helpTextStringBuilder = new StringBuilder();
BuildHelpDescription(helpTextStringBuilder);
BuildHelpArguments(helpTextStringBuilder);
BuildHelpUsage(helpTextStringBuilder);
return helpTextStringBuilder.ToString();
}
/// <summary>
/// Buils the description portion of the help text. Concrete child classes of LocalizationTargetCommand should override this function
/// </summary> and call the base implementation to build any descriptions from parent classes.
/// <param name="builder"></param>
protected virtual void BuildHelpDescription(StringBuilder builder)
{
builder.AppendLine("Description:");
}
/// <summary>
/// Builds the arguments portion of the help text explaining what each parameter of the command does. Child classes should override this function
/// </summary> to call the base implementation as well as provide descriptions for the child arguments.
/// <param name="builder"></param>
protected virtual void BuildHelpArguments(StringBuilder builder)
{
builder.AppendLine("Arguments:");
builder.AppendLine("Preview - An optional flag that will execute this command in preview mode. No files will be created or edited. No folders will be created. No files will be added or checked out of perforce.");
}
/// <summary>
/// Builds the usage portion of the help text. Useres should override this function and call teh base implementation
/// and provide usage scenarios and the associated usage syntax for each scenario.
/// </summary>
/// <param name="builder"></param>
protected virtual void BuildHelpUsage(StringBuilder builder)
{
builder.AppendLine("Usage:");
Localization: Introduced the experimental LocalizationTargetEditor UAT command. This command allows users to create, update, delete and query localization targets in the Engine or project. The LocalizationTargetEditor UAT command is set up to have a series of sub-commands which can be executed with different parameters. This allows the LocalizationTargetEditor to be extensible to users for specialized localization target operations. - Introduced the LocalizationTargetCommand abstract base class. This class is what all othe LocalizationTargetEditor sub-commands should be drived from. A scan of all sub-classes of LocalizationTargetCommand will be scanned for to determine all available localization target commands. - Introduced the PluginLocalizationTargetCommand abstract base class. All commands to be operated on plugins should derive from this class. - Introduced the NewPluginLocalizationTarget sub-command which will create localization config files for plugins and make the necessary updates to .uplugin files. All plugins under a provided directory can be operated on at a time to batch create the necessary localization config files. - The NewPluginLocalizationTarget sub-command has perforce integration and can automatically add/check out all files that have been created/edited. - Introduced a number of classes to encapsulate all the data in the various localization config files. This allows for generation of localization config files from code. - Introduced the LocalizationConfigFileBuilder and LocalizationConfigFileGenerator base classes. These classes and their sub-classes are used to generate localization config files in the correct format provided the config file data. Current support is only for modular localization config files. However, the LocalizationConfigFileBuilder can also be used to generate Monolithic localization config files if necessary.also #rb: Jamie.Dale #jira: UE-194872, UE-194873, UE-194874, #test Used the NewPluginLocalizationTarget sub-command to generate a number of plugins. The generated localization config files yield correct localization gather results and the plugin .locres file was successfully loaded at runtime to display the correct localized text. [CL 28424727 by leon huang in ue5-main branch]
2023-10-03 14:44:56 -04:00
}
public static List<LocalizationTargetCommand> GetAllCommands()
{
return _nameToLocalizationTargetCommandMap.Values.ToList();
}
}
}