home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2271 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: sourcery.han.de!not-for-mail
  2. Newsgroups: comp.sys.amiga.programmer
  3. References: <1143.6601T709T2673@mbox3.swipnet.se>
  4. From: "Olaf Barthel" <olsen@sourcery.han.de>
  5. Date: Mon, 29 Jan 1996 14:19:00 +0100
  6. X-NewsReader: IntuiNews 1.3a (7.9.95)
  7. Subject: Re: Localisation
  8. Message-ID: <13213535@sourcery.han.de>
  9.  
  10. In Article <1143.6601T709T2673@mbox3.swipnet.se>, Roland Bengtsson <roland.bengtsson@mbox3.swipnet.se> wrote:
  11. > I took a look at the locale example at the NDK disk, but I winder if this really is the most effective way to go?
  12. >
  13. > They use a function GetString() that compare localeID with each member in the localelist,
  14. > when it is needed. Of course it doesn't matter, but maybe in a big program with many strings
  15. > on a 68000 without cache. I have never done localisation, but I have a project who need it.
  16. >
  17. > Is it possible to use:
  18. >
  19. > enum { MSG_HELLO, MSG_BYE, NUMSTRINGS };
  20. >
  21. > Then call the list with localestring[MSG_BYE] for example;
  22.  
  23.    This will only work if there is a string assigned to each ID and there
  24. are no gaps between IDs.
  25.  
  26. > I would appreciate if someone could send a short example in email or here if this is possible.
  27. >
  28. > If the NDK disk is the best way, please explain why!
  29.  
  30.    Per se it is not the best way to iterate through the entire database
  31. to look up a single string. However, with small databases the overhead is
  32. neglegible. If your database contents are sorted in ascending order (which
  33. CatComp unfortunately does not enforce) you could use a simple binary
  34. search to look up the string. Here is some modified piece of code I use
  35. in my `term' application; it assumes that the strings are stored in
  36. "AppStrings" and "NumAppStrings" holds the number of entries in the database.
  37.  
  38. ----------------------------------8<---------------------------------
  39.  
  40. STRPTR
  41. GetString(ULONG ID)
  42. {
  43.     STRPTR Builtin;
  44.     LONG Left,Mid,Right;
  45.  
  46.     Left    = 0;
  47.     Right    = NumAppStrings - 1;
  48.  
  49.     do
  50.     {
  51.         Mid = (Left + Right) / 2;
  52.  
  53.         if(ID < AppStrings[Mid].cca_ID)
  54.             Right    = Mid - 1;
  55.         else
  56.             Left    = Mid + 1;
  57.     }
  58.     while(ID != AppStrings[Mid].cca_ID && Left <= Right);
  59.  
  60.     if(ID == AppStrings[Mid].cca_ID)
  61.         Builtin = AppStrings[Mid].cca_Str;
  62.     else
  63.         Builtin = "";
  64.  
  65.     if(Catalog)
  66.     {
  67.         STRPTR String = GetCatalogStr(Catalog,ID,Builtin);
  68.  
  69.         if(String[0])
  70.             return(String);
  71.     }
  72.  
  73.     return(Builtin);
  74. }
  75.  
  76. --
  77. Home: Olaf Barthel, Brabeckstrasse 35, D-30559 Hannover
  78.  Net: olsen@sourcery.han.de
  79.