Garry's Mod Wiki

Revision Difference

Addon_Localization#528216

<cat>Dev</cat>⤶ ⤶ ## language.Add⤶ ⤶ languge.Add will add a localization string for the currently selected language. This is mainly used as a developer tool or when your addon only has 1 language. This method not suitable for multiple languages and changing language will reset all strings added by this function.⤶ ⤶ ## language.GetPhrase⤶ ⤶ This function allows you to retrieve a translated string given an "internal" untranslated one.⤶ ⤶ Most places you can also do `#your.string` which will be rendered as the translated string if a translation for it exists. This method will not work as a substring, that's where <page>language.GetPhrase</page> comes in useful.⤶ ⤶ ## .properties files⤶ ⤶ `.properties` files is how you are meant to localize your addons for multiple language. This is the system Garry's Mod itself uses. The language files will be loaded automatically based on which language the user has currently selected. English files are loaded before that regardless of which language is selected to fill potentially missing translations.⤶ ⤶ To set this system up for your addon is very simple, what you need to do is create `.properties` files in your addon's `resource/localization/` folder. The file and folder structure must follow the base game's usage, which is as follows:⤶ * `resource/localization/` will have folders for each supported language. This can be any number of languages out of a pre set list⤶ * Inside a language folder, for example `resource/localization/en/` you will create `.properties` files which contain translations in a key-value pairs format. The filename can be anything but should ideally represent name of your addon, be unique (the filesystem is not sandboxed and is therefore shared between all addons) and the filename should generally be the same in your addon for all languages.⤶ ⤶ The format of the file is very simple:⤶ * Lines starting with `#` are comments⤶ * Every line is treated as one string, separated by the `=` sigh⤶ ⤶ Here's an example of a language file:⤶ ```⤶ spawnmenu.content_tab=Spawnlists⤶ ⤶ spawnmenu.category.npcs=NPCs⤶ spawnmenu.category.addons=Addons⤶ spawnmenu.category.weapons=Weapons⤶ spawnmenu.category.postprocess=Post Process⤶ spawnmenu.category.your_spawnlists=Your Spawnlists⤶ spawnmenu.category.addon_spawnlists=Addon Spawnlists⤶ spawnmenu.category.games=Games⤶ spawnmenu.category.browse=Browse⤶ spawnmenu.category.entities=Entities⤶ spawnmenu.category.vehicles=Vehicles⤶ spawnmenu.category.creations=Creations⤶ spawnmenu.category.dupes=Dupes⤶ spawnmenu.category.saves=Saves⤶ ⤶ ```⤶ ⤶ In game these will be used as `#spawnmenu.content_tab` or `language.GetPhrase( "spawnmenu.content_tab" )`⤶ ⤶ You can find the built-in English localization here:⤶ https://github.com/Facepunch/garrysmod/tree/master/garrysmod/resource/localization/en⤶ ⤶ Of interest is the `community.properties` file, which contains a set of commonly used words by the Garry's Mod community, translated for you to every language the game supports.⤶ ⤶ `.properties` files also support "unicode" way of writing down characters:⤶ ```⤶ spawnmenu.content_tab=\u0421\u043f\u0438\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e⤶ ``` ⤶ ⤶ Below you will find a complete list of supported languages:⤶ * bg - Bulgarian⤶ * cs - Czech⤶ * da - Danish⤶ * de - German⤶ * el - Greek⤶ * en - English⤶ * en-PT - Pirate English⤶ * es-ES - Spanish⤶ * et - Estonian⤶ * fi - Finnish⤶ * fr - French⤶ * he - Hebrew⤶ * hr - Croatian ⤶ * hu - Hungarian⤶ * it - Italian⤶ * ja - Japanese⤶ * ko - Korean⤶ * lt - Lithuanian⤶ * nl - Dutch⤶ * no - Norwegian⤶ * pl - Polish⤶ * pt-BR - Portuguese, Brazillian⤶ * pt-PT - Portuguese⤶ * ru - Russian⤶ * sk - Slovak⤶ * sv-SE - Swedish⤶ * th - Thai⤶ * tr - Turkish⤶ * uk - Ukrainian⤶ * vi - Vietnamese⤶ * zh-CN - Chinese Simplified⤶ * zh-TW - Chinese Traditional