GetLocalization

From Multi Theft Auto: Wiki
Revision as of 16:05, 28 June 2023 by Tracer (talk | contribs) (Added small comment regarding changes after 1.6)
Jump to navigation Jump to search

This function gets the player's localization setting as set in the MTA client.

Syntax

table getLocalization ( )

Returns

Returns a table with the following entries:

  • code : The language code (eg. "en_US" for "English (United States)" or "ar" for "Arabic").
  • name : The name of the language (eg. "English (United States)" or "Arabic").

Example

This example outputs simple Welcome message at the resource start (also when player joins the game if the resource is already running).

local msg = {cs = "Vítejte", fr = "Accueil", de = "Willkommen", pl = "Powitanie", hu = "Üdv"}

addEventHandler("onClientResourceStart", resourceRoot, 
	function ()
		local languageCode = getLocalization()["code"]
		if msg[languageCode] then --Check if the message is avaible in client's language
			outputChatBox(msg[languageCode] .. "!") --Output it
		else
			outputChatBox("Welcome!") --Output English for any other language
		end
	end)

This is a list of all (probably all) the language codes used in MTA in a table with the full name of the language. Note that when MTA 1.6 was released some of these have changed.

langTable = {
	["ar"] = "Arabic",
	["bg"] = "Bulgarian",
	["cs"] = "Czech",
	["da"] = "Danish",
	["de"] = "German",
	["en_US"] = "English",
	["el"] = "Greek",
	["es"] = "Spanish",
	["et"] = "Estonian",
	["fr"] = "French",
	["hr"] = "Croatian",
	["hu"] = "Hungarian",
	["id"] = "Indonesian",
	["it"] = "Italian",
	["ja"] = "Japanese",
	["lt"] = "Lithuanian",
	["lv"] = "Latvian",
	["mk"] = "Macedonian",
	["nb"] = "Norwegian",
	["nl"] = "Dutch",
	["pt_BR"] = "Brazilian",
	["pl"] = "Polish",
	["ru"] = "Russian",
	["ro"] = "Romanian",
	["sl"] = "Slovenian",
	["sv"] = "Swedish",
	["sk"] = "Slovak",
	["tr"] = "Turkish",
	["uk"] = "Ukrainian",
	["vi"] = "Vietnamese",
	["zh_CN"] = "Chinese",
	["zh_TW"] = "Taiwanese",

}

This function is useful for fixing any scripts that were made before MTA 1.6 as some of the language codes were changed.


function getLanguageCode(c)
	if (c == "fr_FR") then
		return "fr"
	elseif (c == "ru_RU") then
		return "ru"
	elseif (c == "pt_PT") then
		return "pt_BR"
	elseif (c == "pl_PL") then
		return "pl"
	elseif (c == "tr_TR") then
		return "tr"
	elseif (c == "es_ES") then
		return "es"
	elseif (c == "de_DE") then
		return "de"
	elseif (c == "vi_VN") then
		return "vi"
	elseif (c == "ar_SA") then
		return "ar"
	elseif (c == "bg_BG") then
		return "bg"
	elseif (c == "hu_HU") then
		return "hu"
	elseif (c == "ro_RO") then
		return "ro"
	elseif (c == "sv_SE") then
		return "sv"
	elseif (c == "hr_HR") then
		return "hr"
	elseif (c == "uk_UA") then
		return "uk"
	end
	return c
end

code = getLanguageCode(getLocalization().code)

See Also