Allow to extract translations from a single map
This commit is contained in:
committed by
Gustas Kažukauskas
parent
7004b552c9
commit
eb550bbbbb
@@ -30,10 +30,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
|
|
||||||
bool IUtilityCommand.ValidateArguments(string[] args)
|
bool IUtilityCommand.ValidateArguments(string[] args)
|
||||||
{
|
{
|
||||||
return true;
|
return args.Length <= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Extract fluent strings that are not yet localized.")]
|
[Desc("[FILENAME]", "Extract fluent strings that are not yet localized.")]
|
||||||
void IUtilityCommand.Run(Utility utility, string[] args)
|
void IUtilityCommand.Run(Utility utility, string[] args)
|
||||||
{
|
{
|
||||||
// HACK: The engine code assumes that Game.modData is set.
|
// HACK: The engine code assumes that Game.modData is set.
|
||||||
@@ -47,6 +47,18 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
.Where(t => t.Value.Length > 0)
|
.Where(t => t.Value.Length > 0)
|
||||||
.ToDictionary(t => t.Key, t => t.Value);
|
.ToDictionary(t => t.Key, t => t.Value);
|
||||||
|
|
||||||
|
// Extract from a specific map.
|
||||||
|
if (args.Length == 2)
|
||||||
|
{
|
||||||
|
var mapPath = args[1];
|
||||||
|
var resolved = Platform.ResolvePath(mapPath);
|
||||||
|
|
||||||
|
using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(resolved))
|
||||||
|
ExtractFromMap(package, modData, traitInfos);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var modRules = UpdateUtils.LoadModYaml(modData, UpdateUtils.FilterExternalFiles(modData, modData.Manifest.Rules, []));
|
var modRules = UpdateUtils.LoadModYaml(modData, UpdateUtils.FilterExternalFiles(modData, modData.Manifest.Rules, []));
|
||||||
|
|
||||||
// Include files referenced in maps.
|
// Include files referenced in maps.
|
||||||
@@ -68,13 +80,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
ExtractFromFile(Path.Combine(fluentPackage.Name, "rules.ftl"), modRules, traitInfos);
|
ExtractFromFile(Path.Combine(fluentPackage.Name, "rules.ftl"), modRules, traitInfos);
|
||||||
modRules.Save();
|
modRules.Save();
|
||||||
|
|
||||||
// Extract from maps.
|
|
||||||
foreach (var package in modData.MapCache.EnumerateMapPackagesWithoutCaching())
|
foreach (var package in modData.MapCache.EnumerateMapPackagesWithoutCaching())
|
||||||
|
ExtractFromMap(package, modData, traitInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ExtractFromMap(IReadWritePackage package, ModData modData, Dictionary<string, string[]> traitInfos)
|
||||||
{
|
{
|
||||||
using (var mapStream = package.GetStream("map.yaml"))
|
using (var mapStream = package.GetStream("map.yaml"))
|
||||||
{
|
{
|
||||||
if (mapStream == null)
|
if (mapStream == null)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
var yaml = new MiniYamlBuilder(null, MiniYaml.FromStream(mapStream, $"{package.Name}:map.yaml", false).ToList());
|
var yaml = new MiniYamlBuilder(null, MiniYaml.FromStream(mapStream, $"{package.Name}:map.yaml", false).ToList());
|
||||||
var mapRules = new YamlFileSet() { (package, "map.yaml", yaml.Nodes) };
|
var mapRules = new YamlFileSet() { (package, "map.yaml", yaml.Nodes) };
|
||||||
@@ -100,7 +115,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
mapRules.Save();
|
mapRules.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void ExtractFromFile(string fluentPath, YamlFileSet yamlSet, Dictionary<string, string[]> traitInfos, Action addAction = null)
|
static void ExtractFromFile(string fluentPath, YamlFileSet yamlSet, Dictionary<string, string[]> traitInfos, Action addAction = null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user