Jump to content

Example of Mini Code For MultiLang


Recommended Posts

  • Honorable Member
Spoiler


#include "map"
enum Languages
{
	TR,
	EN,
	LANG_MAX,
	DEFAULT_LANG = TR, // change lang or use your multilang func example: GetLang()
};
auto Translate(string input, int lang)
{
	using namespace std;
	map<string, string> Langs[LANG_MAX];
	Langs[TR]["TESTSTRING"] = "[TR]Test multilang";
	Langs[EN]["TESTSTRING"] = "[EN]Test multilang";
   
	if (not(Langs[lang].count(input)) or lang >= LANG_MAX) {
		sys_err("Error in [%s], chat[%s]", __FUNCTION__, input.c_str());
		return "error";
	}
	/* test only
	auto Lang_Name = [](auto lang) -> string {
		return lang == TR ? "TR" : "EN";
	};
	for (auto exist_langs : {TR, EN})
		for (auto [inp,output] : Langs[exist_langs])
			cout << "Lang:[" << Lang_Name(exist_langs) << "] " << "input: " << inp << " output: " << output << endl;
	*/
			
	return Langs[lang][input].c_str();
}

 

Usage:

ChatPacket(CHAT_TYPE_INFO, Translate("TESTSTRING", DEFAULT_LANG));

 

  • Love 1

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.