translator.inc
Original include source with line numbers.
| 1 | /* AMX Mod X Backwards Compatibility |
| 2 | * |
| 3 | * by the AMX Mod X Development Team |
| 4 | * |
| 5 | * This file is provided as is (no warranties). |
| 6 | */ |
| 7 | |
| 8 | #if defined _amxmod_translator_included |
| 9 | #endinput |
| 10 | #endif |
| 11 | #define _amxmod_translator_included |
| 12 | |
| 13 | #define _translator_included |
| 14 | |
| 15 | #include <amxmodx> |
| 16 | #include <amxmod> |
| 17 | #include <amxmisc> |
| 18 | |
| 19 | //From AMX Mod. This is implemented in Core due to the nature of the |
| 20 | // translation engine and what AMX Mod did. |
| 21 | /* Translation backend, used by _T (since natives can't return arrays). */ |
| 22 | native translate(const string[], destid=-1, forcelang=-1); |
| 23 | |
| 24 | stock _T(const string[], destid=-1, forcelang=-1) |
| 25 | { |
| 26 | new TranslationResult[2] = {0, 0}; |
| 27 | TranslationResult[0] = translate(string, destid, forcelang); |
| 28 | return TranslationResult; |
| 29 | } |
| 30 | |
| 31 | stock load_translations(const file[]) |
| 32 | { |
| 33 | static dir[255], path[255]; |
| 34 | get_datadir(dir, 254); |
| 35 | |
| 36 | format(path, 254, "%s/amxmod-lang/%s.txt", dir, file); |
| 37 | new fp |
| 38 | if (!(fp=fopen(path, "r"))) |
| 39 | { |
| 40 | abort(AMX_ERR_NATIVE, "Could not find file: %s", path); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static buffer[1024]; |
| 45 | new lang[3]; |
| 46 | new TransKey:bad_key = TransKey:-1; |
| 47 | new TransKey:cur_key = bad_key; |
| 48 | new len; |
| 49 | while (!feof(fp)) |
| 50 | { |
| 51 | buffer[0] = 0; |
| 52 | fgets(fp, buffer, 1023); |
| 53 | len = strlen(buffer); |
| 54 | if (len == 0) |
| 55 | { |
| 56 | continue; |
| 57 | } |
| 58 | if (isspace(buffer[len-1])) |
| 59 | { |
| 60 | buffer[--len] = 0; |
| 61 | } |
| 62 | if (buffer[0] == '"') |
| 63 | { |
| 64 | remove_quotes(buffer); |
| 65 | cur_key = CreateLangKey(buffer); |
| 66 | AddTranslation("en", cur_key, buffer); |
| 67 | continue; |
| 68 | } |
| 69 | if (isspace(buffer[0])) |
| 70 | { |
| 71 | continue; |
| 72 | } |
| 73 | if ((cur_key != bad_key) && (buffer[2] == ':' && buffer[3] == '"')) |
| 74 | { |
| 75 | lang[0] = buffer[0]; |
| 76 | lang[1] = buffer[1]; |
| 77 | lang[2] = 0; |
| 78 | remove_quotes(buffer[3]); |
| 79 | AddTranslation(lang, cur_key, buffer[3]); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | fclose(fp); |
| 84 | |
| 85 | return 1; |
| 86 | } |
| 87 | |