/// <summary> /// Load LocalisationData files /// </summary> public static void Load(LocalisationConfiguration localisationConfiguration = null) { if (LocalisationData != null) { return; } Reload(localisationConfiguration); }
/// <summary> /// Load LocalisationData files /// </summary> public static void Reload(LocalisationConfiguration localisationConfiguration = null) { Clear(); if (localisationConfiguration == null) { localisationConfiguration = GameManager.LoadResource <LocalisationConfiguration>("LocalisationConfiguration"); } //localisationConfiguration = GameObject.FindObjectOfType<LocalisationConfiguration>(); var setupMode = localisationConfiguration == null ? LocalisationConfiguration.SetupModeType.Auto : localisationConfiguration.SetupMode; string[] loadedSupportedLanguages = new string[0]; // set localisation data if (setupMode == LocalisationConfiguration.SetupModeType.Auto) { // Try to load the default Localisation file directly - don't use GameMangager method as we load in 'reverse' as user items // should overwrite system ones. var asset = Resources.Load <LocalisationData>("Default/Localisation"); if (asset != null) { LocalisationData = ScriptableObject.Instantiate(asset); // create a copy so we don't overwrite values. loadedSupportedLanguages = asset.GetLanguageNames(); } // try and load identifier localisation if specified and present, or if not user localisation var identifierLocalisationLoaded = false; if (GameManager.IsActive && GameManager.GetIdentifierBase() != null) { asset = Resources.Load <LocalisationData>(GameManager.GetIdentifierBase() + "/Localisation"); if (asset != null) { identifierLocalisationLoaded = true; if (LocalisationData == null) { LocalisationData = asset; } else { LocalisationData.Merge(asset); } loadedSupportedLanguages = asset.GetLanguageNames(); // override any previous } } if (!identifierLocalisationLoaded) { asset = Resources.Load <LocalisationData>("Localisation"); if (asset != null) { if (LocalisationData == null) { LocalisationData = asset; } else { LocalisationData.Merge(asset); } loadedSupportedLanguages = asset.GetLanguageNames(); // override any previous } } if (LocalisationData == null) { MyDebug.LogWarning("GlobalLocalisation: No localisation data was found so creating an empty one. Please check that a localisation files exist at /Resources/Localisation or /Resources/Default/Localisation!"); } } else if (setupMode == LocalisationConfiguration.SetupModeType.Specified) { foreach (var localisationData in localisationConfiguration.SpecifiedLocalisationData) { // first item gets loaded / copied, subsequent get merged into this. if (LocalisationData == null) { LocalisationData = ScriptableObject.Instantiate(localisationData); // create a copy so we don't overwrite values. } else { LocalisationData.Merge(localisationData); } loadedSupportedLanguages = localisationData.GetLanguageNames(); // if exists override } if (LocalisationData == null) { MyDebug.LogWarning("GlobalLocalisation: No localisation data was found so creating an empty one. Please check that localisation files exist and are in the correct location!"); } } // if nothing loaded then create an empty localisation to avoid errors. if (LocalisationData == null) { LocalisationData = ScriptableObject.CreateInstance <LocalisationData>(); LocalisationData.AddLanguage("English", "en"); loadedSupportedLanguages = LocalisationData.GetLanguageNames(); } // set Supported Languages - either from config if present or based upon loaded files. if (localisationConfiguration != null && localisationConfiguration.SupportedLanguages.Length > 0) { List <string> validSupportedLanguages = new List <string>(); foreach (var language in localisationConfiguration.SupportedLanguages) { if (LocalisationData.ContainsLanguage(language)) { validSupportedLanguages.Add(language); } else { Debug.Log("GlobalLocalisation: Localisation files do not contain definitions for the specified supported language '" + language + "'"); } } SupportedLanguages = validSupportedLanguages.ToArray(); } else { SupportedLanguages = loadedSupportedLanguages; } // if no usable language is already set then set to the default language. if (!CanUseLanguage(Language)) { SetLanguageToDefault(); } }