Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ExtractLanguageStrings utility command #17224

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ void IUtilityCommand.Run(Utility utility, string[] args)

foreach (var filename in modData.Manifest.ChromeLayout)
{
Console.WriteLine("# {0}:", filename);
var yaml = MiniYaml.FromFile(filename, false);
string name;
OpenRA.FileSystem.IReadOnlyPackage package;

modData.ModFiles.TryGetPackageContaining(filename, out package, out name);
name = package.Name + "/" + name;
Console.WriteLine("# {0}:", name);

var yaml = MiniYaml.FromFile(name, false);
FromChromeLayout(ref yaml, null,
translatableFields.Select(t => t.Name).Distinct(), null);
using (var file = new StreamWriter(filename))
using (var file = new StreamWriter(name))
file.WriteLine(yaml.WriteToString());
}

Expand All @@ -50,9 +56,9 @@ void IUtilityCommand.Run(Utility utility, string[] args)

internal static void FromChromeLayout(ref List<MiniYamlNode> nodes, MiniYamlNode parent, IEnumerable<string> translatables, string container)
{
var parentNode = parent != null ? parent.Key.Split('@') : null;
var parentType = parent != null ? parentNode.First() : null;
var parentLabel = parent != null ? parentNode.Last() : null;
var parentNode = parent != null && parent.Key != null ? parent.Key.Split('@') : null;
var parentType = parent != null && parent.Key != null ? parentNode.First() : null;
var parentLabel = parent != null && parent.Key != null ? parentNode.Last() : null;

if ((parentType == "Background" || parentType == "Container") && parentLabel.IsUppercase())
container = parentLabel;
Expand All @@ -62,7 +68,9 @@ internal static void FromChromeLayout(ref List<MiniYamlNode> nodes, MiniYamlNode
var alreadyTranslated = node.Value.Value != null && node.Value.Value.Contains('@');
if (translatables.Contains(node.Key) && !alreadyTranslated && parentLabel != null)
{
var translationKey = "{0}-{1}-{2}".F(container.Replace('_', '-'), parentLabel.Replace('_', '-'), node.Key.ToUpper());
var translationKey = "{0}-{1}".F(parentLabel.Replace('_', '-'), node.Key.ToUpper());
if (container != null)
translationKey = "{0}-".F(container.Replace('_', '-')) + translationKey;
Console.WriteLine("\t{0}: {1}", translationKey, node.Value.Value);
node.Value.Value = "@{0}@".F(translationKey);
}
Expand Down