On Thursday 12 July 2007, Dennis Schridde wrote: > I am afraid your patch to frameresource.c wont work like this. > > - Unconditional inclusion of locale.h, which shouldn't happen when compile > with --disable-nls, eg. in case where no gettext is available.
> - Variable declaration in the middle of a scope. This will break MSVC. Aha. Will change. > - Just curiosity: You cut off everything after '_' in the locale. Is this > guaranteed to work everywhere? Yes. From man setlocale: A locale name is typically of the form language[_territory][.codeset] [EMAIL PROTECTED], where language is an ISO 639 language code, territory is an ISO 3166 country code, and codeset is a character set or encoding identifier like ISO-8859-1 or UTF-8. But I should also account for the case where no _territory is used but a .codeset. > - Can the search for the translated file maybe go into an own function? I > would make it work like gettext(), hand in the filename and get back the > translation filename in case it exists. Yes, why not. > - setlocale should recieve NULL and delim should be set to '\0' Oh well, we're in the C world here ... I'm usually using C++, where NULL is a no-no. > - The locale is the same for all files, so maybe we want to store it > between retrieving filenames? Yes, I was already thinking of just putting it into a static var, but then - does it really matter ? Oh wait - I remember that on Windoze it does matter, as this is very slow in that regard. > PS: On systems that support it locale.h is included by libintl.h which is > included by gettext.h which is already included by frame.h. > We also do some fixups for sometimes malfunctioning headers there. > So you should not need to include it yourself. OK, I now made the new checkLocaleFile() function aware of the ENABLE_NLS define. See attached patch. > PPS: Lots of strings are duplicated in strings.txt, which afaik only acts > as a translation resource. > The "best" solution might be to drop that file and instead of STR_ID_FUU > use the _("Fuu") gettext style thing... Probably involves a huge effort to > do this? You mean this strings.txt and the whole STR_ID stuff is something like a homebrewn gettext() implementation ? Somehow this system is beyond me ... Do I understand it correctly that: text.h defines numbers for strings (as an enum) text.c assigns keywords to those numbers and builds a binary tree with nodes (number, keyword) accessible via psStringRes Hmmm...when does strings.txt come into play ? -- Best regards/Schöne Grüße Martin () ascii ribbon campaign - against html mail /\ - against microsoft attachments Computers and Internet gave you freedom. TCPA would TAKE your FREEDOM! http://www.againsttcpa.com
Index: frameresource.c =================================================================== --- frameresource.c (revision 2068) +++ frameresource.c (working copy) @@ -30,6 +30,7 @@ #include "frame.h" #include "frameresource.h" #include "resly.h" +#include <physfs.h> // Local prototypes static RES_TYPE *psResTypes=NULL; @@ -371,7 +372,63 @@ return psRes; } +// check if given file exists in a locale dependend subdir +// if so, modify given fileName to hold the locale dep. file, +// else do not change given fileName +void checkLocaleFile(char *fileName) // given string must have MAX_PATH size +{ +#ifndef ENABLE_NLS + return; +#else + static BOOL haveLocale = FALSE; + static char language[20] = { '\0' }; + char localeFile[MAX_PATH]; + + if ( ! haveLocale ) // only get language name once for speed optimization + { + char *localeName = setlocale(LC_MESSAGES, NULL); + char *delim; + + haveLocale = TRUE; + + if ( !localeName ) + { + return; + } + + strncpy(language, localeName, sizeof(language)); + language[sizeof(language) - 1] = '\0'; // be sure to have a 0-terminated string + + delim = strchr(language, '_'); + + if ( !delim ) + { + delim = strchr(language, '.'); + } + + if ( delim ) + { + *delim = '\0'; + } + } + + if ( (language[0] == '\0') || // could not get language + (strlen(fileName) + strlen(language) + 1 >= MAX_PATH) ) + { + return; + } + + snprintf(localeFile, sizeof(localeFile), "%s/%s", language, fileName); + + if ( PHYSFS_exists(localeFile) ) + { + strcpy(fileName, localeFile); + debug(LOG_WZ, "found translated file: %s", fileName); + } +#endif +} + /* Call the load function for a file */ BOOL resLoadFile(const char *pType, const char *pFile) { @@ -415,6 +472,8 @@ strcpy(aFileName, aCurrResDir); strcat(aFileName, pFile); + checkLocaleFile(aFileName); // check for translated file + strcpy(LastResourceFilename,pFile); // Save the filename in case any routines need it // load the resource
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev