Skip to content
Open
Show file tree
Hide file tree
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
52 changes: 33 additions & 19 deletions Src/Utilities/HCSynthByGloss/HCSynthByGloss/HCSynthByGloss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,72 @@
using SIL.Machine.Translation;
using SIL.HCSynthByGloss;
using SIL.Utils;
using HCSynthByGlossLib;
using System.Globalization;
using System.Threading;

namespace SIL.HCSynthByGloss
{
class HCSynthByGloss
{
static void Main(string[] args)
{
const int iLocale = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever use of constants to make command line args meaningful!

const int iArgH = 1;
const int iHcFile = 2;
const int iArgG = 3;
const int iGlossFile = 4;
const int iArgO = 5;
const int iOutputFile = 6;
const int iArgT = 7;
const int iArgS = 8;

bool doTracing = false;
bool showTracing = false;
int argCount = args.Count();
if (argCount != 6 || args[0] != "-h" || args[2] != "-g" || args[4] != "-o")
if (argCount > 0 )
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(args[iLocale]);
}
if (argCount != 7 || args[iArgH] != "-h" || args[iArgG] != "-g" || args[iArgO] != "-o")
{
if (argCount == 7 && args[6] == "-t")
if (argCount == 8 && args[iArgT] == "-t")
{
doTracing = true;
}
else if (argCount == 8 && args[6] == "-t" && args[7] == "-s")
else if (argCount == 9 && args[iArgT] == "-t" && args[iArgS] == "-s")
{
doTracing = true;
showTracing = true;
}
else
{
Console.WriteLine("Usage:");
Console.WriteLine(
"HCSynthByGloss -h HC.xml_file -g gloss_file -o output (-t (-s))"
);
Console.WriteLine("\t-t = turn on tracing");
Console.WriteLine(
"\t-s = show the tracing result in the system default web browser; -s is only valid when also using -t"
);
Console.WriteLine(HCSynthByGlossStrings.ksUsage);
Console.WriteLine(HCSynthByGlossStrings.ksCommandLineUsage);
Console.WriteLine(HCSynthByGlossStrings.ksTurnOnTracing);
Console.WriteLine(HCSynthByGlossStrings.ksShowTracing);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are always used together, I think it would be best to combine them into a single string.

Environment.Exit(1);
}
}
if (!File.Exists(args[1]))
if (!File.Exists(args[iHcFile]))
{
Console.WriteLine("Could not find file '" + args[1] + "'.");
Console.WriteLine(HCSynthByGlossStrings.ksCouldNotFindFile + args[iHcFile] + "'.");
Environment.Exit(2);
}
if (!File.Exists(args[3]))
if (!File.Exists(args[iGlossFile]))
{
Console.WriteLine("Could not find file '" + args[3] + "'.");
Console.WriteLine(HCSynthByGlossStrings.ksCouldNotFindFile + args[iGlossFile] + "'.");
Environment.Exit(3);
}

var dll = new HCSynthByGlossDll(args[5]);
dll.SetHcXmlFile(args[1]);
dll.SetGlossFile(args[3]);
var dll = new HCSynthByGlossDll(args[iOutputFile]);
dll.LocaleCode = args[iLocale];
dll.SetHcXmlFile(args[iHcFile]);
dll.SetGlossFile(args[iGlossFile]);
dll.DoTracing = doTracing;
dll.ShowTracing = showTracing;
var result = dll.Process();
Console.WriteLine("Processing result: " + result + ".");
Console.WriteLine(HCSynthByGlossStrings.ksProcessingResult + result + ".");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using HCSynthByGloss;
using HCSynthByGlossLib;
using Icu;
using SIL.Machine.Morphology.HermitCrab;
using SIL.Utils;
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Xml.XPath;
using System.Xml.Xsl;

Expand All @@ -17,10 +21,11 @@ public class HCSynthByGlossDll
public string HcXmlFile { get; set; } = "";
public string GlossFile { get; set; } = "";
public string OutputFile { get; set; } = "";
public string kSuccess { get; } = "Success!";
public string kError1 { get; } = "Could not find ";
public string kHCXmlFile { get; } = "HC XML file";
public string kGlossFile { get; } = "Gloss file";
public string LocaleCode { get; set; } = "en";
public string kSuccess { get; } = HCSynthByGlossStrings.ksSuccess;
public string kError1 { get; } = HCSynthByGlossStrings.ksCouldNotFind;
public string kHCXmlFile { get; } = HCSynthByGlossStrings.ksHCXmlFile;
public string kGlossFile { get; } = HCSynthByGlossStrings.ksGlossFile;
public string kError2 { get; } = " '";
public string kError3 { get; } = "'";
Language synLang;
Expand Down Expand Up @@ -55,7 +60,7 @@ public string SetGlossFile(string value)

public string Process()
{

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(LocaleCode);
if (!File.Exists(HcXmlFile))
{
return kError1 + kHCXmlFile + kError2 + HcXmlFile + kError3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@ public void ProcessTest()

[Test]
public void ProcessBadInputFilesTest()
{
CheckErrors("en");
CheckErrors("es");
CheckErrors("de");
CheckErrors("fr");
}

private void CheckErrors(string localeCode)
{
dll = new HCSynthByGlossDll(tempFile);
dll.LocaleCode = localeCode;
result = dll.Process();
Assert.AreEqual(dll.kError1 + dll.kHCXmlFile + dll.kError2 + "" + dll.kError3, result);
result = dll.SetHcXmlFile(hcConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,44 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Update="HCSynthByGlossStrings.de.Designer.cs">
<DependentUpon>HCSynthByGlossStrings.de.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="HCSynthByGlossStrings.fr.Designer.cs">
<DependentUpon>HCSynthByGlossStrings.fr.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="HCSynthByGlossStrings.es.Designer.cs">
<DependentUpon>HCSynthByGlossStrings.es.resx</DependentUpon>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="HCSynthByGlossStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>HCSynthByGlossStrings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="HCSynthByGlossStrings.de.resx">
<LastGenOutput>HCSynthByGlossStrings.de.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="HCSynthByGlossStrings.fr.resx">
<LastGenOutput>HCSynthByGlossStrings.fr.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="HCSynthByGlossStrings.es.resx">
<LastGenOutput>HCSynthByGlossStrings.es.Designer.cs</LastGenOutput>
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="HCSynthByGlossStrings.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>HCSynthByGlossStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading