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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • It's hardly surprising that half of small businesses fail within the first 1-5 years. It's not easy to launch a new product, single-handedly manage everything from IT to accounting, fend off the competition, and grow a customer base – all at the same time – even with a great concept. Offering awesome customer service can make the difference between a startup that flies and a startup that dies. Read this white paper to learn nine ways customer support can help you beat the competition and grow your …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds