GetLocalization: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Added small comment regarding changes after 1.6)
No edit summary
Line 29: Line 29:
end)
end)
</syntaxhighlight>
</syntaxhighlight>
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.
This is a list of all the language codes used in MTA in a table with the full name of the language.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
langTable = {
langTable = {
["ar"] = "Arabic",
["ar_SA"] = "Arabic",
["bg"] = "Bulgarian",
["az_AZ"] = "Azerbaijani",
["cs"] = "Czech",
["bg_BG"] = "Bulgarian",
["da"] = "Danish",
["bs_BA"] = "Bosnian",
["de"] = "German",
["cs_CZ= "Czech",
["da_DK"] = "Danish",
["de_DE"] = "German",
["en_US"] = "English",
["en_US"] = "English",
["el"] = "Greek",
["el_GR"] = "Greek",
["es"] = "Spanish",
["es_ES"] = "Spanish",
["et"] = "Estonian",
["et_EE"] = "Estonian",
["fr"] = "French",
["fa_IR"] = "Persian",
["hr"] = "Croatian",
["fi_FI"] = "Finnish",
["hu"] = "Hungarian",
["fil_PH"] = "Filipino",
["id"] = "Indonesian",
["fr_FR"] = "French",
["it"] = "Italian",
["he_IL"] = "Hebrew",
["ja"] = "Japanese",
["hi_IN"] = "Hindi",
["lt"] = "Lithuanian",
["hr_HR"] = "Croatian",
["lv"] = "Latvian",
["hu_HU"] = "Hungarian",
["mk"] = "Macedonian",
["id_ID"] = "Indonesian",
["nb"] = "Norwegian",
["it_IT"] = "Italian",
["nl"] = "Dutch",
["ja_JP"] = "Japanese",
["pt_BR"] = "Brazilian",
["ka_GE"] = "Georgian",
["pl"] = "Polish",
["ko_KR"] = "Korean",
["ru"] = "Russian",
["lt_LT"] = "Lithuanian",
["ro"] = "Romanian",
["lv_LV"] = "Latvian",
["sl"] = "Slovenian",
["mk_MK"] = "Macedonian",
["sv"] = "Swedish",
["nb_NO"] = "Norwegian",
["sk"] = "Slovak",
["nl_NL"] = "Dutch",
["tr"] = "Turkish",
["pt_BR"] = "Portuguese, Brazilian",
["uk"] = "Ukrainian",
["pt_PT"] = "Portuguese",
["vi"] = "Vietnamese",
["pl_PL"] = "Polish",
["zh_CN"] = "Chinese",
["ru_RU"] = "Russian",
["zh_TW"] = "Taiwanese",
["ro_RO"] = "Romanian",
["sl_SL"] = "Slovenian",
["sv_SE"] = "Swedish",
["sk_SK"] = "Slovak",
["srp"] = "Serbian",
["tr_TR"] = "Turkish",
["uk_UA"] = "Ukrainian",
["vi_VN"] = "Vietnamese",
["zh_CN"] = "Chinese Simplified",
["zh_TW"] = "Chinese Traditional",


}
}

Revision as of 12:51, 3 July 2023

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 the language codes used in MTA in a table with the full name of the language.

langTable = {
	["ar_SA"] = "Arabic",
	["az_AZ"] = "Azerbaijani",
	["bg_BG"] = "Bulgarian",
	["bs_BA"] = "Bosnian",
	["cs_CZ= "Czech",
	["da_DK"] = "Danish",
	["de_DE"] = "German",
	["en_US"] = "English",
	["el_GR"] = "Greek",
	["es_ES"] = "Spanish",
	["et_EE"] = "Estonian",
	["fa_IR"] = "Persian",
	["fi_FI"] = "Finnish",
	["fil_PH"] = "Filipino",
	["fr_FR"] = "French",
	["he_IL"] = "Hebrew",
	["hi_IN"] = "Hindi",
	["hr_HR"] = "Croatian",
	["hu_HU"] = "Hungarian",
	["id_ID"] = "Indonesian",
	["it_IT"] = "Italian",
	["ja_JP"] = "Japanese",
	["ka_GE"] = "Georgian",
	["ko_KR"] = "Korean",
	["lt_LT"] = "Lithuanian",
	["lv_LV"] = "Latvian",
	["mk_MK"] = "Macedonian",
	["nb_NO"] = "Norwegian",
	["nl_NL"] = "Dutch",
	["pt_BR"] = "Portuguese, Brazilian",
	["pt_PT"] = "Portuguese",
	["pl_PL"] = "Polish",
	["ru_RU"] = "Russian",
	["ro_RO"] = "Romanian",
	["sl_SL"] = "Slovenian",
	["sv_SE"] = "Swedish",
	["sk_SK"] = "Slovak",
	["srp"] = "Serbian",
	["tr_TR"] = "Turkish",
	["uk_UA"] = "Ukrainian",
	["vi_VN"] = "Vietnamese",
	["zh_CN"] = "Chinese Simplified",
	["zh_TW"] = "Chinese Traditional",

}

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