{"record":{"id":"9ef6c2ffbec1434c","repo":"EllanJiang/GameFramework","slug":"you-must-set-localization-helper-first","errorCode":null,"errorMessage":"You must set localization helper first.","messagePattern":"You must set localization helper first\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Localization/LocalizationManager.cs","lineNumber":64,"sourceCode":"                if (value == Language.Unspecified)\n                {\n                    throw new GameFrameworkException(\"Language is invalid.\");\n                }\n\n                m_Language = value;\n            }\n        }\n\n        /// <summary>\n        /// 获取系统语言。\n        /// </summary>\n        public Language SystemLanguage\n        {\n            get\n            {\n                if (m_LocalizationHelper == null)\n                {\n                    throw new GameFrameworkException(\"You must set localization helper first.\");\n                }\n\n                return m_LocalizationHelper.SystemLanguage;\n            }\n        }\n\n        /// <summary>\n        /// 获取字典数量。\n        /// </summary>\n        public int DictionaryCount\n        {\n            get\n            {\n                return m_Dictionary.Count;\n            }\n        }\n\n        /// <summary>","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Localization/LocalizationManager.cs#L46-L82","documentation":"The LocalizationManager.SystemLanguage property getter requires an ILocalizationHelper to have been installed via SetLocalizationHelper. The helper is the component that actually detects the OS/device language; without it there is no way to answer the query, so the manager throws. This is an initialization-order error.","triggerScenarios":"Reading localization.SystemLanguage before calling SetLocalizationHelper, e.g. querying it in Awake of another component that runs before the localization component initializes its helper.","commonSituations":"Script execution order issues in Unity where a consumer reads SystemLanguage before LocalizationComponent's Awake ran; forgetting to add the LocalizationComponent to the scene while calling the static Localization interface; creating a raw LocalizationManager manually and skipping helper setup.","solutions":["Ensure SetLocalizationHelper (or a LocalizationComponent in the scene) runs before any read of SystemLanguage.","Restructure initialization so consumers query SystemLanguage in Start or later, not before localization's Awake.","Check m_LocalizationHelper availability in your own wrapper before delegating to SystemLanguage."],"exampleFix":"// before\nvoid Awake() { var lang = Localization.SystemLanguage; } // helper not set yet\n\n// after\nvoid Start() // runs after LocalizationComponent.Awake set the helper\n{\n    var lang = Localization.SystemLanguage;\n}","handlingStrategy":"validation","validationCode":"if (LocalizationHelper == null)\n    Localization.SetLocalizationHelper(new DefaultLocalizationHelper());\nvar lang = Localization.SystemLanguage;","typeGuard":null,"tryCatchPattern":"try { lang = Localization.SystemLanguage; }\ncatch (GameFrameworkException ex) { Log.Error(\"Localization not initialized: \" + ex.Message); lang = Language.English; }","preventionTips":["Keep a LocalizationComponent in the scene so the helper is set during Awake.","Consume SystemLanguage only in Start or later, never before localization initialization.","Centralize helper setup in one bootstrap step of the GameFramework initialization sequence."],"tags":["localization","initialization-order","missing-dependency"],"backgroundTag":"missing-dependency","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}