Kaydet (Commit) d3b7a3ac authored tarafından Caolán McNamara's avatar Caolán McNamara

support system dicts named using bcp47 scheme

but fallback to LANG_REGION on failure

Change-Id: Ic31ba142209cdea1565adef2b592fd59111d9162
üst 96e35349
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <i18npool/languagetag.hxx>
#include <i18npool/mslangid.hxx> #include <i18npool/mslangid.hxx>
#include <unotools/lingucfg.hxx> #include <unotools/lingucfg.hxx>
#include <unotools/pathoptions.hxx> #include <unotools/pathoptions.hxx>
...@@ -150,55 +151,65 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy ...@@ -150,55 +151,65 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy
// set of languages to remember the language where it is already // set of languages to remember the language where it is already
// decided to make use of the dictionary. // decided to make use of the dictionary.
std::set< LanguageType > aDicLangInUse; std::set< OUString > aDicLangInUse;
#ifdef SYSTEM_DICTS #ifdef SYSTEM_DICTS
osl::Directory aSystemDicts(aSystemDir); osl::Directory aSystemDicts(aSystemDir);
if (aSystemDicts.open() == osl::FileBase::E_None) if (aSystemDicts.open() == osl::FileBase::E_None)
{ {
osl::DirectoryItem aItem; osl::DirectoryItem aItem;
osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL); osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None) while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
{ {
aItem.getFileStatus(aFileStatus); aItem.getFileStatus(aFileStatus);
rtl::OUString sPath = aFileStatus.getFileURL(); OUString sPath = aFileStatus.getFileURL();
if (sPath.lastIndexOf(aSystemSuffix) == sPath.getLength()-aSystemSuffix.getLength()) if (sPath.lastIndexOf(aSystemSuffix) == sPath.getLength()-aSystemSuffix.getLength())
{ {
sal_Int32 nStartIndex = sPath.lastIndexOf(sal_Unicode('/')) + 1; sal_Int32 nStartIndex = sPath.lastIndexOf(sal_Unicode('/')) + 1;
if (!sPath.match(aSystemPrefix, nStartIndex)) if (!sPath.match(aSystemPrefix, nStartIndex))
continue; continue;
rtl::OUString sChunk = sPath.copy(0, sPath.getLength() - aSystemSuffix.getLength()); OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.getLength(),
sal_Int32 nIndex = nStartIndex + aSystemPrefix.getLength(); sPath.getLength() - aSystemSuffix.getLength() -
rtl::OUString sLang = sChunk.getToken( 0, '_', nIndex ); nStartIndex - aSystemPrefix.getLength());
if (!sLang.getLength()) if (sChunk.isEmpty())
continue; continue;
rtl::OUString sRegion; //We prefer (now) to use language tags
if (nIndex != -1) LanguageTag aLangTag(sChunk, true);
sRegion = sChunk.copy( nIndex, sChunk.getLength() - nIndex ); //On failure try older basic LANG_REGION scheme
if (!aLangTag.isValidBcp47())
// Thus we first get the language of the dictionary {
LanguageType nLang = MsLangId::convertIsoNamesToLanguage( sal_Int32 nIndex = 0;
sLang, sRegion ); OUString sLang = sChunk.getToken(0, '_', nIndex);
if (!sLang.getLength())
if (aDicLangInUse.count( nLang ) == 0) continue;
{ OUString sRegion;
// remember the new language in use if (nIndex != -1)
aDicLangInUse.insert( nLang ); sRegion = sChunk.copy(nIndex);
aLangTag = LanguageTag(sLang, sRegion);
// add the dictionary to the resulting vector }
SvtLinguConfigDictionaryEntry aDicEntry; if (!aLangTag.isValidBcp47())
aDicEntry.aLocations.realloc(1); continue;
aDicEntry.aLocaleNames.realloc(1);
rtl::OUString aLocaleName( MsLangId::convertLanguageToIsoString( nLang ) ); // Thus we first get the language of the dictionary
aDicEntry.aLocations[0] = sPath; OUString aLocaleName(aLangTag.getBcp47());
aDicEntry.aFormatName = aFormatName;
aDicEntry.aLocaleNames[0] = aLocaleName; if (aDicLangInUse.count(aLocaleName) == 0)
aRes.push_back( aDicEntry ); {
} // remember the new language in use
} aDicLangInUse.insert(aLocaleName);
}
// add the dictionary to the resulting vector
SvtLinguConfigDictionaryEntry aDicEntry;
aDicEntry.aLocations.realloc(1);
aDicEntry.aLocaleNames.realloc(1);
aDicEntry.aLocations[0] = sPath;
aDicEntry.aFormatName = aFormatName;
aDicEntry.aLocaleNames[0] = aLocaleName;
aRes.push_back( aDicEntry );
}
}
}
} }
#endif #endif
return aRes; return aRes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment