#include #include #include new Trie:dictionary; new lang[33]; new slang[130]; public plugin_precache(){ dictionary=TrieCreate(); } public register_translate(file[128]){ // registers multilang translations, because default amxx multilang sucks new dictionary_file[128], line[1024], len, key[130], translate[896], lang[3]; get_datadir(dictionary_file, 127); format(dictionary_file, 127, "%s/lang/%s", dictionary_file, file); if(file_exists(dictionary_file)){ for(new i=0; read_file(dictionary_file, i, line, 1023, len); ++i){ if(len && !equali(line, ";", 1) && !(len>=2 && equali(line, "/", 2))){ if(len>=4 && equali(line[0], "[", 1) && equali(line[3], "]", 1)){ copy(lang, 2, line[1]); } else { strtok(line, key, 127, translate, 895, '=', 1); if(equali(translate, "=", 1)){ copy(translate, 895, translate[1]); } trim(translate); add(key, 129, lang); TrieSetString(dictionary, key, translate); } } } } } public translate(id, key[128]){ new lng[130], translation[896]; if(id){ copy(lng, 127, key); add(lng, 129, lang[id]); id=TrieKeyExists(dictionary, lng); } if(!id){ copy(lng, 127, key); add(lng, 129, slang); } if(TrieKeyExists(dictionary, lng)){ TrieGetString(dictionary, lng, translation, 895); } else { copy(translation, 127, "ERR[MLNG]: No translation for "); add(translation, 895, key); log_error(AMX_ERR_NOTFOUND, translation); } return translation; }