Is. #783 - Fix language detection

The `setlocale` call doesn't return a single locale name in glibc when
any of the locale category variable has a different value, instead it
returns a composite locale name which is a concatenation of the entire
list of locale name and its values, causing the language detection fail.

This patch attempts to set the language via LC_MESSAGES and LANG
environment variables which are commonly used in POSIX-like systems,
then fallbacks to `setlocale` as the last resort.
This commit is contained in:
林博仁(Buo-ren Lin) 2018-12-03 22:13:22 +08:00
parent 86b52dc108
commit 88b99acdd6

View file

@ -36,6 +36,7 @@
#include "attrs.h"
#include "sprtf.h"
#if SUPPORT_LOCALIZATIONS
# include "stdlib.h"
# include "locale.h"
#endif
@ -119,7 +120,13 @@ TidyDocImpl* tidyDocCreate( TidyAllocator *allocator )
#if SUPPORT_LOCALIZATIONS
if ( TY_(tidyGetLanguageSetByUser)() == no )
{
TY_(tidySetLanguage)( setlocale( LC_ALL, "") );
if( ! TY_(tidySetLanguage)( getenv( "LC_MESSAGES" ) ) )
{
if( ! TY_(tidySetLanguage)( getenv( "LANG" ) ) )
{
TY_(tidySetLanguage)( setlocale( LC_ALL, "" ) );
}
}
}
#endif