Ejemplo n.º 1
0
void LanguageSelection::Load(void)
{
    MythLocale *locale = new MythLocale();

    QString langCode;

    if (gCoreContext->GetLocale())
    {
        // If the global MythLocale instance exists, then we should use it
        // since it's informed by previously chosen values from the
        // database.
        *locale = *gCoreContext->GetLocale();
    }
    else
    {
        // If no global MythLocale instance exists then we're probably
        // bootstrapping before the database is available, in that case
        // we want to load language from the locale XML defaults if they
        // exist.
        // e.g. the locale defaults might define en_GB for Australia which has
        // no translation of it's own. We can't automatically derive en_GB
        // from en_AU which MythLocale will arrive at and there is no 'en'
        // translation.
        langCode = locale->GetLocaleSetting("Language");
    }

    if (langCode.isEmpty())
        langCode = locale->GetLanguageCode();
    QString localeCode = locale->GetLocaleCode();
    QString countryCode = locale->GetCountryCode();

    LOG(VB_GENERAL, LOG_INFO, 
             QString("System Locale (%1), Country (%2), Language (%3)")
                     .arg(localeCode).arg(countryCode).arg(langCode));

    QMap<QString,QString> langMap = MythTranslation::getLanguages();
    QStringList langs = langMap.values();
    langs.sort();
    MythUIButtonListItem *item;
    bool foundLanguage = false;
    for (QStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
    {
        QString nativeLang = *it;
        QString code = langMap.key(nativeLang); // Slow, but map is small
        QString language = GetISO639EnglishLanguageName(code);
        item = new MythUIButtonListItem(m_languageList, nativeLang);
        item->SetText(language, "language");
        item->SetText(nativeLang, "nativelanguage");
        item->SetData(code);

         // We have to compare against locale for languages like en_GB
        if (code.toLower() == m_language.toLower() ||
            code == langCode || code == localeCode)
        {
            m_languageList->SetItemCurrent(item);
            foundLanguage = true;
        }
    }

    if (m_languageList->IsEmpty())
    {
        LOG(VB_GUI, LOG_ERR, "ERROR - Failed to load translations, at least "
                             "one translation file MUST be installed.");
        
        item = new MythUIButtonListItem(m_languageList,
                                        "English (United States)");
        item->SetText("English (United States)", "language");
        item->SetText("English (United States)", "nativelanguage");
        item->SetData("en_US");
    }

    if (!foundLanguage)
        m_languageList->SetValueByData("en_US");

    ISO3166ToNameMap localesMap = GetISO3166EnglishCountryMap();
    QStringList locales = localesMap.values();
    locales.sort();
    for (QStringList::Iterator it = locales.begin(); it != locales.end();
         ++it)
    {
        QString country = *it;
        QString code = localesMap.key(country); // Slow, but map is small
        QString nativeCountry = GetISO3166CountryName(code);
        item = new MythUIButtonListItem(m_countryList, country);
        item->SetData(code);
        item->SetText(country, "country");
        item->SetText(nativeCountry, "nativecountry");
        item->SetImage(QString("locale/%1.png").arg(code.toLower()));

        if (code == m_country || code == countryCode)
            m_countryList->SetItemCurrent(item);
    }

    delete locale;
}
Ejemplo n.º 2
0
QString MythLocale::GetNativeCountry(void) const
{
    return GetISO3166CountryName(GetCountryCode());
}