Show
Ignore:
Timestamp:
07/02/08 11:22:52 (6 months ago)
Author:
edmanm
Message:

Tolerate mixing and matching the "msgctxt" and overloaded "#:" forms of
specifying message context.

Files:
1 modified

Legend:

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

    r2818 r2826  
    9494} 
    9595 
     96/** Parse the context name from <b>str</b>, where <b>str</b> is of the 
     97 * form ContextName#Number. This is the format used by translate-toolkit. */ 
     98QString 
     99parse_message_context_lame(const QString &str) 
     100{ 
     101  if (str.contains("#")) 
     102    return str.section("#", 0, 0); 
     103  return QString(); 
     104} 
     105 
    96106/** Parse the PO-formatted message string from <b>msg</b>. If <b>msg</b> is a 
    97107 * multiline string, the extra double quotes will be replaced with newlines 
     
    119129} 
    120130 
     131/** Skip past the header portion of the PO file and any leading whitespace.  
     132 * The next line read from <b>po</b> will be the first non-header line in the 
     133 * document. */ 
     134void 
     135skip_po_header(QTextStream *po) 
     136{ 
     137  QString line; 
     138  /* Skip any leading whitespace before the header */ 
     139  po->skipWhiteSpace(); 
     140  /* Read to the first empty line */ 
     141  line = po->readLine(); 
     142  while (!po->atEnd() && !line.isEmpty()) 
     143    line = po->readLine(); 
     144} 
     145 
    121146/** Convert <b>po</b> from the PO format to a TS-formatted XML document. 
    122147 * <b>ts</b> will be set to the resulting TS document. Return the number of 
     
    137162 
    138163  *ts = new_ts_document(); 
    139  
     164   
     165  skip_po_header(po); 
     166  line = read_next_line(po); 
    140167  while (!po->atEnd()) { 
    141     /* Find the start of the next translation */ 
    142     while (!line.startsWith("msgctxt")) 
     168    /* Ignore all "#" lines except "#:" */ 
     169    while (line.startsWith("#")) { 
     170      if (line.startsWith("#:")) { 
     171        /* Context was specified with the stupid overloaded "#:" syntax.*/ 
     172        msgctxt = line.section(" ", 1); 
     173        msgctxt = parse_message_context_lame(msgctxt); 
     174      } 
    143175      line = read_next_line(po); 
    144     msgctxt = line.section(" ", 1); 
    145     msgctxt = parse_message_context(msgctxt); 
    146  
     176    } 
     177 
     178    /* A context specified on a "msgctxt" line takes precedence over a context 
     179     * specified using the overload "#:" notation. */ 
     180    if (line.startsWith("msgctxt ")) {     
     181      msgctxt = line.section(" ", 1); 
     182      msgctxt = parse_message_context(msgctxt); 
     183      line = read_next_line(po); 
     184    } 
     185     
    147186    /* Parse the (possibly multiline) message source string */ 
    148     line = read_next_line(po); 
    149187    if (!line.startsWith("msgid ")) { 
    150188      *errorMessage = "expected 'msgid' line";