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 currentContext = "";
|
||||
Language currentLanguage = Language.None;
|
||||
bool inMsgId = false;
|
||||
bool inMsgStr = false;
|
||||
bool inMsgCtxt = false;
|
||||
|
||||
while(line != null)
|
||||
{
|
||||
@@ -49,7 +52,7 @@ namespace Claunia.Localization.Parsers
|
||||
|
||||
if(line == string.Empty)
|
||||
{
|
||||
if(!firstEmptyMessageId)
|
||||
if(!firstEmptyMessageId && currentMsgId != string.Empty)
|
||||
{
|
||||
Message message = localization.NewMessage();
|
||||
|
||||
@@ -75,6 +78,9 @@ namespace Claunia.Localization.Parsers
|
||||
extractedComment = "";
|
||||
currentReference = "";
|
||||
currentContext = "";
|
||||
inMsgId = false;
|
||||
inMsgStr = false;
|
||||
inMsgCtxt = false;
|
||||
continue; // TODO
|
||||
}
|
||||
|
||||
@@ -197,30 +203,51 @@ namespace Claunia.Localization.Parsers
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(line.StartsWith("msgstr ", StringComparison.Ordinal))
|
||||
{
|
||||
currentMsgString = line.Substring(7, line.Length - 8);
|
||||
inMsgId = false;
|
||||
inMsgStr = true;
|
||||
inMsgCtxt = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(line.StartsWith("msgctxt ", StringComparison.Ordinal))
|
||||
{
|
||||
currentContext = line.Substring(7, line.Length - 8);
|
||||
inMsgId = false;
|
||||
inMsgStr = false;
|
||||
inMsgCtxt = true;
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(inMsgCtxt)
|
||||
{
|
||||
currentContext += line.Substring(1, line.Length - 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
string projectString = line.Substring(1, line.Length - 2);
|
||||
|
||||
if(projectString.StartsWith("Project-Id-Version", StringComparison.Ordinal))
|
||||
@@ -263,14 +290,12 @@ namespace Claunia.Localization.Parsers
|
||||
continue;
|
||||
}
|
||||
|
||||
if(projectString.StartsWith("Language", StringComparison.Ordinal))
|
||||
{
|
||||
if(!projectString.StartsWith("Language", StringComparison.Ordinal)) continue;
|
||||
|
||||
currentLocale = projectString.Substring(10, projectString.Length - 10);
|
||||
if(currentLocale.EndsWith("\\n", StringComparison.Ordinal))
|
||||
currentLocale = currentLocale.Substring(0, currentLocale.Length - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return localization;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user