summaryrefslogtreecommitdiff
path: root/lingucomponent
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-10-04 10:11:55 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-10-04 12:49:27 +0100
commitd3b7a3acb481ef530094296eb4461dd343270879 (patch)
tree0d92614e85c6a73640f84ca8b3ec92e1a6a63d90 /lingucomponent
parent96e353491215fd2b703f2cd48959176f3e401043 (diff)
support system dicts named using bcp47 scheme
but fallback to LANG_REGION on failure Change-Id: Ic31ba142209cdea1565adef2b592fd59111d9162
Diffstat (limited to 'lingucomponent')
-rw-r--r--lingucomponent/source/lingutil/lingutil.cxx103
1 files changed, 57 insertions, 46 deletions
diff --git a/lingucomponent/source/lingutil/lingutil.cxx b/lingucomponent/source/lingutil/lingutil.cxx
index 362ede900410..6259097c888a 100644
--- a/lingucomponent/source/lingutil/lingutil.cxx
+++ b/lingucomponent/source/lingutil/lingutil.cxx
@@ -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,55 +151,65 @@ 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);
- if (aSystemDicts.open() == osl::FileBase::E_None)
- {
- osl::DirectoryItem aItem;
- osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
- while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
- {
- aItem.getFileStatus(aFileStatus);
- rtl::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 );
- if (!sLang.getLength())
- continue;
- rtl::OUString sRegion;
- if (nIndex != -1)
- sRegion = sChunk.copy( nIndex, sChunk.getLength() - nIndex );
-
- // Thus we first get the language of the dictionary
- LanguageType nLang = MsLangId::convertIsoNamesToLanguage(
- sLang, sRegion );
-
- if (aDicLangInUse.count( nLang ) == 0)
- {
- // remember the new language in use
- aDicLangInUse.insert( nLang );
-
- // 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;
- aRes.push_back( aDicEntry );
- }
- }
- }
+ osl::Directory aSystemDicts(aSystemDir);
+ if (aSystemDicts.open() == osl::FileBase::E_None)
+ {
+ osl::DirectoryItem aItem;
+ osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL);
+ while (aSystemDicts.getNextItem(aItem) == osl::FileBase::E_None)
+ {
+ aItem.getFileStatus(aFileStatus);
+ 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;
+ 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;
+ OUString sRegion;
+ if (nIndex != -1)
+ sRegion = sChunk.copy(nIndex);
+ aLangTag = LanguageTag(sLang, sRegion);
+ }
+ if (!aLangTag.isValidBcp47())
+ continue;
+
+ // Thus we first get the language of the dictionary
+ OUString aLocaleName(aLangTag.getBcp47());
+
+ if (aDicLangInUse.count(aLocaleName) == 0)
+ {
+ // 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
return aRes;