diff options
Diffstat (limited to 'unotools/source/misc/syslocale.cxx')
-rw-r--r-- | unotools/source/misc/syslocale.cxx | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx index 8e9d75c6ce0c..f51ef35512cb 100644 --- a/unotools/source/misc/syslocale.cxx +++ b/unotools/source/misc/syslocale.cxx @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: syslocale.cxx,v $ - * $Revision: 1.11 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify @@ -39,6 +36,9 @@ #include <unotools/localedatawrapper.hxx> #include <comphelper/processfactory.hxx> #include <i18npool/mslangid.hxx> +#include <rtl/tencinfo.h> +#include <rtl/locale.h> +#include <osl/nlsupport.h> using namespace osl; using namespace com::sun::star; @@ -187,4 +187,28 @@ LanguageType SvtSysLocale::GetUILanguage() const return pImpl->aSysLocaleOptions.GetRealUILanguage(); } +//------------------------------------------------------------------------ + +// static +rtl_TextEncoding SvtSysLocale::GetBestMimeEncoding() +{ + const sal_Char* pCharSet = rtl_getBestMimeCharsetFromTextEncoding( + gsl_getSystemTextEncoding() ); + if ( !pCharSet ) + { + // If the system locale is unknown to us, e.g. LC_ALL=xx, match the UI + // language if possible. + ::com::sun::star::lang::Locale aLocale( SvtSysLocale().GetUILocale() ); + rtl_Locale * pLocale = rtl_locale_register( aLocale.Language.getStr(), + aLocale.Country.getStr(), aLocale.Variant.getStr() ); + rtl_TextEncoding nEnc = osl_getTextEncodingFromLocale( pLocale ); + pCharSet = rtl_getBestMimeCharsetFromTextEncoding( nEnc ); + } + rtl_TextEncoding nRet; + if ( pCharSet ) + nRet = rtl_getTextEncodingFromMimeCharset( pCharSet ); + else + nRet = RTL_TEXTENCODING_UTF8; + return nRet; +} |