Advertisement
Guest User

LangFiles v0.1

a guest
Aug 19th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.40 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. //                                                                    A
  6.                                                                      /*\
  7.                                                                     /!!!\
  8.                                                                    /!!!!!\
  9.                                                                   /!!!!!!!\
  10.                                                                  /!!!!!!!!!\
  11.                                                                 /!!!!!!!!!!!\
  12.                                                                /!!!!!!!!!!!!!\
  13.                                                               /!!!!!!!!!!!!!!!\
  14.                                                              /!!!!!!!!!!!!!!!!!\
  15.                                                             /!!!!!!!!!!!!!!!!!!!\
  16.                                                            /!!!!!!!!!!!!!!!!!!!!!\
  17.                                                           /!!!!!!!!READ!ME!!!!!!!!\
  18.                                                          /!!!!!!!!!!!!!!!!!!!!!!!!!\
  19.                                                         /!!!!!!!!!!!!!!!!!!!!!!!!!!!\                                                                                                                   *//*
  20.                                                        /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
  21.                                                       /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
  22.                                                      /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
  23.                                                     /!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
  24.                                                    /+===================================+\
  25.                                                   /  LangFiles v0.1 Include made by Meta  \
  26.                                                  /+=======================================+\                                                                                                            *//*
  27.                                                 / With this Inlcude you can write a script  \
  28.                                                / completely without hard-coded texts. The    \
  29.                                               / texts get included from external files with   \
  30.                                              / names based on their language code (e.g. "EN"). \
  31.                                             / You can create a file for your language or create \
  32.                                            / a new one like klingon or some other shit :D.       \                                                                                                      *//*
  33.                                           /+=====================================================+\
  34.                                          / What you are NOT allowed to do: (default shit ^^)       \
  35.                                         / - use it for commercial projects                          \                                                                                                   *//*
  36.                                        / - leave SA:MP                                               \
  37.                                       / - re-release it and/or claim it as your work (very easy xD)   \
  38.                                      / - use it for commercial projects                                \
  39.                                     / - play IV:MP                                                      \
  40.                          __________/+===================================================================+\___________
  41.                         |wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww|
  42.    
  43.    
  44.    
  45.    
  46. */
  47. #include <a_samp>
  48.  
  49. /*
  50. example:
  51.  
  52. public OnPlayerConnect(playerid) //Player's name is 'peter'!
  53. {
  54.     new playername[MAX_PLAYER_NAME], string[100];
  55.     GetPlayerName(playerid, playername, sizeof(playername));
  56.  
  57.     format(string, sizeof(string), "%s%s%s", GetLangVar("DE", "HelloText"), playername, GetLangVar("DE", "HelloText2"));    print(string);
  58.     // Hallo, Peter, willkommen auf unserem Server!
  59.  
  60.     format(string, sizeof(string), "%s%s%s", GetLangVar("ENG", "HelloText"), playername, GetLangVar("ENG", "HelloText2"));  print(string);
  61.     // Hello, Peter, welcome to our server!
  62.  
  63.     format(string, sizeof(string), "%s%s%s", GetLangVar("JP", "HelloText"), playername, GetLangVar("JP", "HelloText2"));    print(string);
  64.     // Kon'nichiwa, Peter, Watashi-tachi no sâba e yôkoso!
  65. }
  66. */
  67.  
  68. stock GetLangVar(lang[256], langvar[50])
  69. /*
  70.     Example: You want the spanish Text stored in variable "Foo" (You must have "E.lang" or "Foo.lang" or whatever).
  71.     Use it like this:
  72.                         GetLangVar("ES",         "Foo")
  73.                                     ^ Language    ^ Variable
  74. */
  75. {
  76.     new string[80], key[256], Data[256];
  77.     format(string, sizeof(string), "Language/%s.lang", lang);
  78.     new File: LangFile = fopen(string, io_read);
  79.     string = "-[#]-";
  80.     if(LangFile)
  81.     {
  82.         while(fread(LangFile, Data, sizeof(Data)))
  83.         {
  84.             key = ini_GetKey(Data);
  85.             if(strfind(Data, "\n") != -1) { strdel(Data, strlen(Data)-1, strlen(Data)); }
  86.             if(strcmp(key, langvar, true) == 0)
  87.             {
  88.                 format(string, strlen(Data), "%s", ini_GetValue(Data)); break;
  89.             }
  90.         }
  91.         fclose(LangFile);
  92.     }
  93.     return string;
  94. }
  95.  
  96. stock ini_GetKey(line[])
  97. {
  98.     new keyRes[256]; keyRes[0] = 0;
  99.     if(strfind(line, "=", true) == -1) return keyRes;
  100.     strmid(keyRes, line, 0, strfind(line, "=", true), sizeof(keyRes)); return keyRes;
  101. }
  102.  
  103. stock ini_GetValue(line[])
  104. {
  105.     new valRes[256]; valRes[0]=0;
  106.     if(strfind(line, "=", true) == -1) return valRes;
  107.     strmid(valRes, line, strfind(line, "=", true)+1, strlen(line), sizeof(valRes)); return valRes;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement