Changeset 2818 for vidalia/trunk/src

Show
Ignore:
Timestamp:
07/02/08 01:17:18 (5 months ago)
Author:
edmanm
Message:

Update po2ts to support parsing msgctxt lines.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vidalia/trunk/src/tools/po2ts/po2ts.cpp

    r2813 r2818  
    8585 
    8686/** Parse the context name from <b>str</b>, where the context name is of the 
    87  * form ContextName#Number. This is the format used by translate-toolkit. */ 
     87 * form DQUOTE ContextName DQUOTE. */ 
    8888QString 
    89 parse_context_name(const QString &str) 
    90 { 
    91   if (str.contains("#")) 
    92     return str.section("#", 0, 0); 
    93   return QString(); 
     89parse_message_context(const QString &str) 
     90{ 
     91  QString out = str.trimmed(); 
     92  out = out.replace("\"", ""); 
     93  return out; 
    9494} 
    9595 
     
    126126po2ts(QTextStream *po, QDomDocument *ts, QString *errorMessage) 
    127127{ 
    128   QString line, context, msgid, msgstr; 
     128  QString line; 
     129  QString msgctxt, msgid, msgstr; 
    129130  QHash<QString,QDomElement> contextElements; 
    130131  QDomElement contextElement, msgElement, transElement; 
     
    138139 
    139140  while (!po->atEnd()) { 
    140     /* Parse the context name and ignore other "#" lines. */ 
    141     if (!line.startsWith("#: ")) { 
     141    /* Find the start of the next translation */ 
     142    while (!line.startsWith("msgctxt")) 
    142143      line = read_next_line(po); 
    143       continue; 
    144     } 
    145     context = parse_context_name(line.section(" ", 1)); 
    146     while (line.startsWith("#")) 
    147       line = read_next_line(po); 
     144    msgctxt = line.section(" ", 1); 
     145    msgctxt = parse_message_context(msgctxt); 
    148146 
    149147    /* Parse the (possibly multiline) message source string */ 
     148    line = read_next_line(po); 
    150149    if (!line.startsWith("msgid ")) { 
    151150      *errorMessage = "expected 'msgid' line"; 
     
    176175 
    177176    /* Add the message and translation to the .ts document */ 
    178     if (contextElements.contains(context)) { 
    179       contextElement = contextElements.value(context); 
     177    if (contextElements.contains(msgctxt)) { 
     178      contextElement = contextElements.value(msgctxt); 
    180179    } else { 
    181       contextElement = new_context_element(ts, context); 
     180      contextElement = new_context_element(ts, msgctxt); 
    182181      ts->documentElement().appendChild(contextElement); 
    183       contextElements.insert(context, contextElement); 
     182      contextElements.insert(msgctxt, contextElement); 
    184183    } 
    185184    contextElement.appendChild(new_message_element(ts, msgid, msgstr));