In managed code there is a property TextInfo.IsRightToLeft that indicates the direction of each culture. This is a simple C# code snippet to detect if the culture is RightToLeft.
using System.Globalization;
…
static bool IslanguageRTL()
{
return CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
}
In unmanaged code, you need to dig deeper in the locale structure to see if it RTL or not. This is a simple C++ code snippet:
#include
…
bool IsLanguageRTL( void )
{
LOCALESIGNATURE localesig;
LANGID languageID=GetUserDefaultUILanguage();
if (GetLocaleInfoW(languageID,LOCALE_FONTSIGNATURE,(LPWSTR)&localesig,
(sizeof(localesig)/sizeof(wchar_t))) && (localesig.lsUsb[3]&0x08000000))
return true;
return false;
}
I hope this helps!
Thank you for sharing code! I just tried it and it worked great for me. You saved my time. Kudos to you!
ReplyDeletee signatures