Merge pull request #27 from decriptor/master
Update resx parser and fix android generator
This commit is contained in:
Коммит
b608957e78
|
@ -173,6 +173,7 @@ namespace Vernacular.Potato.Internal
|
|||
case 'f': PushString ('\f'); break;
|
||||
case 'n': PushString ('\n'); break;
|
||||
case 'r': PushString ('\r'); break;
|
||||
case 't': PushString ('\t'); break;
|
||||
case 'v': PushString ('\v'); break;
|
||||
case '0': PushString ('\0'); break;
|
||||
default: throw new SyntaxException (this, "Invalid string escape sequence");
|
||||
|
|
|
@ -60,9 +60,10 @@ namespace Vernacular.Generators
|
|||
|
||||
private void WriteString (XElement parent, string name, string value, bool formatted = false)
|
||||
{
|
||||
value = EncodeValue(value);
|
||||
var string_element = XElement.Parse (String.Format ("<string{0}>{1}</string>",
|
||||
formatted ? String.Empty : " formatted=\"false\"",
|
||||
value.Replace ("'", "\\'")));
|
||||
value));
|
||||
string_element.SetAttributeValue ("name", name);
|
||||
parent.Add (string_element);
|
||||
}
|
||||
|
@ -97,5 +98,21 @@ namespace Vernacular.Generators
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
string EncodeValue (string value)
|
||||
{
|
||||
if (value.Contains("&"))
|
||||
value = value.Replace("&", "&");
|
||||
if (value.Contains("<"))
|
||||
value = value.Replace("<", "<");
|
||||
if (value.Contains(">"))
|
||||
value = value.Replace(">", ">");
|
||||
if (value.Contains("..."))
|
||||
value = value.Replace("...", "…");
|
||||
if (value.Contains("'"))
|
||||
value = value.Replace("'", "\\'");
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,11 +64,21 @@ namespace Vernacular.Parsers
|
|||
foreach (DictionaryEntry item in reader) {
|
||||
var name = (string)item.Key;
|
||||
var node = (ResXDataNode)item.Value;
|
||||
yield return new LocalizedString {
|
||||
var localized_string = new LocalizedString {
|
||||
Name = name,
|
||||
DeveloperComments = node.Comment,
|
||||
UntranslatedSingularValue = (string)node.GetValue(null as ITypeResolutionService)
|
||||
UntranslatedSingularValue = name,
|
||||
TranslatedValues = new string [] {(string)node.GetValue(null as ITypeResolutionService) }
|
||||
};
|
||||
|
||||
for (int i = 0; i < localized_string.TranslatedValues.Length; i++)
|
||||
{
|
||||
var s = localized_string.TranslatedValues [i];
|
||||
s = s.Replace ("\r", "");
|
||||
localized_string.TranslatedValues[i] = s;
|
||||
}
|
||||
|
||||
yield return localized_string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче