Garry's Mod Wiki

Revision Difference

Addon_Localization#528529

<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. ⤶ <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. ## 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. ⤶ <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 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⤶ `.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/` folder. The file and folder structure must follow the base game's usage, which is as follows: ⤶ * `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/` - 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.⤶ 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" )` ⤶ 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` 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: `.properties` files also support the "unicode" way of writing 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⤶ ## 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⤶