Menu

#6 automatic language detection

None
closed
None
9
2014-10-06
2014-06-27
No

Suggestion for automatic detection of the language of the game:

ubyte detectLanguage()
{
ubyte languageMark[4] = {'E', 'D', 'F', 'S'};
    int count = 0;

for (count = 0; count < sizeof(languageMark) / sizeof(languageMark[0]); count++)
{
    ubyte fileName[256];
    ubyte fileWithPath[256];
    FILE *p_File;

    sprintf((char*)fileName,"tcmaine%c.txt", languageMark[count]);
    dskBuildPathName(TEXT_DIRECTORY, fileName, fileWithPath);
    if (p_File = fopen((char*)fileWithPath,(char*) "r"))
    {
        return (ubyte)count;
    }
}

Log("couldn't detect language of the game!");
NewErrorMsg(Internal_Error, __FILE__, __FUNCTION__, 1);
return 0;
}

further changes in the source code

file: base.cpp
function: tcInit

...
...
txtInit(detectLanguage());
...
...

file: error.cpp

include "text.h"

...
...
...

void NewErrorMsg(long l_ErrorType, const char *filename, const char *funcname, ulong ul_ErrorId)
{
char lang = txtGetLanguage();

Log("Error %ld in %s|%s", ul_ErrorId, filename, funcname);

if (ErrorHandler.fp_CloseAll)
    ErrorHandler.fp_CloseAll();

switch (l_ErrorType)
{
    case Internal_Error:
        if (lang==TXT_LANG_ENGLISH)
        {
        Log("Internal Error!");
        }
        else
        {
        Log("Interner Fehler!");
        }
    break;

    case No_Mem:
        if (lang==TXT_LANG_ENGLISH)
            {
        Log("You don't have enough memory!");
        }
        else
            {
        Log("Sie haben nicht genug Speicher!");
        }
    break;

    case Disk_Defect:
        if (lang==TXT_LANG_ENGLISH)
            {
        Log("Can't open file!");
        }
        else
            {
        Log("Kann Datei nicht oeffnen!");
        }
    break;
}

exit(-1);
}

Discussion

  • Oliver Gantert

    Oliver Gantert - 2014-06-27
    • status: open --> accepted
    • assigned_to: Oliver Gantert
    • Group: -->
     
  • Oliver Gantert

    Oliver Gantert - 2014-06-27

    Added in version 0.2a (2014-06-27)

     
  • Oliver Gantert

    Oliver Gantert - 2014-06-27
    • status: accepted --> closed
     

Log in to post a comment.

Auth0 Logo