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 @@
#include <osl/file.hxx>
#include <tools/debug.hxx>
#include <tools/urlobj.hxx>
#include <i18npool/languagetag.hxx>
#include <i18npool/mslangid.hxx>
#include <unotools/lingucfg.hxx>
#include <unotools/pathoptions.hxx>
......@@ -150,7 +151,7 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy
// set of languages to remember the language where it is already
// decided to make use of the dictionary.
std::set< LanguageType > aDicLangInUse;
std::set< OUString > aDicLangInUse;
#ifdef SYSTEM_DICTS
osl::Directory aSystemDicts(aSystemDir);
......@@ -161,35 +162,46 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy
while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
{
aItem.getFileStatus(aFileStatus);
rtl::OUString sPath = aFileStatus.getFileURL();
OUString sPath = aFileStatus.getFileURL();
if (sPath.lastIndexOf(aSystemSuffix) == sPath.getLength()-aSystemSuffix.getLength())
{
sal_Int32 nStartIndex = sPath.lastIndexOf(sal_Unicode('/')) + 1;
if (!sPath.match(aSystemPrefix, nStartIndex))
continue;
rtl::OUString sChunk = sPath.copy(0, sPath.getLength() - aSystemSuffix.getLength());
sal_Int32 nIndex = nStartIndex + aSystemPrefix.getLength();
rtl::OUString sLang = sChunk.getToken( 0, '_', nIndex );
OUString sChunk = sPath.copy(nStartIndex + aSystemPrefix.getLength(),
sPath.getLength() - aSystemSuffix.getLength() -
nStartIndex - aSystemPrefix.getLength());
if (sChunk.isEmpty())
continue;
//We prefer (now) to use language tags
LanguageTag aLangTag(sChunk, true);
//On failure try older basic LANG_REGION scheme
if (!aLangTag.isValidBcp47())
{
sal_Int32 nIndex = 0;
OUString sLang = sChunk.getToken(0, '_', nIndex);
if (!sLang.getLength())
continue;
rtl::OUString sRegion;
OUString sRegion;
if (nIndex != -1)
sRegion = sChunk.copy( nIndex, sChunk.getLength() - nIndex );
sRegion = sChunk.copy(nIndex);
aLangTag = LanguageTag(sLang, sRegion);
}
if (!aLangTag.isValidBcp47())
continue;
// Thus we first get the language of the dictionary
LanguageType nLang = MsLangId::convertIsoNamesToLanguage(
sLang, sRegion );
OUString aLocaleName(aLangTag.getBcp47());
if (aDicLangInUse.count( nLang ) == 0)
if (aDicLangInUse.count(aLocaleName) == 0)
{
// remember the new language in use
aDicLangInUse.insert( nLang );
aDicLangInUse.insert(aLocaleName);
// add the dictionary to the resulting vector
SvtLinguConfigDictionaryEntry aDicEntry;
aDicEntry.aLocations.realloc(1);
aDicEntry.aLocaleNames.realloc(1);
rtl::OUString aLocaleName( MsLangId::convertLanguageToIsoString( nLang ) );
aDicEntry.aLocations[0] = sPath;
aDicEntry.aFormatName = aFormatName;
aDicEntry.aLocaleNames[0] = aLocaleName;
......@@ -198,7 +210,6 @@ std::vector< SvtLinguConfigDictionaryEntry > GetOldStyleDics( const char *pDicTy
}
}
}
#endif
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