2015-08-01 23:03:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace EduNetworkBuilder
|
|
|
|
|
{
|
2018-03-15 23:12:20 +01:00
|
|
|
|
[Serializable]
|
2015-08-01 23:03:23 +02:00
|
|
|
|
public class LanguageString
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public string text="";
|
|
|
|
|
public string language="en";
|
|
|
|
|
public string tag_type;
|
2017-07-30 01:31:19 +02:00
|
|
|
|
private LanguageString() { }
|
2015-08-01 23:03:23 +02:00
|
|
|
|
|
|
|
|
|
public LanguageString(string lang, string msg, string tag)
|
|
|
|
|
{
|
|
|
|
|
text = msg;
|
|
|
|
|
language = lang;
|
|
|
|
|
tag_type = tag;
|
|
|
|
|
}
|
2017-07-30 01:31:19 +02:00
|
|
|
|
public LanguageString Clone()
|
|
|
|
|
{
|
|
|
|
|
LanguageString newitem = new LanguageString();
|
|
|
|
|
newitem.text = text;
|
|
|
|
|
newitem.language = language;
|
|
|
|
|
newitem.tag_type = tag_type;
|
|
|
|
|
return newitem;
|
|
|
|
|
}
|
2015-08-01 23:03:23 +02:00
|
|
|
|
|
|
|
|
|
public LanguageString(XmlNode theNode, string tag)
|
|
|
|
|
{
|
|
|
|
|
XmlNodeType myNodetype = theNode.NodeType;
|
|
|
|
|
if (myNodetype == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
if(Regex.IsMatch(theNode.Name.ToLower(),"^[a-z][a-z]_" + tag))
|
|
|
|
|
{
|
|
|
|
|
//We have a language, and then a message
|
|
|
|
|
text = theNode.InnerText;
|
|
|
|
|
language = Regex.Replace(theNode.Name.ToLower(), "_" + tag, "");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//It is just a message. Use the default language.
|
|
|
|
|
language = "en";
|
|
|
|
|
text = theNode.InnerText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tag_type = tag;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-16 19:59:14 +01:00
|
|
|
|
public bool Equals(LanguageString compareWith)
|
|
|
|
|
{
|
|
|
|
|
if (text != compareWith.text) return false;
|
|
|
|
|
if (tag_type != compareWith.tag_type) return false;
|
|
|
|
|
if (language != compareWith.language) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 23:03:23 +02:00
|
|
|
|
public void Save(XmlWriter writer)
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString(language+"_" + tag_type, text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-15 23:12:20 +01:00
|
|
|
|
[Serializable]
|
2015-08-01 23:03:23 +02:00
|
|
|
|
public class LanguageStrings
|
|
|
|
|
{
|
|
|
|
|
List<LanguageString> TheStrings = new List<LanguageString>();
|
|
|
|
|
string tag = "";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Make a language string list of type: "message", "title"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">Should be of type "message" or "title"</param>
|
|
|
|
|
public LanguageStrings(string type)
|
|
|
|
|
{
|
|
|
|
|
tag = type;
|
|
|
|
|
}
|
2017-07-30 01:31:19 +02:00
|
|
|
|
private LanguageStrings() { }
|
|
|
|
|
public LanguageStrings(LanguageStrings ToCopy)
|
|
|
|
|
{
|
|
|
|
|
LanguageStrings.Clone(ToCopy, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clone(LanguageStrings source, LanguageStrings dest)
|
|
|
|
|
{
|
|
|
|
|
dest.tag = source.tag;
|
|
|
|
|
dest.TheStrings.Clear();
|
|
|
|
|
foreach(LanguageString ls in source.TheStrings)
|
|
|
|
|
{
|
|
|
|
|
dest.TheStrings.Add(ls.Clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public LanguageStrings Clone()
|
|
|
|
|
{
|
|
|
|
|
LanguageStrings newitem = new LanguageStrings();
|
|
|
|
|
LanguageStrings.Clone(this, newitem);
|
|
|
|
|
return newitem;
|
|
|
|
|
}
|
2015-08-01 23:03:23 +02:00
|
|
|
|
|
|
|
|
|
public void Add(XmlNode theNode)
|
|
|
|
|
{
|
|
|
|
|
LanguageString oneString = new LanguageString(theNode, tag);
|
|
|
|
|
//remove duplicates
|
|
|
|
|
for (int i = TheStrings.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (TheStrings[i].language == oneString.language)
|
|
|
|
|
{
|
|
|
|
|
TheStrings.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TheStrings.Add(oneString);
|
|
|
|
|
}
|
|
|
|
|
public void Add(string Text)
|
|
|
|
|
{
|
2017-06-16 18:27:53 +02:00
|
|
|
|
NBSettings oursettings = NB.GetSettings();
|
|
|
|
|
LanguageString oneString = new LanguageString(oursettings.ChosenLanguage,Text,tag);
|
2015-08-01 23:03:23 +02:00
|
|
|
|
//remove duplicates
|
|
|
|
|
for (int i = TheStrings.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (TheStrings[i].language == oneString.language)
|
|
|
|
|
{
|
|
|
|
|
TheStrings.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TheStrings.Add(oneString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(XmlWriter writer)
|
|
|
|
|
{
|
|
|
|
|
foreach(LanguageString LS in TheStrings)
|
|
|
|
|
{
|
|
|
|
|
LS.Save(writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetText(string language)
|
|
|
|
|
{
|
|
|
|
|
//Find the matching language
|
|
|
|
|
foreach(LanguageString LS in TheStrings)
|
|
|
|
|
{
|
|
|
|
|
if(LS.language == language)
|
|
|
|
|
{
|
|
|
|
|
return LS.text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return the english version if one exists
|
|
|
|
|
if(language != "en")
|
|
|
|
|
{
|
|
|
|
|
return GetText("en");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return the first language (if the puzzle is only in french, use that.)
|
|
|
|
|
if (TheStrings.Count > 0)
|
|
|
|
|
return TheStrings[0].text;
|
|
|
|
|
|
|
|
|
|
//If there is no language, return a blank message
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 22:57:12 +02:00
|
|
|
|
public void ChangeText(string language, string NewText)
|
|
|
|
|
{
|
|
|
|
|
bool done = false;
|
|
|
|
|
//Find the matching language
|
|
|
|
|
foreach (LanguageString LS in TheStrings)
|
|
|
|
|
{
|
|
|
|
|
if (LS.language == language)
|
|
|
|
|
{
|
|
|
|
|
LS.text = NewText;
|
|
|
|
|
done = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!done)
|
|
|
|
|
{
|
|
|
|
|
LanguageString oneString = new LanguageString(language, NewText, tag);
|
|
|
|
|
TheStrings.Add(oneString);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 23:03:23 +02:00
|
|
|
|
public string GetText()
|
|
|
|
|
{
|
2017-06-16 18:27:53 +02:00
|
|
|
|
NBSettings oursettings = NB.GetSettings();
|
|
|
|
|
return GetText(oursettings.ChosenLanguage);
|
2015-08-01 23:03:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|