Skip to content

Instantly share code, notes, and snippets.

@michael-fa
Last active December 18, 2022 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michael-fa/c48b758742eecdfe21dc041fe95f57ed to your computer and use it in GitHub Desktop.
Save michael-fa/c48b758742eecdfe21dc041fe95f57ed to your computer and use it in GitHub Desktop.
samp-multilang-system
// @ GITHUB USER: SCROLL DOWN TO .MD FILE FOR INFO & 'DOCS'
// Dont know what to do? Like, defining the Languages (which's pretty easy to me) or defined TextID's to read from file?
// Look at https://gist.github.com/michael-fa/c48b758742eecdfe21dc041fe95f57ed where this file probably came from!
// THIS SCRIPT NEEDS DINI2 TO WORK!
//ADD LANGUAGES HERE IF YOU WANT TO
enum Languages {
ENG,
GER
}
//This is the actual "ID" number
enum TextID {
SCM_BAN_WRONGPASSWORD //example define your own ones
}
//These are the text's keys (to identify each text) - INDEXES MUST BE THE SAME AS TextID ENUM
//but don' t need to be the same as TextID
new TEXT_KEYS[TextID][] = {
{"scm_ban_wrongpassword"} //example define your own ones
};
//native GetText(Languages:langid, TextID:msgid, bIsDialog = false, readWhat = 1);
stock GetText(Languages:langid, TextID:msgid, bIsDialog = false, readWhat = 1)
{
new the_string[500];
if(bIsDialog)
{
new cont[500];
format(the_string, sizeof(the_string), "text/dialogs/");
switch(_:langid)
{
case ENG:format(the_string, 500, "%sen/%s.txt",the_string, TEXT_KEYS[msgid][0]);
case GER:format(the_string, 500, "%sde/%s.txt",the_string, TEXT_KEYS[msgid][0]);
}
new File:text = fopen(the_string, io_read);
if(!text)
{
printf(" [WARNING][FATAL] Dialog Translation %s (%s) not found, but used!", TEXT_KEYS[msgid][0], the_string);
strpack(the_string, "Dialog Language File not found, report to admin!");
return the_string;
}
//readout context
format(the_string, sizeof(the_string), "\0");
new _line = 0;
while(fread(text, cont))
{
switch(readWhat)
{
case 0: //Title
{
format(the_string, sizeof(the_string), "%s", cont);
if(_line == 0)break;
break;
}
case 1: //Content
{
if(_line != 0)
{
if(strfind(cont, "#button") != -1)continue;
format(the_string, sizeof(the_string), "%s%s", the_string, cont);
}
}
case 2: //Button0
{
if(strfind(cont, "#button0") != -1)
{
strdel(cont, 0, 8);
format(the_string, sizeof(the_string), "%s", cont);
break;
}
}
case 3: //Button 1
{
if(strfind(cont, "#button1") != -1){
format(the_string, sizeof(the_string), "%s", cont);
strdel(cont, 0, 7);
}
}
}
_line++;
}
fclose(text);
}
else
{
format(the_string, 16, "text/");
switch(_:langid)
{
case ENG:format(the_string, 16, "%sen.txt",the_string);
case GER:format(the_string, 16, "%sde.txt",the_string);
}
if(!dini_Exists(the_string))
{
printf(" [WARNING][FATAL] Language %s (%s) not found, but used!", the_string, #msgid);
strpack(the_string, "Language File not found, report to admin!");
return the_string;
}
if(!dini_Isset(the_string, TEXT_KEYS[msgid][0]))
{
printf(" [WARNING][FATAL] TEXT_KEY %s (%s) not found, but used!", TEXT_KEYS[msgid][0], the_string);
strpack(the_string, "TEXT in Language not found, report to admin!");
return the_string;
}
//strpack(dbgtext, the_string);
format(the_string, sizeof(the_string), dini_Get(the_string, TEXT_KEYS[msgid][0]));
}
return the_string;
}

Multilanguage System for SA-MP Servers

Needed: Dini2 (just include it in your main gamemode where this would get included in to)

Works easy by just including it and using GetText where a string needs to be translated. The idea mainly works for "static" Messages/Dialogs you send to your player.. and only these it's for.

⚠️ NO TEXTDRAW SUPPORT

(As far as of 15.12.19 a few days after creating: No testing so far, but should actually work flawless in TEXT mode (not DIALOG Mode)

How it works

Example: format(GetText(Languages:p1, int p2, int TEXT_TYPE, int p4)); NOTE: this is just to show you the types and does not work in pawn that way Description of params

  • p1: Language enum name - you define them yourself and use the current ones defined under LAGUAGES but if you pass numbers use ':' tag. Like ':0'
  • p2: Message ID (or enum name) - you define them yourself and use the current ones defined under TEXT_KEYS
  • TEXT_TYPE: (what kind of text to read? for dialog (..text/dialogs/), or single line string like.. (text/*.txt) ? (0 - 1)
  • p4: (Use if dialog only) What to read (int: 0 - 3) from 0=title to 3=BUTTON NO RESPONSE) 1 by default and will always return the dialog body

DIALOG SYSTEM

  • Uses "scriptfiles/text/" and "scriptfiles/text/dialogs" to read the whole dialog data from the file named like the TextID.
  • REMINDER: TextID (example: SCM_BAN_WRONGPASSWORD will be the dialog translation-file name)
  • One files holds the whole content like title and button text and it's stored there the following way:

Remember that this is just a description of how the lines inside a translation-file should look like! Titles MUST be in line 0 (the first) ! The buttons should be the last two lines but can be some lines between. DO NOT PUT THE BUTTON DEFINITIONS SOMEWHERE IN A LINE (between the words we read as content) '''BOF (dialogs/SCM_BAN_WRONGPASSWORD.txt)

     title line
     content can be how long you want it from now..
          like here a bit more
       and here
       
     and there
     
     and may  all the way                 
                           back here in the file..
     
     #button0deintext   // < right button v
     #button1deintext   // < left button button
     
     
     best songs 2019: take me back to london, fine (mike shinoda) and go check out bagpipes from bagdad lmao!

'''EOF the last line will be displayed in body part of dialog too.. we read out between the lines and only look for defines we really need, no matter where in the line!

only dialogs work in this way:

and a simple String of text is stored in text/YOUR_LANGUAGE.txt and from there you can define each TEXT_KEY to each string you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment