GetLocalization: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added an incomplete (where do I find them?) table of language codes to their language)
m (Converted language codes to a table (easier to fix/add new codes))
 
(10 intermediate revisions by 2 users not shown)
Line 29: Line 29:
end)
end)
</syntaxhighlight>
</syntaxhighlight>
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.
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_SA"] = "Arabic",
["az_AZ"] = "Azerbaijani",
["bg_BG"] = "Bulgarian",
["bs_BA"] = "Bosnian",
["cs_CZ"] = "Czech",
["da_DK"] = "Danish",
["de_DE"] = "German",
["en_US"] = "English",
["en_US"] = "English",
["ru"] = "Russian",
["el_GR"] = "Greek",
["ar"] = "Arabic",
["es_ES"] = "Spanish",
["es"] = "Spanish",
["et_EE"] = "Estonian",
["pt_BR"] = "Brazilian",
["fa_IR"] = "Persian",
["hu"] = "Hungarian",
["fi_FI"] = "Finnish",
["de"] = "German",
["fil_PH"] = "Filipino",
["pl"] = "Polish",
["fr_FR"] = "French",
["nl"] = "Dutch",
["he_IL"] = "Hebrew",
["tr"] = "Turkish",
["hi_IN"] = "Hindi",
["fr"] = "French",
["hr_HR"] = "Croatian",
["hr"] = "Croatian",
["hu_HU"] = "Hungarian",
["sl"] = "Slovenian",
["id_ID"] = "Indonesian",
["it"] = "Italian",
["it_IT"] = "Italian",
["zh_CN"] = "Chinese",
["ja_JP"] = "Japanese",
["ro"] = "Romanian",
["ka_GE"] = "Georgian",
["nb"] = "Norwegian",
["ko_KR"] = "Korean",
["se"] = "Swedish",
["lt_LT"] = "Lithuanian",
["el"] = "Greek",
["lv_LV"] = "Latvian",
["lt"] = "Lithuanian",
["mk_MK"] = "Macedonian",
["id"] = "Indonesian",
["nb_NO"] = "Norwegian",
["vi"] = "Vietnamese",
["nl_NL"] = "Dutch",
["bg"] = "Bulgarian",
["pt_BR"] = "Portuguese, Brazilian",
["sv"] = "Unknown", -- Google is saying Swedish but MTA uses "se" for that.
["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",
 
}
}
</syntaxhighlight>
<!-- Or... just update the scripts? Why complicate everything? -->
This function is useful for fixing any scripts that were made before MTA 1.6 as some of the language codes were changed.
<syntaxhighlight lang="lua">
local languageCodes = {
['ar_SA'] = 'ar',
['bg_BG'] = 'bg',
['da_DK'] = 'da',
['de_DE'] = 'de',
['el_GR'] = 'el',
['es_ES'] = 'es',
['fr_FR'] = 'fr',
['hr_HR'] = 'hr',
['hu_HU'] = 'hu',
['id_ID'] = 'id',
['it_IT'] = 'it',
['lt_LT'] = 'lt',
['nb_NO'] = 'nb',
['nl_NL'] = 'nl',
['pl_PL'] = 'pl',
['pt_PT'] = 'pt_BR',
['ro_RO'] = 'ro',
['ru_RU'] = 'ru',
['sl_SL'] = 'sl',
['sv_SE'] = 'sv',
['tr_TR'] = 'tr',
['uk_UA'] = 'uk',
['vi_VN'] = 'vi',
}
function getLanguageCode(c)
return languageCodes[c] or c
end
code = getLanguageCode(getLocalization().code)
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 11:56, 28 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.

local languageCodes = {
	['ar_SA'] = 'ar',
	['bg_BG'] = 'bg',
	['da_DK'] = 'da',
	['de_DE'] = 'de',
	['el_GR'] = 'el',
	['es_ES'] = 'es',
	['fr_FR'] = 'fr',
	['hr_HR'] = 'hr',
	['hu_HU'] = 'hu',
	['id_ID'] = 'id',
	['it_IT'] = 'it',
	['lt_LT'] = 'lt',
	['nb_NO'] = 'nb',
	['nl_NL'] = 'nl',
	['pl_PL'] = 'pl',
	['pt_PT'] = 'pt_BR',
	['ro_RO'] = 'ro',
	['ru_RU'] = 'ru',
	['sl_SL'] = 'sl',
	['sv_SE'] = 'sv',
	['tr_TR'] = 'tr',
	['uk_UA'] = 'uk',
	['vi_VN'] = 'vi',
}

function getLanguageCode(c)
	return languageCodes[c] or c
end

code = getLanguageCode(getLocalization().code)

See Also