sourcemod icon indicating copy to clipboard operation
sourcemod copied to clipboard

FormatNativeString + translation

Open schmidt39 opened this issue 4 years ago • 4 comments

online translator*

If translation (%T %t) is present in "any ..." then the plugin-caller must do LoadTranslations (otherwise there will be an error). There is an awkward moment here: All translation is already in the plugin (native-creator) and I do not want plugins to constantly load translation (why, if it already exists). Your api doesn't allow use translation of the owner plugin, so this sounds like a suggestion for future updates. It seems that all I can do now is pass arguments in arrays, their number, types, and call VFormat + SetNativeString, but this is inconvenient.

schmidt39 avatar Dec 15 '20 16:12 schmidt39

There are no issues. Show the problematic code. Did you saw simple examples with SetGlobalTransTarget() here? https://forums.alliedmods.net/showthread.php?t=314844

After that, you just call:

CPrintToChatAll("%t", "your_phrase");
// or
CPrintToChat(client, "%t", "your_phrase");

dragokas avatar Dec 15 '20 20:12 dragokas

MyFormat.phrases.txt

"Phrases"
{
	"test_phrase"
	{
		"en" "abcdef"
	}
}

a.sp

public void OnPluginStart()
{
	LoadTranslations("MyFormat.phrases");
	ForceChangeLevel("de_dust2", "update phrases pls");
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	CreateNative("MyFormat", MyFormat_);
	return APLRes_Success;
}

// native bool MyFormat(char[] buffer, int size, const char[] format, any ...);
public int MyFormat_(Handle plugin, int args) {
	return FormatNativeString(1, 3, 4, GetNativeCell(2)) == SP_ERROR_NONE;
}

b.sp

native bool MyFormat(char[] buffer, int size, const char[] format, any ...);

public void OnPluginStart()
{
	char s[64];
	MyFormat(s, sizeof(s), "%T", "test_phrase", LANG_SERVER);
	PrintToServer(s);
}

Result: [SM] Exception reported: Language phrase "test_phrase" not found (arg 6)

I repeat the problem: I want to use the translation already contained in a.sp I don't want to write LoadTranslations("MyFormat.phrases"); in b.sp (but I must to do it if I want to use "any ...").

schmidt39 avatar Dec 15 '20 23:12 schmidt39

I don't think there's anything wrong with the current setup for translations. Plugins are expected to load translation files that contain the phrase(s) they want to use. It shouldn't be up to the plugin owning the native to provide the translation just for the sake of saving one line for other plugins.

Psykotikism avatar Dec 18 '20 00:12 Psykotikism

Yes, this is not a mistake, it is just discomfort. The logic says that since I execute the code at a.sp and return it to the caller, then I should be able to use my own translation, but in this case it is impossible. And since I hate non-logic, I reported it.

schmidt39 avatar Dec 18 '20 01:12 schmidt39