本文整理汇总了C++中Translator类的典型用法代码示例。如果您正苦于以下问题:C++ Translator类的具体用法?C++ Translator怎么用?C++ Translator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Translator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sManager
// SessionManager must be read-locked
Call::Call(SessionManager *_sManager, unsigned int _id, unsigned int _client, unsigned int _translator, string lang)
: sManager(_sManager),
id(_id),
client(_client),
translator(_translator),
state(INIT),
start_time(0), end_time(0), accounted(0),
cost(0),
price(0),
client_balance(0)
{
pthread_mutex_init(&mutex, 0);
Session *cs = sManager->findSessionByUser(_client);
if (!cs)
throw logic_error("Client session not found.");
if (!dynamic_cast<Client *>(cs->getUser()) ||
(!TRANSLATORS_CALL && dynamic_cast<Translator *>(cs->getUser())))
throw logic_error("Client not found.");
Client *c = dynamic_cast<Client *>(cs->getUser());
clientName = c->getName();
Session *ts = sManager->findSessionByUser(_translator);
if (!ts)
throw logic_error("Translator session not found.");
Translator *t = dynamic_cast<Translator *>(ts->getUser());
if (!t)
throw logic_error("Translator not found.");
setTranslateLang(lang);
setClientLang(t->getCommonLang(c));
price = t->getClientPrice(c, lang);
translatorName = t->getName();
}
开发者ID:raschupkin,项目名称:TranslateNet,代码行数:32,代码来源:Call.cpp
示例2: releaseTranslator
static bool releaseTranslator(Translator &tor, const QString &qmFileName,
ConversionData &cd, bool removeIdentical)
{
tor.reportDuplicates(tor.resolveDuplicates(), qmFileName, cd.isVerbose());
if (cd.isVerbose())
printOut(LR::tr("Updating '%1'...\n").arg(qmFileName));
if (removeIdentical) {
if (cd.isVerbose())
printOut(LR::tr("Removing translations equal to source text in '%1'...\n").arg(qmFileName));
tor.stripIdenticalSourceTranslations();
}
QFile file(qmFileName);
if (!file.open(QIODevice::WriteOnly)) {
printErr(LR::tr("lrelease error: cannot create '%1': %2\n")
.arg(qmFileName, file.errorString()));
return false;
}
tor.normalizeTranslations(cd);
bool ok = saveQM(tor, file, cd);
file.close();
if (!ok) {
printErr(LR::tr("lrelease error: cannot save '%1': %2")
.arg(qmFileName, cd.error()));
} else if (!cd.errors().isEmpty()) {
printOut(cd.error());
}
cd.clearErrors();
return ok;
}
开发者ID:KDE,项目名称:android-qt,代码行数:33,代码来源:main.cpp
示例3: QLatin1String
bool DataModel::load(const QString &fileName, bool *langGuessed, QWidget *parent)
{
Translator tor;
ConversionData cd;
bool ok = tor.load(fileName, cd, QLatin1String("auto"));
if (!ok) {
QMessageBox::warning(parent, QObject::tr("Qt Linguist"), cd.error());
return false;
}
Translator::Duplicates dupes = tor.resolveDuplicates();
if (!dupes.byId.isEmpty() || !dupes.byContents.isEmpty()) {
QString err = tr("<qt>Duplicate messages found in '%1':").arg(Qt::escape(fileName));
int numdups = 0;
foreach (int i, dupes.byId) {
if (++numdups >= 5) {
err += tr("<p>[more duplicates omitted]");
goto doWarn;
}
err += tr("<p>* ID: %1").arg(Qt::escape(tor.message(i).id()));
}
foreach (int j, dupes.byContents) {
const TranslatorMessage &msg = tor.message(j);
if (++numdups >= 5) {
err += tr("<p>[more duplicates omitted]");
break;
}
err += tr("<p>* Context: %1<br>* Source: %2")
.arg(Qt::escape(msg.context()), Qt::escape(msg.sourceText()));
if (!msg.comment().isEmpty())
err += tr("<br>* Comment: %3").arg(Qt::escape(msg.comment()));
}
doWarn:
QMessageBox::warning(parent, QObject::tr("Qt Linguist"), err);
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:35,代码来源:messagemodel.cpp
示例4: saveQPH
static bool saveQPH(const Translator &translator, QIODevice &dev, ConversionData &)
{
QTextStream t(&dev);
t.setCodec(QTextCodec::codecForName("UTF-8"));
t << "<!DOCTYPE QPH>\n<QPH";
QString languageCode = translator.languageCode();
if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
t << " language=\"" << languageCode << "\"";
languageCode = translator.sourceLanguageCode();
if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
t << " sourcelanguage=\"" << languageCode << "\"";
t << ">\n";
foreach (const TranslatorMessage &msg, translator.messages()) {
t << "<phrase>\n";
t << " <source>" << protect(msg.sourceText()) << "</source>\n";
QString str = msg.translations().join(QLatin1String("@"));
str.replace(QChar(Translator::BinaryVariantSeparator),
QChar(Translator::TextVariantSeparator));
t << " <target>" << protect(str)
<< "</target>\n";
if (!msg.comment().isEmpty())
t << " <definition>" << protect(msg.comment()) << "</definition>\n";
t << "</phrase>\n";
}
t << "</QPH>\n";
return true;
}
开发者ID:mohdpatah,项目名称:qt,代码行数:27,代码来源:qph.cpp
示例5: intersection
Translator Translator::intersection(const Translator &first, const Translator &second){
multimap <string, string> fst_dict = first.dictionary, snd_dict = second.dictionary;
multimap <string, string>::iterator fst_it = fst_dict.begin(),
fst_end = fst_dict.end(), snd_it, snd_curr_key, snd_end = snd_dict.end(),
fst_stop, snd_stop;
pair <multimap <string, string>::iterator, multimap<string, string>::iterator> key_range;
string origin, mid;
set <string> curr_translations;
Word curr_entry;
Translator intersection;
while(fst_it != fst_end){
origin = fst_it->first;
snd_curr_key = snd_dict.find(origin);
fst_stop = fst_dict.upper_bound(origin);
if(snd_curr_key != snd_end){ // the key is on the second translator too
curr_translations.clear(); // empty the translations for this key
snd_stop = snd_dict.upper_bound(origin);
for(; fst_it != fst_stop; ++fst_it){ // iterate over the A->B translations
for(snd_it = snd_curr_key; snd_it != snd_stop; ++snd_it){ // iterate over the C->B
if(fst_it->second == snd_it->second){ // translations match
curr_translations.insert(fst_it->second);
}
}
}
if(not curr_translations.empty()){
curr_entry = Word(origin, curr_translations);
intersection.addEntry(curr_entry);
}
}
fst_it = fst_stop;
}
return intersection;
}
开发者ID:cronos2,项目名称:Translator,代码行数:58,代码来源:Translator.cpp
示例6: main
int main(int argc, char** argv) {
string impl = "printer";
const char* script = NULL;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-j") {
impl = "jit";
} else {
script = argv[i];
}
}
Translator* translator = Translator::create(impl);
if (translator == 0) {
cout << "TODO: Implement translator factory in translator.cpp!!!!" << endl;
return 1;
}
const char* expr = "double x; double y;"
"x += 8.0; y = 2.0;"
"print('Hello, x=',x,' y=',y,'\n');"
;
bool isDefaultExpr = true;
if (script != NULL) {
expr = loadFile(script);
if (expr == 0) {
printf("Cannot read file: %s\n", script);
return 1;
}
isDefaultExpr = false;
}
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
printf("Cannot translate expression: expression at %d,%d; "
"error '%s'\n",
line, offset,
translateStatus->getError().c_str());
}
if (code != NULL) {
delete code;
}
delete translateStatus;
delete translator;
if (!isDefaultExpr) {
delete [] expr;
}
return 0;
}
开发者ID:kamanov,项目名称:Shared,代码行数:58,代码来源:main.cpp
示例7: main
int main(int argc, char** argv) {
const char* script = 0;
std::string mode = INTERPRETE;
for (int32_t i = 1; i < argc; i++) {
if (string(argv[i]) == "-d") {
mode = DISASM;
} else if (string(argv[i]) == "-j") {
mode = JIT;
} else {
script = argv[i];
}
}
if (script == 0) {
cout << "Usage: interpreter [-d | -j] <source_file>" << endl;
return WRONG_ARG_COUNT;
}
const char* expr = loadFile(script);
if (expr == 0) {
cout << "Cannot read file: " << script << endl;
return CANNOT_READ_SOURCE;
}
Translator* translator = new BytecodeTranslatorImpl();
Code* code = 0;
Status* translateStatus = translator->translate(expr, &code);
if (translateStatus == 0) {
//todo
} else if (translateStatus->isError()) {
uint32_t position = translateStatus->getPosition();
uint32_t line = 0, offset = 0;
positionToLineOffset(expr, position, line, offset);
cout << "Cannot translate expression: expression at " << line << ", " << offset << "; "
<< "error '" << translateStatus->getError().c_str() << "'" << endl;
} else {
assert(code != 0);
if (mode == DISASM) {
code->disassemble(cout);
} else if (mode == JIT) {
} else {
vector<Var*> t;
code->execute(t);
}
delete code;
}
delete translateStatus;
delete translator;
return 0;
}
开发者ID:nvmd,项目名称:spbau-mathvm,代码行数:56,代码来源:main.cpp
示例8: mainM
int mainM()
{
Player *p1 = new Center("李俊宏");
p1->attack();
p1->defence();
Translator *tl = new Translator("姚明");
tl->attack();
tl->defence();
cin.get();
return 0;
}
开发者ID:zhoajianjun,项目名称:docs,代码行数:12,代码来源:16适配器模式.cpp
示例9: tr
void MainWindow::on_convertPushButton_clicked()
{
if (_to==_from)
{
QMessageBox::warning(this, tr("Coptic Font Converter"),
tr("Please select different source and destination fonts."),
QMessageBox::Ok);
return;
}
QString text= ui->inputTextEdit->toPlainText();
QString unicodeText;
if (_from != UNICODE)
{
Translator transFrom;
switch(_from)
{
case CS:
{
transFrom.Load("/Developer/cs.csv");
}
break;
default:
QMessageBox::warning(this, tr("Coptic Font Converter"),
tr("Selected source font is not yet supported."),
QMessageBox::Ok);
return;
}
//if (transFrom == NULL)
// QMessageBox::warning(this, tr("Coptic Font Converter"),
// tr("Error creating source translator."),
// QMessageBox::Ok);
unicodeText = transFrom.ToUnicode(text);
}
QString destText;
if(_to != UNICODE)
{
//convert from unicode
}
else
destText = unicodeText;
ui->outputTextEdit->setText(destText);
ui->outputTextEdit->selectAll();
ui->outputTextEdit->setFont( QFont("FreeSerifAvvaShenouda",22));
}
开发者ID:jonathanslote,项目名称:psalmody,代码行数:52,代码来源:mainwindow.cpp
示例10: createStandardContextMenu
void TwitterWidgetItemMessage::contextMenuEvent(QContextMenuEvent *event) {
QMenu *menu = createStandardContextMenu(event->pos());
menu->addMenu(languagesMenu);
Translator *translator = Translator::getInstance();
QAction *action = menu->exec(event->globalPos());
if (actionLanguage.find(action) != actionLanguage.end()) {
if (actionLanguage[action] == "-") {
setHtml(QwitTools::prepareMessage(message.text, message.account));
} else {
translator->translate(message.text, actionLanguage[action], this);
}
}
delete menu;
}
开发者ID:artikz,项目名称:qwit,代码行数:14,代码来源:TwitterWidgetItemMessage.cpp
示例11: traverse
// Recursively traverse an eZ Publish directory
static void traverse( const QDir &dir, Translator &fetchedTor, ConversionData cd, UpdateOptions options, bool *fail )
{
if ( options & Verbose )
printOut( QObject::tr( " Checking subdirectory '%1'" ).arg( qPrintable(dir.path()) ) );
if ( !dir.exists() )
return;
const QFileInfoList list = dir.entryInfoList();
QFileInfo fi;
for ( int i = 0; i < list.size(); ++i )
{
fi = list.at( i );
if ( fi.fileName().startsWith( "." ) )
{
// Do nothing
}
else if ( fi.isDir() )
{
QDir subdir = dir;
subdir.setCurrent( subdir.path() + QDir::separator() + fi.fileName() );
traverse( subdir.currentPath(), fetchedTor, cd, options, fail );
subdir.setCurrent( dir.path() );
}
else
{
if ( fi.fileName().endsWith(QLatin1String(".php"), Qt::CaseInsensitive) )
{
if ( options & Verbose )
printOut( QObject::tr( " Checking '%1'" ).arg( qPrintable(fi.fileName()) ) );
if ( !fetchedTor.load(fi.fileName(), cd, QLatin1String("php")) )
{
qWarning( "%s", qPrintable( cd.error() ) );
*fail = true;
}
}
else if ( fi.fileName().endsWith(QLatin1String(".tpl"), Qt::CaseInsensitive) )
{
if ( options & Verbose )
printOut( QObject::tr( " Checking '%1'" ).arg( qPrintable(fi.fileName()) ) );
if ( !fetchedTor.load(fi.fileName(), cd, QLatin1String("tpl")) )
{
qWarning( "%s", qPrintable( cd.error() ) );
*fail = true;
}
}
}
}
}
开发者ID:,项目名称:,代码行数:50,代码来源:
示例12: updateTsFiles
static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames,
const QStringList &alienFiles,
const QString &sourceLanguage, const QString &targetLanguage,
UpdateOptions options, bool *fail)
{
QList<Translator> aliens;
foreach (const QString &fileName, alienFiles) {
ConversionData cd;
Translator tor;
if (!tor.load(fileName, cd, QLatin1String("auto"))) {
printErr(cd.error());
*fail = true;
continue;
}
tor.resolveDuplicates();
aliens << tor;
}
开发者ID:FlavioFalcao,项目名称:qt5,代码行数:17,代码来源:main.cpp
示例13: while
bool QPHReader::read(Translator &translator)
{
m_currentField = NoField;
QString result;
while (!atEnd()) {
readNext();
if (isStartElement()) {
if (name() == QLatin1String("source")) {
m_currentField = SourceField;
} else if (name() == QLatin1String("target")) {
m_currentField = TargetField;
} else if (name() == QLatin1String("definition")) {
m_currentField = DefinitionField;
} else {
m_currentField = NoField;
if (name() == QLatin1String("QPH")) {
QXmlStreamAttributes atts = attributes();
translator.setLanguageCode(atts.value(QLatin1String("language")).toString());
translator.setSourceLanguageCode(atts.value(QLatin1String("sourcelanguage")).toString());
}
}
} else if (isWhiteSpace()) {
// ignore these
} else if (isCharacters()) {
if (m_currentField == SourceField)
m_currentSource += text();
else if (m_currentField == TargetField)
m_currentTarget += text();
else if (m_currentField == DefinitionField)
m_currentDefinition += text();
} else if (isEndElement() && name() == QLatin1String("phrase")) {
m_currentTarget.replace(QChar(Translator::TextVariantSeparator),
QChar(Translator::BinaryVariantSeparator));
TranslatorMessage msg;
msg.setSourceText(m_currentSource);
msg.setTranslation(m_currentTarget);
msg.setComment(m_currentDefinition);
translator.append(msg);
m_currentSource.clear();
m_currentTarget.clear();
m_currentDefinition.clear();
}
}
return true;
}
开发者ID:mohdpatah,项目名称:qt,代码行数:45,代码来源:qph.cpp
示例14: loadSettings
void DialogOptions::loadSettings()
{
if (!settings->contains("Options/Overwrite mode"))
radioAskFirst->setChecked(true);
else {
if (settings->value("Options/Overwrite mode").toBool())
radioOverwrite->setChecked(true);
else
radioAskFirst->setChecked(true);
}
Translator t;
qDebug() << "Lingua corrente " << t.currentLanguage();
int idx = comboLangs->findText(t.currentLanguage(), Qt::MatchExactly);
comboLangs->setCurrentIndex(idx);
}
开发者ID:lukeandrew,项目名称:Converseen,代码行数:18,代码来源:dialogoptions.cpp
示例15: setLanguage
void DialogOptions::setLanguage()
{
Translator t;
QString lang;
if (comboLangs->currentText() == "English")
lang = "English";
else
lang = t.loadTranslationFiles()
.at(comboLangs->currentIndex())
.first;
if (lang != t.loadCurrentTranslationName()) {
t.saveSettings(lang);
QMessageBox::warning(0, tr("Warning!"),
tr("Please, restart Converseen to apply current language!"));
}
}
开发者ID:lukeandrew,项目名称:Converseen,代码行数:19,代码来源:dialogoptions.cpp
示例16: compose
Translator Translator::compose(const Translator &first, const Translator &second){
multimap <string, string> fst_dict = first.dictionary, snd_dict = second.dictionary;
multimap <string, string>::iterator fst_it = fst_dict.begin(),
fst_end = fst_dict.end(), snd_it, stop;
pair <multimap <string, string>::iterator, multimap<string, string>::iterator> key_range;
string origin, mid;
set <string> curr_translations;
Word curr_entry;
Translator composition;
while(fst_it != fst_end){
origin = fst_it->first;
stop = fst_dict.upper_bound(origin);
curr_translations.clear(); // empty the translations for this key
for(; fst_it != stop; ++fst_it){
mid = fst_it->second;
key_range = snd_dict.equal_range(mid);
for(snd_it = key_range.first; snd_it != key_range.second; ++snd_it){
curr_translations.insert(snd_it->second);
}
}
curr_entry = Word(origin, curr_translations);
composition.addEntry(curr_entry);
}
return composition;
}
开发者ID:cronos2,项目名称:Translator,代码行数:41,代码来源:Translator.cpp
示例17: loadTsFile
static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbose */)
{
ConversionData cd;
bool ok = tor.load(tsFileName, cd, QLatin1String("auto"));
if (!ok) {
qWarning("lrelease error: %s\n", qPrintable(cd.error()));
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
}
return ok;
}
开发者ID:Fale,项目名称:qtmoko,代码行数:12,代码来源:main.cpp
示例18: loadTsFile
static bool loadTsFile(Translator &tor, const QString &tsFileName, bool /* verbose */)
{
ConversionData cd;
bool ok = tor.load(tsFileName, cd, QLatin1String("auto"));
if (!ok) {
printErr(LR::tr("lrelease error: %1").arg(cd.error()));
} else {
if (!cd.errors().isEmpty())
printOut(cd.error());
}
cd.clearErrors();
return ok;
}
开发者ID:KDE,项目名称:android-qt,代码行数:13,代码来源:main.cpp
示例19: loadJava
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
cd.appendError(QString::fromLatin1("Cannot open %1: %2")
.arg(filename, file.errorString()));
return false;
}
yyDefaultContext = cd.m_defaultContext;
yyInPos = -1;
yyFileName = filename;
yyPackage.clear();
yyScope.clear();
yyTok = -1;
yyParenDepth = 0;
yyCurLineNo = 0;
yyParenLineNo = 1;
QTextStream ts(&file);
QByteArray codecName;
if (!cd.m_codecForSource.isEmpty())
codecName = cd.m_codecForSource;
else
codecName = translator.codecName(); // Just because it should be latin1 already
ts.setCodec(QTextCodec::codecForName(codecName));
ts.setAutoDetectUnicode(true);
yyInStr = ts.readAll();
yyInPos = 0;
yyFileName = filename;
yyCurLineNo = 1;
yyParenLineNo = 1;
parse(&translator);
// Java uses UTF-16 internally and Jambi makes UTF-8 for tr() purposes of it.
translator.setCodecName("UTF-8");
return true;
}
开发者ID:Mr-Kumar-Abhishek,项目名称:qt,代码行数:39,代码来源:java.cpp
示例20: releaseTranslator
static bool releaseTranslator(Translator &tor, const QString &qmFileName,
bool verbose, bool ignoreUnfinished,
bool removeIdentical, TranslatorSaveMode mode)
{
Translator::reportDuplicates(tor.resolveDuplicates(), qmFileName, verbose);
if (verbose)
printOut(QCoreApplication::tr( "Updating '%1'...\n").arg(qmFileName));
if (removeIdentical) {
if ( verbose )
printOut(QCoreApplication::tr( "Removing translations equal to source text in '%1'...\n").arg(qmFileName));
tor.stripIdenticalSourceTranslations();
}
QFile file(qmFileName);
if (!file.open(QIODevice::WriteOnly)) {
qWarning("lrelease error: cannot create '%s': %s\n",
qPrintable(qmFileName), qPrintable(file.errorString()));
return false;
}
ConversionData cd;
tor.normalizeTranslations(cd);
cd.m_verbose = verbose;
cd.m_ignoreUnfinished = ignoreUnfinished;
cd.m_saveMode = mode;
bool ok = tor.release(&file, cd);
file.close();
if (!ok) {
qWarning("lrelease error: cannot save '%s': %s\n",
qPrintable(qmFileName), qPrintable(cd.error()));
return false;
} else if (!cd.errors().isEmpty()) {
printOut(cd.error());
}
return true;
}
开发者ID:,项目名称:,代码行数:38,代码来源:
注:本文中的Translator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论