Changeset 2817 for vidalia/trunk/src

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

Modify ts2po to use a 'msgctxt' line for specifying a message's context,
rather than overloading the "#:" line (pootle > 1.0 supports msgctxt). Also
now use the "#:", as intended, for the string's filename and line number.

Location:
vidalia/trunk/src/tools/ts2po
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • vidalia/trunk/src/tools/ts2po/CMakeLists.txt

    r2747 r2817  
    1212 
    1313## Define this version of ts2po 
    14 set(VERSION "0.1") 
     14set(VERSION "0.2") 
    1515 
    1616## Include the source and binary directories so it can find out configured 
  • vidalia/trunk/src/tools/ts2po/ts2po.cpp

    r2814 r2817  
    1010 
    1111#include <QFile> 
     12#include <QFileInfo> 
    1213#include <QDomDocument> 
    1314#include <QTextStream> 
     
    2324#define TS_ELEMENT_SOURCE             "source" 
    2425#define TS_ELEMENT_TRANSLATION        "translation" 
     26#define TS_ELEMENT_LOCATION           "location" 
     27#define TS_ATTR_FILENAME              "filename" 
     28#define TS_ATTR_LINE                  "line" 
    2529 
    2630 
     
    4145  QString tstamp = create_po_timestamp(); 
    4246 
    43   header.append("#,fuzzy\n"); 
    4447  header.append("msgid \"\"\n"); 
    4548  header.append("msgstr \"\"\n"); 
     
    6164} 
    6265 
     66/** Parse the filename from the relative or absolute path given in 
     67 * <b>filePath</b>. */ 
     68QString 
     69parse_filename(const QString &filePath) 
     70{ 
     71  QFileInfo file(filePath); 
     72  return file.fileName(); 
     73} 
     74 
    6375/** Convert the messages in <b>context</b> to PO format. The output will be 
    6476 * appended to <b>po</b>. Returns the number of source messages converted on 
     
    6779convert_context(const QDomElement &context, QString *po, QString *errorMessage) 
    6880{ 
    69   QString msgid, msgstr; 
     81  QString msgctxt, msgid, msgstr; 
     82  QString filename, line; 
    7083  QDomElement location, source, translation; 
    7184  int n = 0; 
     
    8093    return -1; 
    8194  } 
     95  msgctxt = name.text(); 
    8296 
    8397  QDomElement msg = context.firstChildElement(TS_ELEMENT_MESSAGE); 
     
    102116    msgstr.replace("\n", "\"\n\""); 
    103117   
     118    /* Try to extract the <location> tags (optional) */ 
     119    location = msg.firstChildElement(TS_ELEMENT_LOCATION); 
     120    filename = parse_filename(location.attribute(TS_ATTR_FILENAME)); 
     121    line = location.attribute(TS_ATTR_LINE); 
     122 
    104123    /* Format the .po entry for this string */ 
    105     (*po).append(QString("#: %1#%2\n").arg(name.text()).arg(++n)); 
     124    if (!filename.isEmpty() && !line.isEmpty()) 
     125      (*po).append(QString("#: %1:%2\n").arg(filename).arg(line)); 
     126    (*po).append(QString("msgctxt \"%1\"\n").arg(msgctxt)); 
    106127    (*po).append(QString("msgid \"%1\"\n").arg(msgid)); 
    107128    (*po).append(QString("msgstr \"%1\"\n").arg(msgstr)); 
     
    110131    /* Find the next source message in the current context */ 
    111132    msg = msg.nextSiblingElement(TS_ELEMENT_MESSAGE); 
     133    n++; 
    112134  } 
    113135  return n;