Skip to content

Localization

Eliot Partridge edited this page Dec 10, 2020 · 4 revisions

When developing a product, you want it to be accessible by as many users as possible, all around the world. Part of this accessibility stems from translating your addon into multiple different languages, so that users who don't speak your language can still enjoy the content you've created. That's where localization comes in. GMAU provides a simple localization framework, making it easy for developers and translators to provide multiple language support for their maps and extensions.

Using the localization system

If all you need to do is reference existing localization strings, then in most cases, you don't need to do much. For example, when referencing location labels in your map manifest or in entity keyvalues, you can simply reference the localization key of the string you wish to use, and the gamemode will automatically translate it into the appropriate language on the client if such a translation is available. For a list of the default available localization keys, see lang/au_default.moon.

If you're adding translations to a custom task or other custom UI element, you will need to call GAMEMODE.Lang:GetEntry (see sh_lang.moon) to translate the internal localization key into a human-readable format based on the client's chosen language. You only need to pass in the localization key you wish to translate; the gamemode will automatically choose the appropriate language based on the user's preference, and fall back to English if a translation isn't available. If no English translation is available for the provided string, the string itself will be returned instead, helping you quickly spot keys which need translating.

print(GAMEMODE.Lang:GetEntry("area.cafeteria"))
print(GAMEMODE.Lang:GetEntry("meeting.timer.begins")(1)) -- some localization entries are functions!

Adding new localization strings

If your addon requires new localization strings to be added, then you will need to at least populate the English translation for those strings. To provide an English translation for your localization strings, you will need a reference to the localization table for English, which can be fetched with GAMEMODE.Lang:Get, as shown below:

local LANG = GAMEMODE.Lang:Get('en')

Once you have this reference, you can insert new entries into this localization table simply by assigning new values into the table, like so:

LANG['area.outside'] = 'Outside'
LANG['task.sortSamples'] = 'Sort Samples'

Your custom language entries should be registered in a file under lua/amongus/lang/ (or gamemodes/amongus/gamemode/lang). Note that you can grab a reference to multiple language tables in the same file, if you'd rather keep all your translations under one file.

Translating localization strings into another language

If you speak a language other than English and would like to provide translations for the gamemode or a custom addon in your language, then you will need to edit or create a language file for the gamemode/addon. Once you have the file, simply grab a reference to the language table for the language you wish to provide translations for, using the method described above. The code you should use in place of 'en' is likely an ISO 639-1 code (although, you cna confirm by opening up Garry's Mod, switching your language to the appropriate language in the menu, and checking the value of the gmod_language convar in the developer console). Once you have a reference to the language localization table, simply add entries to the language table that match the format described above, making sure to use the same. For example:

local LANG = GAMEMODE.Lang:Get('es') -- Spanish/Español
LANG['area.communications'] = 'Comunicaciones'