Game Development Reference
In-Depth Information
6. The directory where we store the localized string iles is deined for the of simplicity,
in another global variable:
const std::string g_LocalePath = "Localizer";
How it works...
The LocalizeString() function accepts a string in the base language and returns its
translation. Whenever we want to render some text, we do not use string literals directly, as
this will seriously reduce our ability to localize our game. Instead, we wrap these literals into
the LocalizeString() calls:
PrintString( LocalizeString( "Some text") );
There's more...
To render a text in an appropriate language we can use the OS functions to detect its current
locale settings. On Android, we use the following Java code in our Activity . SetLocale()
is called from the Activity constructor:
import java.util.Locale;
private static void SetLocale()
{
Detect the locale name and pass it to our native code:
String Lang = Locale.getDefault().getLanguage();
SetLocaleName( Lang );
}
In the native code, we just capture the locale name:
JNIEXPORT void JNICALL
Java_ com_packtpub_ndkcookbook_app14_App14Activity_SetLocaleName(
JNIEnv* env, jobject obj, jstring LocaleName )
{
g_LocaleName = ConvertJString( env, LocaleName );
}
On Windows, things are even simpler. We call the GetLocaleInfo() WinAPI function and
extract the current language name in the ISO639 format ( http://en.wikipedia.org/
wiki/ISO_639 ):
char Buf[9];
GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME,
Buf, sizeof(Buf) );
g_LocaleName = std::string( Buf );
 
Search WWH ::




Custom Search