本文整理汇总了C++中QLocale::name方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::name方法的具体用法?C++ QLocale::name怎么用?C++ QLocale::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_system_locale
QLocale get_system_locale(void)
{
QLocale locale = QLocale::system();
#ifdef Q_OS_UNIX
// Qt's locale detection under UNIX works wrong -->
{
QMap<QString,QString> env_vars;
Q_FOREACH(const QString& var, QProcess::systemEnvironment())
{
int pos = var.indexOf('=');
QString name = var.mid(0, pos);
QString value = var.mid(pos + 1);
env_vars[name] = value;
MLIB_DV("Gotten an environment variable: '%1'='%2'.", name, value);
}
if(!env_vars["LC_ALL"].isEmpty())
{
locale = QLocale(env_vars["LC_ALL"]);
MLIB_D("Setting the locale to LC_ALL's value '%1'.", locale.name());
}
else if(!env_vars["LC_MESSAGES"].isEmpty())
{
locale = QLocale(env_vars["LC_MESSAGES"]);
MLIB_D("Setting the locale to LC_MESSAGES's value '%1'.", locale.name());
}
else if(!env_vars["LANG"].isEmpty())
{
locale = QLocale(env_vars["LANG"]);
MLIB_D("Setting the locale to LANG's value '%1'.", locale.name());
}
}
示例2: Init
void MythLocale::Init(const QString &localeName)
{
QString dbLanguage = GetMythDB()->GetSetting("Language", "");
QString dbCountry = GetMythDB()->GetSetting("Country", "");
if (!localeName.isEmpty())
{
m_localeCode = localeName;
}
else if (!dbLanguage.isEmpty() &&
!dbCountry.isEmpty())
{
QString langcode = dbLanguage.section('_',0,0);
m_localeCode = QString("%1_%2").arg(langcode)
.arg(dbCountry.toUpper());
}
else
{
QLocale locale = QLocale::system();
if (locale.name().isEmpty() || locale.name() == "C")
{
// If all else has failed use the US locale
m_localeCode = "en_US";
}
else
m_localeCode = locale.name();
}
m_qtLocale = QLocale(m_localeCode);
}
示例3: locale
widgetLocale::widgetLocale(QWidget *parent) : QWidget(parent), ui(new Ui::widgetLocale)
{
//Initialize the Interface
ui->setupUi(this);
//Connect the signals/slots
connect(ui->pushCancel, SIGNAL(clicked()), this, SLOT(slotClose()) );
connect(ui->pushApply, SIGNAL(clicked()), this, SLOT(slotApply()) );
//Get all the available languages
locCodeL = getLanguages(); //get language codes
locL.clear();
for(int i=0; i<locCodeL.length(); i++){
QLocale locale(locCodeL[i]);
locL << QLocale::languageToString(locale.language());
}
//Get the current language
QLocale mylocale = QLocale::system();
initLocale = mylocale.name(); //save this for later
QString cLocale = QLocale::languageToString(mylocale.language()) + " ("+mylocale.name()+")";
//qDebug() << "Default Locale:" << cLocale;
//Setup the interface
ui->lineCurrentLocale->setText(cLocale); //current language
for(int i=0; i< locL.length(); i++){
ui->localeListWidget->addItem(locL[i] + " ("+locCodeL[i]+")"); //Available languages
}
ui->localeListWidget->sortItems(); //Sort them by translated name
}
示例4: langDir
LanguageManager::LanguageManager()
{
// lookup qm files under the :/lang dir
QDir langDir( QmDirPath );
for ( QListIterator<QFileInfo> it( langDir.entryInfoList(
QStringList() << QmTemplate.arg( QmInfoPrefix ), QDir::Files | QDir::CaseSensitive ) ); it.hasNext(); )
{
const QFileInfo qmFileInfo = it.next();
QString moduleName;
QString suffix;
if ( !_splitFileName( qmFileInfo.completeBaseName(), &moduleName, &suffix ) )
continue;
Q_ASSERT( moduleName == QmInfoPrefix );
Q_ASSERT( !languageInfoForName_.contains( suffix ) );
QTranslator * infoTranslator = new QTranslator( this );
if ( !infoTranslator->load( qmFileInfo.filePath() ) )
{
delete infoTranslator;
continue;
}
LanguageInfo languageInfo;
languageInfo.isNull = false;
languageInfo.name = suffix;
languageInfo.englishName = infoTranslator->translate( "LanguageManager", LanguageNameInEnglish );
languageInfo.nativeName = infoTranslator->translate( "LanguageManager", LanguageNameInNative );
languageInfoForName_[ languageInfo.name ] = languageInfo;
names_ << languageInfo.name;
}
QString defaultName;
const QLocale currentLocale;
if ( languageInfoForName_.contains( currentLocale.name() ) )
{
defaultName = currentLocale.name();
}
else
{
const QString localeLangName = currentLocale.name().left( currentLocale.name().indexOf( QLatin1Char( '_' ) ) );
if ( languageInfoForName_.contains( localeLangName ) )
{
defaultName = localeLangName;
}
else
{
if ( languageInfoForName_.contains( DefaultLanguageName ) )
defaultName = DefaultLanguageName;
}
}
if ( !defaultName.isNull() )
setCurrentName( defaultName );
}
示例5: QApplication
// Constructor.
qsynthApplication(int& argc, char **argv) : QApplication(argc, argv),
m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)
{
// Load translation support.
QLocale loc;
if (loc.language() != QLocale::C) {
// Try own Qt translation...
m_pQtTranslator = new QTranslator(this);
QString sLocName = "qt_" + loc.name();
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (m_pQtTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pQtTranslator);
} else {
delete m_pQtTranslator;
m_pQtTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toLocal8Bit().data(),
sLocPath.toLocal8Bit().data(),
sLocName.toLocal8Bit().data());
#endif
}
// Try own application translation...
m_pMyTranslator = new QTranslator(this);
sLocName = "qsynth_" + loc.name();
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
sLocPath = CONFIG_DATADIR "/qsynth/translations";
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
delete m_pMyTranslator;
m_pMyTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toLocal8Bit().data(),
sLocPath.toLocal8Bit().data(),
sLocName.toLocal8Bit().data());
#endif
}
}
}
#ifdef CONFIG_X11
#ifdef CONFIG_XUNIQUE
// Instance uniqueness initialization...
m_pDisplay = QX11Info::display();
m_aUnique = XInternAtom(m_pDisplay, QSYNTH_XUNIQUE, false);
XGrabServer(m_pDisplay);
m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
XUngrabServer(m_pDisplay);
#if QT_VERSION >= 0x050100
m_pXcbEventFilter = new qsynthXcbEventFilter(this);
installNativeEventFilter(m_pXcbEventFilter);
#endif
#endif // CONFIG_XUNIQUE
#endif // CONFIG_X11
}
示例6: QWidget
GreetingPage::GreetingPage( QWidget* parent )
: QWidget( parent )
, ui( new Ui::GreetingPage )
{
ui->setupUi( this );
QString defaultLocale = QLocale::system().name();
{
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
{
QLocale thisLocale = QLocale( locale );
QString lang = QLocale::languageToString( thisLocale.language() );
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
lang.append( QString( " (%1)" )
.arg( QLocale::countryToString( thisLocale.country() ) ) );
ui->languageWidget->addItem( lang );
ui->languageWidget->item( ui->languageWidget->count() - 1 )
->setData( Qt::UserRole, thisLocale );
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
thisLocale.country() == QLocale( defaultLocale ).country() )
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
}
ui->languageWidget->sortItems();
connect( ui->languageWidget, &QListWidget::currentItemChanged,
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
{
QLocale selectedLocale = current->data( Qt::UserRole ).toLocale();
cDebug() << "Selected locale" << selectedLocale.name();
QLocale::setDefault( selectedLocale );
CalamaresUtils::installTranslator( selectedLocale.name(), qApp );
} );
connect( ui->languageWidget, &QListWidget::itemDoubleClicked,
this, []
{
Calamares::ViewManager::instance()->next();
} );
}
ui->mainText->setAlignment( Qt::AlignCenter );
ui->mainText->setWordWrap( true );
ui->mainText->setOpenExternalLinks( true );
CALAMARES_RETRANSLATE(
ui->mainText->setText( tr( "<h1>Welcome to the %1 installer.</h1><br/>"
"This program will ask you some questions and "
"set up %2 on your computer." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::VersionedName ) )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ProductName ) ) );
)
示例7: QApplication
// Constructor.
qjackctlApplication(int& argc, char **argv) : QApplication(argc, argv),
m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)
{
// Load translation support.
QLocale loc;
if (loc.language() != QLocale::C) {
// Try own Qt translation...
m_pQtTranslator = new QTranslator(this);
QString sLocName = "qt_" + loc.name();
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (m_pQtTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pQtTranslator);
} else {
delete m_pQtTranslator;
m_pQtTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toUtf8().constData(),
sLocPath.toUtf8().constData(),
sLocName.toUtf8().constData());
#endif
}
// Try own application translation...
m_pMyTranslator = new QTranslator(this);
sLocName = "qjackctl_" + loc.name();
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
sLocPath = CONFIG_DATADIR "/qjackctl/translations";
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
delete m_pMyTranslator;
m_pMyTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toUtf8().constData(),
sLocPath.toUtf8().constData(),
sLocName.toUtf8().constData());
#endif
}
}
}
#ifdef CONFIG_X11
#ifdef CONFIG_XUNIQUE
m_pDisplay = NULL;
m_wOwner = None;
#if QT_VERSION >= 0x050100
m_pXcbEventFilter = new qjackctlXcbEventFilter(this);
installNativeEventFilter(m_pXcbEventFilter);
#endif
#endif // CONFIG_XUNIQUE
#endif // CONFIG_X11
}
示例8: slotChangeLocale
void PCDMgui::slotChangeLocale(){
//Open the selector
wLoc = new widgetLocale();
QLocale currLocale = this->locale();
Backend::log("Current PCDM Locale: " + currLocale.name() );
wLoc->setCurrentLocale(currLocale.name());
wLoc->setWindowModality(Qt::ApplicationModal);
wLoc->show();
wLoc->raise();
//Connect the language changed signal
connect(wLoc,SIGNAL(languageChanged(QString)),this,SLOT(slotLocaleChanged(QString)) );
}
示例9: QApplication
// Constructor.
qsamplerApplication(int& argc, char **argv) : QApplication(argc, argv),
m_pQtTranslator(0), m_pMyTranslator(0), m_pWidget(0)
{
// Load translation support.
QLocale loc;
if (loc.language() != QLocale::C) {
// Try own Qt translation...
m_pQtTranslator = new QTranslator(this);
QString sLocName = "qt_" + loc.name();
QString sLocPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (m_pQtTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pQtTranslator);
} else {
delete m_pQtTranslator;
m_pQtTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toUtf8().constData(),
sLocPath.toUtf8().constData(),
sLocName.toUtf8().constData());
#endif
}
// Try own application translation...
m_pMyTranslator = new QTranslator(this);
sLocName = "qsampler_" + loc.name();
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
sLocPath = CONFIG_PREFIX "/share/locale";
if (m_pMyTranslator->load(sLocName, sLocPath)) {
QApplication::installTranslator(m_pMyTranslator);
} else {
delete m_pMyTranslator;
m_pMyTranslator = 0;
#ifdef CONFIG_DEBUG
qWarning("Warning: no translation found for '%s' locale: %s/%s.qm",
loc.name().toUtf8().constData(),
sLocPath.toUtf8().constData(),
sLocName.toUtf8().constData());
#endif
}
}
}
#if defined(Q_WS_X11)
m_pDisplay = QX11Info::display();
m_aUnique = XInternAtom(m_pDisplay, QSAMPLER_XUNIQUE, false);
XGrabServer(m_pDisplay);
m_wOwner = XGetSelectionOwner(m_pDisplay, m_aUnique);
XUngrabServer(m_pDisplay);
#endif
}
示例10: load
static void load()
{
// The way Qt translation system handles plural forms makes it necessary to
// have a translation file which contains only plural forms for `en`. That's
// why we load the `en` translation unconditionally, then load the
// translation for the current locale to overload it.
loadTranslation(QStringLiteral("en"));
QLocale locale = QLocale::system();
if (locale.name() != QStringLiteral("en")) {
if (!loadTranslation(locale.name())) {
loadTranslation(locale.bcp47Name());
}
}
}
示例11: main
int main(int argc, char ** argv)
{
QStringList in;
for(int i=1; i<argc; i++){ //skip the first arg (app binary)
in << QString(argv[i]);
}
if(in.isEmpty()){ in << QDir::homePath(); }
#ifdef __linux
QApplication a(argc, argv);
#else
QtSingleApplication a(argc, argv);
if( a.isRunning() ){
return !(a.sendMessage(in.join("\n")));
}
#endif
QTranslator translator;
QLocale mylocale;
QString langCode = mylocale.name();
if ( ! QFile::exists(PREFIX + "/share/Lumina-DE/i18n/lumina-config_" + langCode + ".qm" ) ) langCode.truncate(langCode.indexOf("_"));
translator.load( QString("lumina-config_") + langCode, PREFIX + "/share/i18n/Lumina-DE/" );
a.installTranslator( &translator );
qDebug() << "Locale:" << langCode;
MainUI w;
QObject::connect(&a, SIGNAL(messageReceived(const QString&)), &w, SLOT(slotSingleInstance(const QString&)) );
w.OpenDirs(in);
w.show();
int retCode = a.exec();
return retCode;
}
示例12: QDialog
SpellCheckSelectorDialog::SpellCheckSelectorDialog(QWidget *parent, Qt::WindowFlags f) :
QDialog(parent, f),
ui(std::make_shared<Ui::SpellCheckSelectorDialog>())
{
ui->setupUi(this);
auto conf = Configuration::getInstance();
auto sl = conf->getAllAvailableSpellCheckDictNames();
int index = -1;
QLocale locale;
for(int i=0; i<sl.length(); i++){
QString dictName = sl.at(i);
if(dictName=="en_GB"){
ui->languageComboBox->addItem("English - United Kingdom", dictName);
} else if(dictName=="en_US"){
ui->languageComboBox->addItem("English - United States", dictName);
} else {
ui->languageComboBox->addItem(dictName, dictName);
}
if(dictName==locale.name())
index = i;
}
if(index==-1 && sl.length()>=1){
ui->languageComboBox->setCurrentIndex(0);
}
connect(ui->buttonBox, SIGNAL(rejected()),
this, SLOT(close()));
connect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(acceptSlot()));
}
示例13: main
int main(int argc, char ** argv)
{
PCSingleApplication a(argc, argv);
if(!a.isPrimaryProcess()){ return 0; }
//Check for root
if (0 != getuid())
{
QMessageBox msg;
msg.setText(QObject::tr("This application requires administrator privileges for operation."));
msg.exec();
exit(2);
}
QTranslator translator;
QLocale mylocale;
QString langCode = mylocale.name();
if ( ! QFile::exists(PREFIX + "/share/pcbsd/i18n/pc-bootconfig_" + langCode + ".qm" ) ) langCode.truncate(langCode.indexOf("_"));
translator.load( QString("pc-bootconfig_") + langCode, PREFIX + "/share/pcbsd/i18n/" );
a.installTranslator( &translator );
qDebug() << "Locale:" << langCode;
QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") ); //Force Utf-8 compliance
mainUI w;
QObject::connect(&a, SIGNAL(InputsAvailable(QStringList)), &w, SLOT(slotSingleInstance()) );
w.show();
int retCode = a.exec();
return retCode;
}
示例14: main
int main( int argc, char ** argv )
{
QApplication a(argc, argv);
QTranslator translator;
QLocale mylocale;
QString langCode = mylocale.name();
if ( ! QFile::exists( PREFIX + "/share/pcbsd/i18n/PBSystem_" + langCode + ".qm" ) )
langCode.truncate(langCode.indexOf("_"));
translator.load( QString("PBSystem_") + langCode, PREFIX + "/share/pcbsd/i18n/" );
a.installTranslator( &translator );
qDebug() << "Locale:" << langCode;
QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") ); //Force Utf-8 compliance
// Make sure we are running as root
if (getuid() != 0) {
qDebug("Error, needs to be run as root");
exit(1);
}
PBSystemTab w;
w.ProgramInit();
QString Tmp = QString(argv[1]);
if ( Tmp == "-updates" )
w.changeOpenTab(1);
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
示例15: slotStartLogin
void PCDMgui::slotStartLogin(QString displayname, QString password){
//Get user inputs
QString username = Backend::getUsernameFromDisplayname(displayname);
QString desktop;
if(simpleDESwitcher){
desktop = loginW->currentDE();
}else{
desktop = deSwitcher->currentItem();
}
QString devPassword;
bool anonymous = loginW->isAnonymous();
if(!anonymous && pcCurrent.contains(username)){
//personacrypt user - also pull device password
devPassword = loginW->currentDevicePassword();
}
QLocale currLocale = this->locale();
QString lang = currLocale.name();
//Disable user input while confirming login
loginW->setEnabled(false);
if(!simpleDESwitcher){ deSwitcher->setEnabled(false); }
toolbar->setEnabled(false);
//Try to login
emit xLoginAttempt(username, password, desktop, lang , devPassword,anonymous);
//Return signals are connected to the slotLogin[Success/Failure] functions
}