GetLocalization: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Updated New items template)
Line 17: Line 17:
This example outputs simple ''Welcome'' message at the resource start (also when player joins the game if the resource is already running).
This example outputs simple ''Welcome'' message at the resource start (also when player joins the game if the resource is already running).
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local msg = {cs = "Vítejte", fr = "Accueil", de = "Willkommen", pl = "Powitanie"}
local msg = {cs = "Vítejte", fr = "Accueil", de = "Willkommen", pl = "Powitanie", hu = "Üdv"}


addEventHandler("onClientResourceStart", resourceRoot,  
addEventHandler("onClientResourceStart", resourceRoot,  

Revision as of 14:01, 29 September 2018

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)

See Also