Exemplo n.º 1
0
bool SVGTests::isValid() const
{
    if (m_requiredFeatures->isSpecified()) {
        const Vector<String>& requiredFeatures = m_requiredFeatures->value()->values();
        Vector<String>::const_iterator it = requiredFeatures.begin();
        Vector<String>::const_iterator itEnd = requiredFeatures.end();
        for (; it != itEnd; ++it) {
            if (it->isEmpty() || !DOMImplementation::hasFeature(*it, String()))
                return false;
        }
    }

    if (m_systemLanguage->isSpecified()) {
        bool matchFound = false;

        const Vector<String>& systemLanguage = m_systemLanguage->value()->values();
        Vector<String>::const_iterator it = systemLanguage.begin();
        Vector<String>::const_iterator itEnd = systemLanguage.end();
        for (; it != itEnd; ++it) {
            if (*it == defaultLanguage().string().substring(0, 2)) {
                matchFound = true;
                break;
            }
        }

        if (!matchFound)
            return false;
    }

    if (!m_requiredExtensions->value()->values().isEmpty())
        return false;

    return true;
}
Element* AccessibilitySVGElement::childElementWithMatchingLanguage(ChildrenType& children) const
{
    String languageCode = language();
    if (languageCode.isEmpty())
        languageCode = defaultLanguage();

    // The best match for a group of child SVG2 'title' or 'desc' elements may be the one
    // which lacks a 'lang' attribute value. However, indexOfBestMatchingLanguageInList()
    // currently bases its decision on non-empty strings. Furthermore, we cannot count on
    // that child element having a given position. So we'll look for such an element while
    // building the language list and save it as our fallback.

    Element* fallback = nullptr;
    Vector<String> childLanguageCodes;
    Vector<Element*> elements;
    for (auto& child : children) {
        auto& lang = child.attributeWithoutSynchronization(SVGNames::langAttr);
        childLanguageCodes.append(lang);
        elements.append(&child);

        // The current draft of the SVG2 spec states if there are multiple equally-valid
        // matches, the first match should be used.
        if (lang.isEmpty() && !fallback)
            fallback = &child;
    }

    bool exactMatch;
    size_t index = indexOfBestMatchingLanguageInList(languageCode, childLanguageCodes, exactMatch);
    if (index < childLanguageCodes.size())
        return elements[index];

    return fallback;
}
Exemplo n.º 3
0
void HTMLElement::mapLanguageAttributeToLocale(const AtomicString& value, MutableStylePropertySet* style)
{
    if (!value.isEmpty()) {
        // Have to quote so the locale id is treated as a string instead of as a CSS keyword.
        addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLocale, serializeString(value));

        // FIXME: Remove the following UseCounter code when we collect enough
        // data.
        UseCounter::count(document(), UseCounter::LangAttribute);
        if (isHTMLHtmlElement(*this))
            UseCounter::count(document(), UseCounter::LangAttributeOnHTML);
        else if (isHTMLBodyElement(*this))
            UseCounter::count(document(), UseCounter::LangAttributeOnBody);
        String htmlLanguage = value.string();
        size_t firstSeparator = htmlLanguage.find('-');
        if (firstSeparator != kNotFound)
            htmlLanguage = htmlLanguage.left(firstSeparator);
        String uiLanguage = defaultLanguage();
        firstSeparator = uiLanguage.find('-');
        if (firstSeparator != kNotFound)
            uiLanguage = uiLanguage.left(firstSeparator);
        firstSeparator = uiLanguage.find('_');
        if (firstSeparator != kNotFound)
            uiLanguage = uiLanguage.left(firstSeparator);
        if (!equalIgnoringCase(htmlLanguage, uiLanguage))
            UseCounter::count(document(), UseCounter::LangAttributeDoesNotMatchToUILocale);
    } else {
        // The empty string means the language is explicitly unknown.
        addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLocale, CSSValueAuto);
    }
}
Exemplo n.º 4
0
static const char* UILanguage()
{
    // Chrome's UI language can be different from the OS UI language on Windows.
    // We want to return Chrome's UI language here.
    DEFINE_STATIC_LOCAL(CString, locale, (defaultLanguage().latin1()));
    return locale.data();
}
Exemplo n.º 5
0
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
   DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersion()));
   DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));

   // FIXME: We should upate the user agent if the default language changes.
   String language = defaultLanguage();

   if (applicationNameForUserAgent.isEmpty())
       return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)");
   return makeString("Mozilla/5.0 (Windows; U; ", osVersion, "; ", language, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko) ", applicationNameForUserAgent);
}
Exemplo n.º 6
0
QsLanguage::~QsLanguage()
{
   const int defaultLanguageId = defaultLanguage().id;
   if( mApplicationLanguage != defaultLanguageId )
   {
      Q_ASSERT_X(0,"QsLanguage","You forgot to uninstall the translators!");
      setApplicationLanguage(defaultLanguageId);
   }

   qDeleteAll(mLangIdToQtTranslator.values());
   qDeleteAll(mLangIdToTranslator.values());
}
Exemplo n.º 7
0
static LCID LCIDFromLocale(const AtomicString& locale)
{
    // According to MSDN, 9 is enough for LOCALE_SISO639LANGNAME.
    const size_t languageCodeBufferSize = 9;
    WCHAR lowercaseLanguageCode[languageCodeBufferSize];
    ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lowercaseLanguageCode, languageCodeBufferSize);
    String userDefaultLanguageCode = String(lowercaseLanguageCode);

    LCID lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCode, String(locale));
    if (!lcid)
        lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCode, defaultLanguage());
    return lcid;
}
Exemplo n.º 8
0
bool SVGTests::isValid() const
{
    unsigned featuresSize = m_requiredFeatures.value.size();
    for (unsigned i = 0; i < featuresSize; ++i) {
        String value = m_requiredFeatures.value.at(i);
        if (value.isEmpty() || !DOMImplementation::hasFeature(value, String()))
            return false;
    }

    unsigned systemLanguageSize = m_systemLanguage.value.size();
    for (unsigned i = 0; i < systemLanguageSize; ++i) {
        String value = m_systemLanguage.value.at(i);
        if (value != defaultLanguage().substring(0, 2))
            return false;
    }

    if (!m_requiredExtensions.value.isEmpty())
        return false;

    return true;
}
status_t
LocaleRosterData::_LoadLocaleSettings()
{
	BPath path;
	BFile file;
	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (status == B_OK) {
		path.Append("Locale settings");
		status = file.SetTo(path.Path(), B_READ_ONLY);
	}
	BMessage settings;
	if (status == B_OK)
		status = settings.Unflatten(&file);

	if (status == B_OK) {
		BFormattingConventions conventions(&settings);
		fDefaultLocale.SetFormattingConventions(conventions);

		_SetPreferredLanguages(&settings);

		bool preferred;
		if (settings.FindBool(kTranslateFilesystemField, &preferred) == B_OK)
			_SetFilesystemTranslationPreferred(preferred);

		return B_OK;
	}


	// Something went wrong (no settings file or invalid BMessage), so we
	// set everything to default values

	fPreferredLanguages.MakeEmpty();
	fPreferredLanguages.AddString(kLanguageField, "en");
	BLanguage defaultLanguage("en_US");
	fDefaultLocale.SetLanguage(defaultLanguage);
	BFormattingConventions conventions("en_US");
	fDefaultLocale.SetFormattingConventions(conventions);

	return status;
}
void AcceptLanguagesResolver::acceptLanguagesChanged(
    const String& acceptLanguages)
{
    // Use the UI locale if it can disambiguate the Unified Han.
    // Historically we use ICU on Windows. crbug.com/586520
#if OS(WIN)
    // Since Chrome synchronizes the ICU default locale with its UI locale,
    // this ICU locale tells the current UI locale of Chrome.
    m_preferredHanScript = scriptCodeForHanFromLocale(
        icu::Locale::getDefault().getName(), '_');
#else
    m_preferredHanScript = scriptCodeForHanFromLocale(defaultLanguage());
#endif
    if (m_preferredHanScript != USCRIPT_COMMON) {
        // We don't need additional locale if defaultLanguage() can disambiguate
        // since it's always passed to matchFamilyStyleCharacter() separately.
        m_preferredHanSkFontMgrLocale = nullptr;
        return;
    }

    updateFromAcceptLanguages(acceptLanguages);
}
Exemplo n.º 11
0
bool SVGTests::isValid() const
{
    ExceptionCode ec = 0;

    if (m_features) {
        for (unsigned long i = 0; i < m_features->numberOfItems(); i++) {
            String value = m_features->getItem(i, ec);
            if (value.isEmpty() || !DOMImplementation::hasFeature(value, String()))
                return false;
        }
    }

    if (m_systemLanguage) {
        for (unsigned long i = 0; i < m_systemLanguage->numberOfItems(); i++)
            if (m_systemLanguage->getItem(i, ec) != defaultLanguage().substring(0, 2))
                return false;
    }

    if (m_extensions && m_extensions->numberOfItems() > 0)
        return false;

    return true;
}
Exemplo n.º 12
0
AcceptLanguage::AcceptLanguage(QWidget* parent)
    : QDialog(parent)
    , ui(new Ui::AcceptLanguage)
{
    ui->setupUi(this);

    Settings settings;
    settings.beginGroup("Language");
    QStringList langs = settings.value("acceptLanguage", defaultLanguage()).toStringList();

    foreach(const QString & code, langs) {
        QString code_ = code;
        QLocale loc = QLocale(code_.replace('-', '_'));
        QString label;

        if (loc.language() == QLocale::C) {
            label = tr("Personal [%1]").arg(code);
        }
        else {
            label = QString("%1/%2 [%3]").arg(loc.languageToString(loc.language()), loc.countryToString(loc.country()), code);
        }

        ui->listWidget->addItem(label);
    }
Exemplo n.º 13
0
bool SVGTests::isValid() const
{
    // No need to check requiredFeatures since hasFeature always returns true.

    if (m_systemLanguage->isSpecified()) {
        bool matchFound = false;

        const Vector<String>& systemLanguage = m_systemLanguage->value()->values();
        for (const auto& value : systemLanguage) {
            if (value == defaultLanguage().string().substring(0, 2)) {
                matchFound = true;
                break;
            }
        }

        if (!matchFound)
            return false;
    }

    if (!m_requiredExtensions->value()->values().isEmpty())
        return false;

    return true;
}
Exemplo n.º 14
0
String Navigator::language() const
{
    return defaultLanguage();
}
Exemplo n.º 15
0
Locale& Locale::defaultLocale()
{
    static Locale* locale = Locale::create(defaultLanguage()).leakPtr();
    ASSERT(isMainThread());
    return *locale;
}
Exemplo n.º 16
0
static inline UDateFormat* createShortDateFormatter()
{
    const UChar gmtTimezone[3] = {'G', 'M', 'T'};
    UErrorCode status = U_ZERO_ERROR;
    return udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
}
Exemplo n.º 17
0
void SettingsModel::validate(void)
{
	if(this->compressionEncoder() < SettingsModel::MP3Encoder || this->compressionEncoder() >= SettingsModel::ENCODER_COUNT)
	{
		this->compressionEncoder(SettingsModel::MP3Encoder);
	}
	
	CHECK_RCMODE(LAME);
	CHECK_RCMODE(OggEnc);
	CHECK_RCMODE(AacEnc);
	CHECK_RCMODE(Aften);
	CHECK_RCMODE(OpusEnc);
	
	if(EncoderRegistry::getAacEncoder() == AAC_ENCODER_NONE)
	{
		if(this->compressionEncoder() == SettingsModel::AACEncoder)
		{
			qWarning("AAC encoder selected, but not available any more. Reverting to MP3!");
			this->compressionEncoder(SettingsModel::MP3Encoder);
		}
	}
	
	if(this->outputDir().isEmpty() || (!DIR_EXISTS(this->outputDir())))
	{
		qWarning("Output directory not set yet or does NOT exist anymore -> Resetting");
		this->outputDir(defaultDirectory());
	}

	if(this->mostRecentInputPath().isEmpty() || (!DIR_EXISTS(this->mostRecentInputPath())))
	{
		qWarning("Most recent input directory not set yet or does NOT exist anymore -> Resetting");
		this->mostRecentInputPath(defaultDirectory());
	}

	if(!this->currentLanguageFile().isEmpty())
	{
		const QString qmPath = QFileInfo(this->currentLanguageFile()).canonicalFilePath();
		if(qmPath.isEmpty() || (!(QFileInfo(qmPath).exists() && QFileInfo(qmPath).isFile() && (QFileInfo(qmPath).suffix().compare("qm", Qt::CaseInsensitive) == 0))))
		{
			qWarning("Current language file missing, reverting to built-in translator!");
			this->currentLanguageFile(QString());
		}
	}

	if(!lamexp_query_translations().contains(this->currentLanguage(), Qt::CaseInsensitive))
	{
		qWarning("Current language \"%s\" is unknown, reverting to default language!", this->currentLanguage().toLatin1().constData());
		this->currentLanguage(defaultLanguage());
	}

	if(this->hibernateComputer())
	{
		if(!lamexp_is_hibernation_supported())
		{
			this->hibernateComputer(false);
		}
	}

	if(this->overwriteMode() < SettingsModel::Overwrite_KeepBoth || this->overwriteMode() > SettingsModel::Overwrite_Replaces)
	{
		this->overwriteMode(SettingsModel::Overwrite_KeepBoth);
	}

}
Exemplo n.º 18
0
 ScopedDateFormat()
 {
     UErrorCode status = U_ZERO_ERROR;
     m_dateFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
 }
Exemplo n.º 19
0
AtomicString NavigatorLanguage::language()
{
    return defaultLanguage();
}
Exemplo n.º 20
0
static LCID LCIDFromLocale(const String& locale, bool defaultsForLocale)
{
    // LocaleNameToLCID() is available since Windows Vista.
    LocaleNameToLCIDPtr localeNameToLCID = reinterpret_cast<LocaleNameToLCIDPtr>(::GetProcAddress(::GetModuleHandle(L"kernel32"), "LocaleNameToLCID"));
    if (!localeNameToLCID)
        localeNameToLCID = convertLocaleNameToLCID;

    // According to MSDN, 9 is enough for LOCALE_SISO639LANGNAME.
    const size_t languageCodeBufferSize = 9;
    WCHAR lowercaseLanguageCode[languageCodeBufferSize];
    ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME | (defaultsForLocale ? LOCALE_NOUSEROVERRIDE : 0), lowercaseLanguageCode, languageCodeBufferSize);
    String userDefaultLanguageCode = String(lowercaseLanguageCode);

    LCID lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCode, localeNameToLCID, locale);
    if (!lcid)
        lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCode, localeNameToLCID, defaultLanguage());
    return lcid;
}