Fix parsing gettext catalogs with only more than one line per message string, id, or context.
This commit is contained in:
@@ -40,6 +40,9 @@ namespace Claunia.Localization.Parsers
|
|||||||
string currentReference = "";
|
string currentReference = "";
|
||||||
string currentContext = "";
|
string currentContext = "";
|
||||||
Language currentLanguage = Language.None;
|
Language currentLanguage = Language.None;
|
||||||
|
bool inMsgId = false;
|
||||||
|
bool inMsgStr = false;
|
||||||
|
bool inMsgCtxt = false;
|
||||||
|
|
||||||
while(line != null)
|
while(line != null)
|
||||||
{
|
{
|
||||||
@@ -49,7 +52,7 @@ namespace Claunia.Localization.Parsers
|
|||||||
|
|
||||||
if(line == string.Empty)
|
if(line == string.Empty)
|
||||||
{
|
{
|
||||||
if(!firstEmptyMessageId)
|
if(!firstEmptyMessageId && currentMsgId != string.Empty)
|
||||||
{
|
{
|
||||||
Message message = localization.NewMessage();
|
Message message = localization.NewMessage();
|
||||||
|
|
||||||
@@ -75,6 +78,9 @@ namespace Claunia.Localization.Parsers
|
|||||||
extractedComment = "";
|
extractedComment = "";
|
||||||
currentReference = "";
|
currentReference = "";
|
||||||
currentContext = "";
|
currentContext = "";
|
||||||
|
inMsgId = false;
|
||||||
|
inMsgStr = false;
|
||||||
|
inMsgCtxt = false;
|
||||||
continue; // TODO
|
continue; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,30 +203,51 @@ namespace Claunia.Localization.Parsers
|
|||||||
|
|
||||||
if(line.StartsWith("msgid ", StringComparison.Ordinal))
|
if(line.StartsWith("msgid ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
currentMsgId += line.Substring(7, line.Length - 8);
|
currentMsgId = line.Substring(7, line.Length - 8);
|
||||||
|
inMsgId = true;
|
||||||
|
inMsgStr = false;
|
||||||
|
inMsgCtxt = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line.StartsWith("msgstr ", StringComparison.Ordinal))
|
if(line.StartsWith("msgstr ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
currentMsgString = line.Substring(7, line.Length - 8);
|
currentMsgString = line.Substring(7, line.Length - 8);
|
||||||
|
inMsgId = false;
|
||||||
|
inMsgStr = true;
|
||||||
|
inMsgCtxt = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line.StartsWith("msgctxt ", StringComparison.Ordinal))
|
if(line.StartsWith("msgctxt ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
currentContext = line.Substring(7, line.Length - 8);
|
currentContext = line.Substring(7, line.Length - 8);
|
||||||
|
inMsgId = false;
|
||||||
|
inMsgStr = false;
|
||||||
|
inMsgCtxt = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line[0] == '"')
|
if(line[0] != '"') continue;
|
||||||
|
|
||||||
|
if(inMsgId)
|
||||||
{
|
{
|
||||||
if(currentMsgId != string.Empty)
|
currentMsgId += line.Substring(1, line.Length - 2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inMsgStr)
|
||||||
{
|
{
|
||||||
currentMsgString += line.Substring(1, line.Length - 2);
|
currentMsgString += line.Substring(1, line.Length - 2);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(inMsgCtxt)
|
||||||
|
{
|
||||||
|
currentContext += line.Substring(1, line.Length - 2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
string projectString = line.Substring(1, line.Length - 2);
|
string projectString = line.Substring(1, line.Length - 2);
|
||||||
|
|
||||||
if(projectString.StartsWith("Project-Id-Version", StringComparison.Ordinal))
|
if(projectString.StartsWith("Project-Id-Version", StringComparison.Ordinal))
|
||||||
@@ -263,14 +290,12 @@ namespace Claunia.Localization.Parsers
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(projectString.StartsWith("Language", StringComparison.Ordinal))
|
if(!projectString.StartsWith("Language", StringComparison.Ordinal)) continue;
|
||||||
{
|
|
||||||
currentLocale = projectString.Substring(10, projectString.Length - 10);
|
currentLocale = projectString.Substring(10, projectString.Length - 10);
|
||||||
if(currentLocale.EndsWith("\\n", StringComparison.Ordinal))
|
if(currentLocale.EndsWith("\\n", StringComparison.Ordinal))
|
||||||
currentLocale = currentLocale.Substring(0, currentLocale.Length - 2);
|
currentLocale = currentLocale.Substring(0, currentLocale.Length - 2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return localization;
|
return localization;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user