core/smn_lang.cpp
author Borja Ferrer <faluco@alliedmods.net>
Thu Jul 05 14:47:36 2007 +0000 (2007-07-05)
changeset 1041 f7b2073013df
parent 1034 5ac2c40f13de
child 1105 ce907ba50921
permissions -rw-r--r--
added a time stamp argument to FormatTime
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include "PluginSys.h"
    16 #include "Translator.h"
    17 #include "LibrarySys.h"
    18 #include "sm_stringutil.h"
    19 
    20 static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
    21 {
    22 	char *filename;
    23 	unsigned int index;
    24 	CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext());
    25 
    26 	pCtx->LocalToString(params[1], &filename);
    27 
    28 	/* Check if there is no extension */
    29 	const char *ext = g_LibSys.GetFileExtension(filename);
    30 	if (!ext || (strcmp(ext, "cfg") && strcmp(ext, "txt")))
    31 	{
    32 		/* Append one */
    33 		static char new_file[PLATFORM_MAX_PATH];
    34 		UTIL_Format(new_file, sizeof(new_file), "%s.txt", filename);
    35 		filename = new_file;
    36 	}
    37 
    38 	index = g_Translator.FindOrAddPhraseFile(filename);
    39 	pl->AddLangFile(index);
    40 
    41 	return 1;
    42 }
    43 
    44 static cell_t sm_SetGlobalTransTarget(IPluginContext *pContext, const cell_t *params)
    45 {
    46 	g_SourceMod.SetGlobalTarget(params[1]);
    47 
    48 	return 1;
    49 }
    50 
    51 REGISTER_NATIVES(langNativeS)
    52 {
    53 	{"LoadTranslations",			sm_LoadTranslations},
    54 	{"SetGlobalTransTarget",		sm_SetGlobalTransTarget},
    55 	{NULL,							NULL},
    56 };