Files

103 lines
2.5 KiB
C#
Raw Permalink 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 EpicGames.Core;
using System;
using UnrealBuildTool;
namespace EpicGames.Localization
{
public enum LocalizationConfigFileFormat
{
LegacyMonolithic,
Modular,
// Add new values above this comment and upda te the value of Latest
Latest = Modular
}
public class LocalizationConfigFile
{
private readonly ConfigFile _configFile;
public string Name { get; set; } = "";
public LocalizationConfigFile()
{
_configFile = new ConfigFile();
}
public LocalizationConfigFile(string fileName)
{
_configFile = new ConfigFile();
Name = fileName;
}
public LocalizationConfigFileSection FindOrAddSection(string sectionName)
{
ConfigFileSection configSection = _configFile.FindOrAddSection(sectionName);
return new LocalizationConfigFileSection(configSection);
}
public void Load(string filePath)
{
// @TODOLocalization: Load the config file and parse all the data into the various LocalizationConfigFileParam classes
}
public void Write(FileReference destinationFilePath)
{
// Go through all the config values and replace \ directory separators with / for uniformity across platforms
foreach (string sectionName in _configFile.SectionNames)
{
ConfigFileSection section;
if (_configFile.TryGetSection(sectionName, out section))
{
foreach (ConfigLine line in section.Lines)
{
line.Value = line.Value.Replace('\\', '/');
}
}
}
_configFile.Write(destinationFilePath);
}
}
public class LocalizationConfigFileSection
{
private readonly ConfigFileSection _configFileSection;
public LocalizationConfigFileSection(ConfigFileSection configFileSection)
{
_configFileSection = configFileSection;
}
public void AddValue(string key, bool value)
{
if (!String.IsNullOrEmpty(key))
{
_configFileSection.Lines.Add(new ConfigLine(ConfigLineAction.Set, key, value ? "true" : "false"));
}
}
public void AddValue(string key, string value)
{
if (!String.IsNullOrEmpty(value) && !String.IsNullOrEmpty(key))
{
_configFileSection.Lines.Add(new ConfigLine(ConfigLineAction.Set, key, value));
}
}
public void AddValues(string key, string[] values)
{
if (String.IsNullOrEmpty(key) || values.Length == 0)
{
return;
}
foreach (string value in values)
{
if (!String.IsNullOrEmpty(value))
{
_configFileSection.Lines.Add(new ConfigLine(ConfigLineAction.Set, key, value));
}
}
}
}
}