Garry's Mod Wiki

Revision Difference

Addon_Localization#548166

<cat>Dev</cat> ## language.Add <page>language.Add</page> will add a localization string for the user's currently selected language. This is mainly used as a developer tool, or for addons that use only 1 language. This method not suitable if you want to add localization strings for multiple languages. <page>language.Add</page> will add a localization string for the user's currently selected language. This is mainly used as a developer tool, or for addons that use only 1 language. This method is not suitable if you want to add localization strings for multiple languages. ## language.GetPhrase <page>language.GetPhrase</page> allows you to retrieve a translated string given an "internal" untranslated one. In most places, you can also write `"#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 handy. ## .properties files `.properties` files help developers localize addons for multiple languages. This is the same system that Garry's Mod uses. The language files will be loaded automatically based on the user's currently selected language. English (`en`) files are loaded before any other language in order to fill potentially missing translations. Setting this system up for your addon is very simple. What you need to do is create `.properties` files in your addon's [`resource/localization/`](https://github.com/Facepunch/garrysmod/tree/master/garrysmod/resource/localization) folder. The file and folder structure must follow the base game's usage, which is as follows: * [`resource/localization/`](https://github.com/Facepunch/garrysmod/tree/master/garrysmod/resource/localization) should have folders for each language code your addon supports. This can be any number of languages out of the predefined list at the bottom of this page. * Inside a language folder - for example, [`resource/localization/en/`](https://github.com/Facepunch/garrysmod/tree/master/garrysmod/resource/localization/en) - you should create `.properties` files, which contain translations in a key-value pairs format. The filename can be anything, but should ideally represent the name of your addon, be unique (the filesystem is not sandboxed and is therefore shared between all addons), and should generally be the same across all languages within your addon. The format of these `.properties` files is very simple: * Lines starting with `#` are comments. * Every line is treated as one string, with keys and values separated by the `=` sign. * The part that contains the key ( before the `=` sign ) must not contain spaces. * The first row must currently be left empty containing nothing whatsoever. Here's an example of such language file [`spawnmenu.properties`](https://github.com/Facepunch/garrysmod/blob/master/garrysmod/resource/localization/en/spawnmenu.properties) edited with [sublime text](https://www.sublimetext.com/): ``` | File | Edit | Selection | Find | View | Goto | Tools | Project | Preferences | Help | --------------------------------------------------------------------------------------- <>| spawnmenu.properties |_________________________________________________________ + V 1| H 2| spawnmenu.content_tab=Spawnlists H 3| H 3| spawnmenu.category.npcs=NPCs H 4| spawnmenu.category.addons=Addons | 5| spawnmenu.category.weapons=Weapons | 6| spawnmenu.category.postprocess=Post Process | 7| spawnmenu.category.your_spawnlists=Your Spawnlists | 8| spawnmenu.category.addon_spawnlists=Addon Spawnlists | 9| spawnmenu.category.games=Games | 10| spawnmenu.category.browse=Browse | 11| spawnmenu.category.entities=Entities | 12| spawnmenu.category.vehicles=Vehicles | 13| spawnmenu.category.creations=Creations | 14| spawnmenu.category.dupes=Dupes | 15| spawnmenu.category.saves=Saves | 16| ``` As an example, these can be used in game 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`](https://github.com/Facepunch/garrysmod/blob/master/garrysmod/resource/localization/en/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 [the unicode way](https://en.wikipedia.org/wiki/Unicode) of writing characters: ``` spawnmenu.content_tab=\u0421\u043f\u0438\u0441\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e ``` ## Supported languages Below you will find a complete list of supported languages: Code | Language| -----|---------| | `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 (Brazil) | `pt-PT` | Portuguese (Portugal) | `ru` | Russian | `sk` | Slovak | `sv-SE` | Swedish | `th` | Thai | `tr` | Turkish | `uk` | Ukrainian | `vi` | Vietnamese | `zh-CN` | Chinese Simplified | `zh-TW` | Chinese Traditional