Files
leon huang 95acda43f6 Localization:
Introduced opt in localization for plugins. Plugins can be set to never have localization config files generated, auto-generated or have the localization pipeline use the user generated localization config files.
- All existing plugins with localization targets will be retrofitted to have a LocalizationConfigGenerationPolicy of Never to match current behavior.
- Introduced the LocalizationConfigGenerationPolicy enum to plugin descriptors and LocalizationTargetDescriptors. This controls whether plugin localization targets use user generated localization config files, auto-generated localization config files or if the plugin is never to have localization config files and thus not localized.
- Introduced a step in the Localize UAT command to auto-generate localization config files with default settings for plugins that opt into the auto-generation feature.
- Added a clean up step in the Localize uAT command to delete all auto-generated files and folders from a run of the command.
- Added a -PreserveAutoGeneratedResources flag for the Localize UAT command to preserve the auto-generated files and directories for debugging.
-Updated both the C# and C++ version of the LocalizationTargetDescriptor to contain the new LocalizationConfigGenerationPolicy and have them read and written from the plugin descriptor files.
- Updated the NewPluginLocalizationTarget command under the LocalizationTargetEditor UAT command to accept a LocalizationConfigGenerationPolicy as a command line argument for all plugin localization targets to be created.
If the parameter is not specified, the parameter defaults to the Auto LocalizationConfigGenerationPolicy for all the plugins specified.
#rb: Jamie.Dale
#jira: UE-194880, UE-194879
#test Used the NewPluginLocalizationTarget sub-command to create plugins with an auto localization target. Used the Localize UAT command to perform a gather for such a plugin. Config files were indeed generated, the plugin was gathered and the loc data stored in PluginName/Content/Localization and then the config files were deleted. No fuss, no muss

[CL 30172150 by leon huang in ue5-main branch]
2023-12-06 19:03:56 -05:00

184 lines
5.8 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Linq;
using System.Diagnostics;
using EpicGames.Core;
namespace UnrealBuildTool
{
/// <summary>
///
/// </summary>
public enum LocalizationTargetDescriptorLoadingPolicy
{
/// <summary>
///
/// </summary>
Never,
/// <summary>
///
/// </summary>
Always,
/// <summary>
///
/// </summary>
Editor,
/// <summary>
///
/// </summary>
Game,
/// <summary>
///
/// </summary>
PropertyNames,
/// <summary>
///
/// </summary>
ToolTips,
};
/// <summary>
/// How this localization target should be generated during the localization gather pipeline
/// </summary>
public enum LocalizationConfigGenerationPolicy
{
/// <summary>
/// This localization target should never have localization config files associated with it during the localization gather pipeline.
/// </summary>
Never,
/// <summary>
/// This localization target should only use user generated localization config files during the localization gather pipeline.
/// </summary>
User,
/// <summary>
/// Default auto-generated localization config files will be used to generate the localization target and localization content files during the localization gather pipeline
/// </summary>
Auto,
}
/// <summary>
/// Description of a localization target.
/// </summary>
[DebuggerDisplay("Name={Name}")]
public class LocalizationTargetDescriptor
{
/// <summary>
/// Name of this target
/// </summary>
public readonly string Name;
/// <summary>
/// When should the localization data associated with a target should be loaded?
/// </summary>
public LocalizationTargetDescriptorLoadingPolicy LoadingPolicy;
/// <summary>
/// How should this localization target's localization config files be generated during a localization gather.
/// </summary>
public LocalizationConfigGenerationPolicy ConfigGenerationPolicy;
/// <summary>
/// Constructor
/// </summary>
/// <param name="InName">Name of the target</param>
/// <param name="InLoadingPolicy">When should the localization data associated with a target should be loaded?</param>
public LocalizationTargetDescriptor(string InName, LocalizationTargetDescriptorLoadingPolicy InLoadingPolicy)
{
Name = InName;
LoadingPolicy = InLoadingPolicy;
// Older plugins and localization target descriptors won't have the generation policy. We default it to Never.
ConfigGenerationPolicy = LocalizationConfigGenerationPolicy.Never;
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="InName">The name of the localization target.</param>
/// <param name="InLoadingPolicy"> When the localization data associated with this localization target should be loaded.</param>
/// <param name="InGenerationPolicy">How the localization config files should be generated during a localization gather to create the localization data files.</param>
public LocalizationTargetDescriptor(string InName, LocalizationTargetDescriptorLoadingPolicy InLoadingPolicy, LocalizationConfigGenerationPolicy InGenerationPolicy)
{
Name = InName;
LoadingPolicy = InLoadingPolicy;
ConfigGenerationPolicy = InGenerationPolicy;
}
/// <summary>
/// Constructs a LocalizationTargetDescriptor from a Json object
/// </summary>
/// <param name="InObject"></param>
/// <returns>The new localization target descriptor</returns>
public static LocalizationTargetDescriptor FromJsonObject(JsonObject InObject)
{
LocalizationTargetDescriptor descriptor = new LocalizationTargetDescriptor(InObject.GetStringField("Name"), InObject.GetEnumField<LocalizationTargetDescriptorLoadingPolicy>("LoadingPolicy"));
LocalizationConfigGenerationPolicy policy;
if (InObject.TryGetEnumField<LocalizationConfigGenerationPolicy>("ConfigGenerationPolicy", out policy))
{
descriptor.ConfigGenerationPolicy = policy;
}
return descriptor;
}
/// <summary>
/// Write this target to a JsonWriter
/// </summary>
/// <param name="Writer">Writer to output to</param>
void Write(JsonWriter Writer)
{
Writer.WriteObjectStart();
Writer.WriteValue("Name", Name);
Writer.WriteValue("LoadingPolicy", LoadingPolicy.ToString());
Writer.WriteValue("ConfigGenerationPolicy", ConfigGenerationPolicy.ToString());
Writer.WriteObjectEnd();
}
JsonObject ToJsonObject()
{
JsonObject localizationTargetObject= new JsonObject();
localizationTargetObject.AddOrSetFieldValue("Name", Name);
localizationTargetObject.AddOrSetFieldValue("LoadingPolicy", LoadingPolicy.ToString());
localizationTargetObject.AddOrSetFieldValue("ConfigGenerationPolicy", ConfigGenerationPolicy.ToString());
return localizationTargetObject;
}
/// <summary>
/// Write an array of target descriptors
/// </summary>
/// <param name="Writer">The Json writer to output to</param>
/// <param name="Name">Name of the array</param>
/// <param name="Targets">Array of targets</param>
public static void WriteArray(JsonWriter Writer, string Name, LocalizationTargetDescriptor[]? Targets)
{
if (Targets != null && Targets.Length > 0)
{
Writer.WriteArrayStart(Name);
foreach (LocalizationTargetDescriptor Target in Targets)
{
Target.Write(Writer);
}
Writer.WriteArrayEnd();
}
}
/// <summary>
/// Updates a JsonObject with an array of localization target descriptors.
/// </summary>
/// <param name="InObject">The Json object to update.</param>
/// <param name="Name">Name of the array</param>
/// <param name="Targets">Array of targets</param>
public static void UpdateJson(JsonObject InObject, string Name, LocalizationTargetDescriptor[]? Targets)
{
if (Targets != null && Targets.Length > 0)
{
JsonObject[] JsonObjects = Targets.Select(X => X.ToJsonObject()).ToArray();
InObject.AddOrSetFieldValue(Name, JsonObjects);
}
}
}
}