コード例 #1
0
        private LinkedListNode <ScriptTranslationFile> LoadFile(string fileName)
        {
            if (translationFileLookup.TryGetValue(fileName, out var node))
            {
                translationFileCache.Remove(node);
                translationFileCache.AddFirst(node);
                return(node);
            }

            if (translationFileCache.Count == Configuration.ScriptTranslations.MaxTranslationFilesCached.Value)
            {
                translationFileLookup.Remove(translationFileCache.Last.Value.FileName);
                translationFileCache.RemoveLast();
            }

            try
            {
                var file = new ScriptTranslationFile(fileName, translationFiles[fileName]);
                file.LoadTranslations();
                var result = translationFileCache.AddFirst(file);
                translationFileLookup.Add(fileName, result);
                return(result);
            }
            catch (Exception e)
            {
                Core.Logger.LogError(
                    $"Failed to load translations for file {fileName} because: {e.Message}. Skipping file...");
                translationFiles.Remove(fileName);
                return(null);
            }
        }
コード例 #2
0
        public override void LoadLanguage()
        {
            Core.Logger.LogInfo("Loading script translations");

            namesFile = null;
            translationFiles.Clear();
            translationFileCache.Clear();
            translationFileLookup.Clear();

            var files = Core.TranslationLoader.GetScriptTranslationFileNames();

            if (files == null)
            {
                Core.Logger.LogInfo("No script translation found! Skipping...");
                return;
            }

            foreach (var file in files)
            {
                var fileName = Path.GetFileNameWithoutExtension(file);
                if (translationFiles.ContainsKey(fileName))
                {
                    Core.Logger.LogWarning(
                        $"Script translation file {fileName} is declared twice in different locations ({file} and {translationFiles[fileName]})");
                    continue;
                }

                if (fileName == "__npc_names" && namesFile == null)
                {
                    namesFile = new ScriptTranslationFile(fileName, file);
                    namesFile.LoadTranslations();
                    continue;
                }

                translationFiles[fileName] = file;
            }
        }