i18nlangtag/qa/cppunit/test_languagetag.cxx | 18 +++++++++++ i18nlangtag/source/languagetag/languagetag.cxx | 38 +++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-)
New commits: commit 79fc6b82b7071262ec71c27f81e68b7d274ae695 Author: Eike Rathke <er...@redhat.com> Date: Sat Oct 12 15:04:37 2013 +0200 for unmapped language-only register primary language ID if available ... instead of an on-the-fly ID Change-Id: I5cb38e91b67d02f0ccda90feb2ad0c60cd3765c5 diff --git a/i18nlangtag/qa/cppunit/test_languagetag.cxx b/i18nlangtag/qa/cppunit/test_languagetag.cxx index 91ef1ef..8a055be 100644 --- a/i18nlangtag/qa/cppunit/test_languagetag.cxx +++ b/i18nlangtag/qa/cppunit/test_languagetag.cxx @@ -324,6 +324,24 @@ void TestLanguageTag::testAllTags() CPPUNIT_ASSERT( de_DE.getLanguageType() == LANGUAGE_GERMAN ); } + // Unmapped but known language-only. + { + OUString s_de( "de" ); + LanguageTag de( s_de, true ); + lang::Locale aLocale = de.getLocale(); + CPPUNIT_ASSERT( de.getBcp47() == s_de ); + CPPUNIT_ASSERT( aLocale.Language == "de" ); + CPPUNIT_ASSERT( aLocale.Country == "" ); + CPPUNIT_ASSERT( aLocale.Variant == "" ); + LanguageType de_LangID = de.getLanguageType(); + CPPUNIT_ASSERT( de_LangID != LANGUAGE_GERMAN ); + CPPUNIT_ASSERT( MsLangId::getPrimaryLanguage( de_LangID) == MsLangId::getPrimaryLanguage( LANGUAGE_GERMAN) ); + CPPUNIT_ASSERT( de.makeFallback().getBcp47() == "de-DE"); + // Check registered mapping. + LanguageTag de_l( de_LangID); + CPPUNIT_ASSERT( de_l.getBcp47() == s_de ); + } + // 'de-1901' derived from 'de-DE-1901' grandfathered to check that it is // accepted as (DIGIT 3ALNUM) variant { diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index 02225a4..fc1f5b5 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -308,9 +308,13 @@ private: /** Generates on-the-fly LangID and registers the maBcp47,mnLangID pair. + @param nRegisterID + If not 0 and not LANGUAGE_DONTKNOW, use that ID instead of + generating an on-the-fly ID. + @return NULL if no ID could be obtained or registration failed. */ - LanguageTag::ImplPtr registerOnTheFly(); + LanguageTag::ImplPtr registerOnTheFly( LanguageType nRegisterID ); /** Obtain Language, Script, Country and Variants via simpleExtract() and assign them to the cached variables if successful. @@ -592,7 +596,7 @@ LanguageTag::~LanguageTag() } -LanguageTag::ImplPtr LanguageTagImpl::registerOnTheFly() +LanguageTag::ImplPtr LanguageTagImpl::registerOnTheFly( LanguageType nRegisterID ) { LanguageTag::ImplPtr pImpl; @@ -640,7 +644,8 @@ LanguageTag::ImplPtr LanguageTagImpl::registerOnTheFly() if (!bOtherImpl || !pImpl->mbInitializedLangID) { - LanguageType nLang = getNextOnTheFlyLanguage(); + LanguageType nLang = ((nRegisterID == 0 || nRegisterID == LANGUAGE_DONTKNOW) ? + getNextOnTheFlyLanguage() : nRegisterID); if (!nLang) { // out of IDs, nothing to register @@ -878,7 +883,11 @@ LanguageTag::ImplPtr LanguageTag::registerImpl() const pImpl->convertBcp47ToLocale(); if (!pImpl->mbInitializedLangID) pImpl->convertLocaleToLang( true); - bool bInsert = LanguageTag::isOnTheFlyID( pImpl->mnLangID); + // Unconditionally insert (round-trip is possible) for + // on-the-fly IDs and (generated or not) primary language IDs. + bool bInsert = (pImpl->mnLangID != LANGUAGE_DONTKNOW && + (LanguageTag::isOnTheFlyID( pImpl->mnLangID) || + (pImpl->mnLangID == MsLangId::getPrimaryLanguage( pImpl->mnLangID)))); OUString aBcp47; if (!bInsert) { @@ -1298,7 +1307,26 @@ void LanguageTagImpl::convertLocaleToLang( bool bAllowOnTheFlyID ) if (mnLangID == LANGUAGE_DONTKNOW && bAllowOnTheFlyID) { if (isValidBcp47()) - registerOnTheFly(); + { + // For language-only (including script) look if we know some + // locale of that language and if so use the primary language + // ID of that instead of generating an on-the-fly-ID. + if (getCountry().isEmpty() && isIsoODF()) + { + lang::Locale aLoc( MsLangId::Conversion::lookupFallbackLocale( maLocale)); + // 'en-US' is last resort, do not use except when looking + // for 'en'. + if (aLoc.Language != "en" || getLanguage() == "en") + { + mnLangID = MsLangId::Conversion::convertLocaleToLanguage( aLoc); + // LANGUAGE_DONTKNOW is all bits of primary language, + // so this is ok even if the conversion failed, which + // it should not anyway.. + mnLangID = MsLangId::getPrimaryLanguage( mnLangID); + } + } + registerOnTheFly( mnLangID); + } else { SAL_WARN( "i18nlangtag", "LanguageTagImpl::convertLocaleToLang: with bAllowOnTheFlyID invalid '" _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits