Tip: Detect if a Language Font is Installed (Such as East Asian)

There are times when your application might need to display Japanese fonts or some other East Asian languages, like Chinese or Korean—which are collectively know as CJK in acronym. On a Japanese Windows XP, this is not a problem. On a non-Japanese Windows XP, there is a problem, because the Japanese characters will appear as squared boxes, so (non-Japanese) users may wonder what the actual language and its content are. A way is needed to detect when the application is running on non-Japanese Windows XP without the East Asian Language Pack installed, and it needs to be able to notify the users that the East Asian Language Pack needs to be installed in order to display Japanese text.

Upon seeing the prompt, the user may choose the install the East Asian Language Pack if they can understand Japanese or they can ignore it ( or not run the application), if they don't understand Japanese anyway. Please note this is not a problem on Windows Vista and Windows 7 as these two operating systems have all of the common languages installed.

I have searched for the solution on how to detect if an East Asian Language is installed on Windows XP, however I can find none. Instead, I find many useless replies taht say this is a non-issue: because only a Japanese user will run a Japanese application and they will have all the necessary fonts installed. While this is true in most cases, it is not true in all cases. For example, if I have an English OpenGL game demo that happens to display Japanese text in one of the signboards in the scene because it is depicting a busy street in a Japanese City, then I need a way to detect if Japanese language is installed so that I can generate the text glyphs for that scene. If Japanese language is not installed, I can choose to display English text instead.

I found out that there is a API, EnumSystemLanguageGroups function, which can do this. This is the function signature below.

BOOL EnumSystemLanguageGroups(
  __in  LANGUAGEGROUP_ENUMPROC lpLanguageGroupEnumProc,
  __in  DWORD dwFlags,
  __in  LONG_PTR lParam
);

The first parameter, lpLanguageGroupEnumProc, is a callback function, of EnumLanguageGroupsProc type, which is called during system language enumeration. The second parameter, dwFlags, is a flag that can be passed in LGRPID_INSTALLED or LGRPID_SUPPORTED, depending which is the minimum support you want to detect. The third parameter, lParam, is an address of a variable that will be passed into the callback function. You can set the language enumeration result into this variable inside the callback function. Below is a code sample on how to detect if Japanese is installed.

#include <string>
#include <iostream>
#include <Windows.h>
#include <Winnls.h>

BOOL CALLBACK JapaneseEnumLanguageGroupsProc(
    LGRPID LanguageGroup,             // language-group identifier
    LPTSTR lpLanguageGroupString,     // language-group identifier string
    LPTSTR lpLanguageGroupNameString, // language-group name string 
    DWORD dwFlags,                    // options
    LONG_PTR  lParam                  // callback parameter
    )
{
    LONG* plLang = (LONG*)(lParam);
    std::wstring strLang=lpLanguageGroupNameString;
    if(L"Japanese"==strLang&&dwFlags==LGRPID_INSTALLED)
    {
        *plLang = 1;
        return FALSE; // Do not enumerate anymore
    }

    return TRUE;
}

bool IsJapaneseLangInstalled()
{
    LONG lLang=0;
    EnumSystemLanguageGroups(
        JapaneseEnumLanguageGroupsProc, // callback function
        LGRPID_SUPPORTED,               // language groups
        (LONG_PTR)&lLang          // callback parameter
        );

    if(lLang==1)
        return true;

    return false;
}

int _tmain(int argc, _TCHAR* argv[])
{
	std::wstring strAns = IsJapaneseLangInstalled() ? L"Yes" : L"No" ;
	std::wcout<<L"Japanese Language Installed : " <<  strAns  << std::endl;
	
	return 0;
}

Note: For Chinese language, you have to choose whether you want to detect if Traditional Chinese, Simplified Chinese, or both are installed. The sample code to detect CJK is included as a source code download of this article.



About the Author

Wong Shao Voon

I guess I'll write here what I does in my free time, than to write an accolade of skills which I currently possess. I believe the things I does in my free time, say more about me.

When I am not working, I like to watch Japanese anime. I am also writing some movie script, hoping to see my own movie on the big screen one day.

I like to jog because it makes me feel good, having done something meaningful in the morning before the day starts.

I also writes articles for CodeGuru; I have a few ideas to write about but never get around writing because of hectic schedule.

Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds