Text and asset localization for UdonSharp, split out of LCGUdonSharp. It needs only the VRChat Worlds SDK’s own UdonSharp; LCGUdonSharp is optional.
Unity String and Asset Tables bake into Udon, with direct manager calls, dropdowns, callbacks, Smart variables/choose/plural, sprite/texture/audio/prefab variants and fallback. A legacy JSON table workflow is also included.
Import LCG Localization Examples from Package Manager, then see UnityLocalization.md in the sample for setup. Menus are under Tools > LCG Localization.
Add Tools > LCG Localization > Create Unity Manager to your scene, then assign the manager to a public field. Add using UdonSharp;, which is where the LCG* classes live.
using UdonSharp;
using UnityEngine;
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
public class ShopSign : UdonSharpBehaviour
{
public LCGLocalization localization;
public LCGLocalizedText priceText;
private void Start()
{
Debug.Log(localization.Get("hello"));
Debug.Log(localization.GetOrDefault("maybe_missing", "Fallback text"));
}
// Button: switch this player's language. Returns false for an unsupported code.
public void UseThai() { localization.SetLanguage("th"); }
// For Smart Strings such as "{price} coins".
public void SetPrice(int price)
{
localization.SetVariable("price", price.ToString()); // every text on this manager
priceText.SetVariable("price", price.ToString()); // one text; the name must already be listed on it
}
// Add this behaviour to the manager's Language Changed Targets.
public void LocalizationChanged()
{
Debug.Log("Now using " + localization.CurrentLanguage);
}
}
| Manager member | Purpose |
|---|---|
Get(key) | Translation, or the key when missing |
GetOrDefault(key, fallback) | Translation, or fallback when missing |
GetWithVariables(key, fallback, names, values) | Translation with one-off Smart variables |
SetLanguage(code) | Select a language and stop following the client language |
NextLanguage() | Cycle through languages |
FollowClientLanguage() | Return to VRChat’s selected language |
CurrentLanguage, GetLanguages() | Read the current language or all languages |
SetVariable(name, value) | Set a shared Smart variable and refresh all text |
Language choice is local to each player. It is not synced or saved between visits.
If your script is in its own assembly definition, reference LogicCuteGuy.LCGLocalization.Runtime and give that assembly a U# assembly definition.
From LCGUdonSharp 0.3.x: install this package alongside LCGUdonSharp 0.4.0. Scripts keep their GUIDs and the UdonSharp namespace, so existing scenes stay bound.
com.logiccuteguy.lcglocalization
Undefined
0.1.0
2022.3 or later
No legacy packages
LogicCuteGuy