GetLocalization

From Multi Theft Auto: Wiki
Revision as of 15:50, 14 June 2019 by Arran Fortuna (talk | contribs) (Added an incomplete (where do I find them?) table of language codes to their language)
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 many of but not all (please add more to this list) the language codes in a table with the full name of the language.

langTable = {
	["en_US"] = "English",
	["ru"] = "Russian",
	["ar"] = "Arabic",
	["es"] = "Spanish",
	["pt_BR"] = "Brazilian",
	["hu"] = "Hungarian",
	["de"] = "German",
	["pl"] = "Polish",
	["nl"] = "Dutch",
	["tr"] = "Turkish",
	["fr"] = "French",
	["hr"] = "Croatian",
	["sl"] = "Slovenian",
	["it"] = "Italian",
	["zh_CN"] = "Chinese",
	["ro"] = "Romanian",
	["nb"] = "Norwegian",
	["se"] = "Swedish",
	["el"] = "Greek",
	["lt"] = "Lithuanian",
	["id"] = "Indonesian",
	["vi"] = "Vietnamese",
	["bg"] = "Bulgarian",
	["sv"] = "Unknown", -- Google is saying Swedish but MTA uses "se" for that.
}

See Also