Garry's Mod Wiki

Revision Difference

Addon_Localization#547578

<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. ## 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/` 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. * 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 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 ``` 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 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 ``` ## 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