S&box Wiki

Revision Difference

localization#548070

<cat>Code.Misc</cat>⤶ <cat>UI.Intro</cat>⤶ <title>Localization</title> # What Is Localization Instead of doing `label.Text = "Hello World"`, you do `label.Text = "#helloworld";`. This way you can use the localization system to change `#helloworld` into `こんにちは世界` if they have their language set to Japanese. # Tokens When doing UI stuff if you set a value to a string starting with `#` - it'll become a token, which means it'll look for its real value in the localization system. This works both when creating Panels using code and using templates. # Definitions To create your definitions create a folder in the root of your addon called `.localization`. Then inside that create a folder for the language. `en` is English. Then create a Json file inside that, which will hold your tokens. # Example Filename: `.localization\en\sandbox.json` ``` { "spawnmenu.props" : "models", "spawnmenu.entities" : "entities", "spawnmenu.cloudmodels": "asset.party", "spawnmenu.tools": "tools", "spawnmenu.utility": "utility" } ``` Then our code can do something like this.. ```csharp Add.Button( "#spawnmenu.utility" ); ``` # Languages For now there are two languages. English (en) and Pirate (en-pt). We'll add more languages on request and over time.