TextToSpeechPrivate::TextToSpeechPrivate() { spd = spd_open("Mumble", NULL, NULL, SPD_MODE_THREADED); if (! spd) { qWarning("TextToSpeech: Failed to contact speech dispatcher."); } else { QString lang; if (!g.s.qsTTSLanguage.isEmpty()) { lang = g.s.qsTTSLanguage; } else if (!g.s.qsLanguage.isEmpty()) { QLocale locale(g.s.qsLanguage); lang = locale.bcp47Name(); } else { QLocale systemLocale; lang = systemLocale.bcp47Name(); } if (!lang.isEmpty()) { if (spd_set_language(spd, lang.toLocal8Bit().constData()) != 0) { qWarning("TextToSpeech: Failed to set language."); } } if (spd_set_punctuation(spd, SPD_PUNCT_NONE) != 0) qWarning("TextToSpech: Failed to set punctuation mode."); if (spd_set_spelling(spd, SPD_SPELL_ON) != 0) qWarning("TextToSpeech: Failed to set spelling mode."); } }
void LanguageWidget::currentIndexChanged(int index) { if(index < 0) return; LocaleModel *const model = qobject_cast<LocaleModel *>(ui->languages->model()); const QLocale locale = model->locale(ui->languages->model()->index(index, 0)); QSettings settings; settings.setValue("locale", locale.bcp47Name()); settings.sync(); sync(); }
void InfoWidget::localeChanged(QLocale locale) { setLocale(locale); name->setText(locale.name()); bcp47Name->setText(locale.bcp47Name()); languageName->setText(QLocale::languageToString(locale.language())); nativeLanguageName->setText(locale.nativeLanguageName()); scriptName->setText(QLocale::scriptToString(locale.script())); countryName->setText(QLocale::countryToString(locale.country())); nativeCountryName->setText(locale.nativeCountryName()); }
// caseFunc can either be u_strToUpper or u_strToLower static bool qt_u_strToCase(const QString &str, QString *out, const QLocale &locale, Ptr_u_strToCase caseFunc) { Q_ASSERT(out); if (!icuCollator) return false; QString result(str.size(), Qt::Uninitialized); UErrorCode status = U_ZERO_ERROR; int32_t size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(), reinterpret_cast<const UChar *>(str.constData()), str.size(), locale.bcp47Name().toLatin1().constData(), &status); if (U_FAILURE(status)) return false; if (size < result.size()) { result.resize(size); } else if (size > result.size()) { // the resulting string is larger than our source string result.resize(size); status = U_ZERO_ERROR; size = caseFunc(reinterpret_cast<UChar *>(result.data()), result.size(), reinterpret_cast<const UChar *>(str.constData()), str.size(), locale.bcp47Name().toLatin1().constData(), &status); if (U_FAILURE(status)) return false; // if the sizes don't match now, we give up. if (size != result.size()) return false; } *out = result; return true; }
QString uiLanguage(QLocale *callerLoc) { QSettings s; s.beginGroup("Language"); if (!s.value("UseSystemLanguage", true).toBool()) { loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString()); } else { loc = QLocale(QLocale().uiLanguages().first()); } QString uiLang = loc.uiLanguages().first(); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } if (callerLoc) *callerLoc = loc; // the short format is fine // the long format uses long weekday and month names, so replace those with the short ones // for time we don't want the time zone designator and don't want leading zeroes on the hours shortDateFormat = loc.dateFormat(QLocale::ShortFormat); dateFormat = loc.dateFormat(QLocale::LongFormat); dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); // special hack for Swedish as our switching from long weekday names to short weekday names // messes things up there dateFormat.replace("'en' 'den' d:'e'", " d"); timeFormat = loc.timeFormat(); timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); return uiLang; }
QString uiLanguage(QLocale *callerLoc) { QSettings s; s.beginGroup("Language"); QLocale loc; if (!s.value("UseSystemLanguage", true).toBool()) { loc = QLocale(s.value("UiLanguage", QLocale().uiLanguages().first()).toString()); } QString uiLang = loc.uiLanguages().first(); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } if (callerLoc) *callerLoc = loc; return uiLang; }
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()); } } }
// load KDE translators system based translations // TODO: document other possible supported translation systems, if any, and where their catalog files are static void loadTranslations(QApplication &app) { // Quote from ecm_create_qm_loader created code: // 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. const QString en(QStringLiteral("en")); loadTranslation(en, app); QLocale locale = QLocale::system(); if (locale.name() != en) { if (!loadTranslation(locale.name(), app)) { loadTranslation(locale.bcp47Name(), app); } } }
AcceptLanguageDialog::AcceptLanguageDialog(const QString &languages, QWidget *parent) : Dialog(parent), m_ui(new Ui::AcceptLanguageDialog) { m_ui->setupUi(this); m_model = new QStandardItemModel(this); m_model->setHorizontalHeaderLabels(QStringList({tr("Name"), tr("Code")})); m_ui->languagesViewWidget->setModel(m_model); QStringList chosenLanguages(languages.split(QLatin1Char(','), QString::SkipEmptyParts)); for (int i = 0; i < chosenLanguages.count(); ++i) { addLanguage(chosenLanguages.at(i).section(QLatin1Char(';'), 0, 0)); } const QList<QLocale> locales(QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry)); QVector<QPair<QString, QString> > entries; for (int i = 0; i < locales.count(); ++i) { const QLocale locale(locales.at(i)); if (locale != QLocale::c()) { if (locale.nativeCountryName().isEmpty() || locale.nativeLanguageName().isEmpty()) { entries.append({tr("Unknown [%1]").arg(locale.bcp47Name()), locale.bcp47Name()}); } else { entries.append({QStringLiteral("%1 - %2 [%3]").arg(locale.nativeLanguageName()).arg(locale.nativeCountryName()).arg(locale.bcp47Name()), locale.bcp47Name()}); } } } QCollator collator; collator.setCaseSensitivity(Qt::CaseInsensitive); qSort(entries.begin(), entries.end(), [&](const QPair<QString, QString> &first, const QPair<QString, QString> &second) { return (collator.compare(first.first, second.first) < 0); }); entries.prepend(QPair<QString, QString>(tr("Any other"), QLatin1String("*"))); entries.prepend(QPair<QString, QString>(tr("System language (%1 - %2)").arg(QLocale::system().nativeLanguageName()).arg(QLocale::system().nativeCountryName()), QString("system"))); for (int i = 0; i < entries.count(); ++i) { m_ui->languagesComboBox->addItem(entries.at(i).first, entries.at(i).second); } m_ui->moveDownButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-down"))); m_ui->moveUpButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-up"))); m_ui->languagesComboBox->installEventFilter(this); connect(m_ui->moveDownButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveDownRow); connect(m_ui->moveUpButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveUpRow); connect(m_ui->removeButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::removeRow); connect(m_ui->addButton, &QToolButton::clicked, this, &AcceptLanguageDialog::addNewLanguage); connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveDownChanged, m_ui->moveDownButton, &QToolButton::setEnabled); connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveUpChanged, m_ui->moveUpButton, &QToolButton::setEnabled); connect(m_ui->languagesViewWidget, &ItemViewWidget::needsActionsUpdate, this, &AcceptLanguageDialog::updateActions); }
void init_ui(int *argcp, char ***argvp) { QVariant v; application = new QApplication(*argcp, *argvp); // tell Qt to use system proxies // note: on Linux, "system" == "environment variables" QNetworkProxyFactory::setUseSystemConfiguration(true); #if QT_VERSION < 0x050000 // ask QString in Qt 4 to interpret all char* as UTF-8, // like Qt 5 does. // 106 is "UTF-8", this is faster than lookup by name // [http://www.iana.org/assignments/character-sets/character-sets.xml] QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106)); #endif QCoreApplication::setOrganizationName("Subsurface"); QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); QCoreApplication::setApplicationName("Subsurface"); xslt_path = strdup(getSubsurfaceDataPath("xslt").toAscii().data()); QLocale loc; QString uiLang = loc.uiLanguages().first(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info if (!uiLang.contains('-') && uiLang != loc.bcp47Name()) { QLocale loc2(loc.bcp47Name()); loc = loc2; uiLang = loc2.uiLanguages().first(); } // we don't have translations for English - if we don't check for this // Qt will proceed to load the second language in preference order - not what we want // on Linux this tends to be en-US, but on the Mac it's just en if (!uiLang.startsWith("en")) { qtTranslator = new QTranslator; if (qtTranslator->load(loc,"qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { application->installTranslator(qtTranslator); } else { qDebug() << "can't find Qt localization for locale" << uiLang << "searching in" << QLibraryInfo::location(QLibraryInfo::TranslationsPath); } ssrfTranslator = new QTranslator; if (ssrfTranslator->load(loc,"subsurface", "_") || ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("translations")) || ssrfTranslator->load(loc,"subsurface", "_", getSubsurfaceDataPath("../translations"))) { application->installTranslator(ssrfTranslator); } else { qDebug() << "can't find Subsurface localization for locale" << uiLang; } } QSettings s; s.beginGroup("GeneralSettings"); prefs.default_filename = getSetting(s, "default_filename"); s.endGroup(); s.beginGroup("DiveComputer"); default_dive_computer_vendor = getSetting(s, "dive_computer_vendor"); default_dive_computer_product = getSetting(s,"dive_computer_product"); default_dive_computer_device = getSetting(s, "dive_computer_device"); s.endGroup(); window = new MainWindow(); window->show(); if (existing_filename && existing_filename[0] != '\0') window->setTitle(MWTF_FILENAME); else window->setTitle(MWTF_DEFAULT); return; }