using System.Collections.Generic; using AnP.Types; using AnP.Utils; using AnP.Interfaces.Application; namespace AnP.Managers{ public class I18NManager{ private static readonly Dictionary> DEFAULT_SENTENCES = new Dictionary>{ {"english", new Dictionary{ {"greeting", new I18NSentenceType.Text("Hello, World!")} }} }; private static readonly Options GET_OPTIONS = new Options(); public AnPInterface anp; private Dictionary> sentences; private string language; private string default_language; public I18NManager(AnPInterface anp){ this.anp = anp; sentences = new Dictionary>(DEFAULT_SENTENCES); language = default_language = "english"; } public string get(object strings, object? inputs = null, object? languages = null, int custom_options = 0){ List keys = Common.get_keys(strings); Options options = new Options(custom_options, GET_OPTIONS); if(keys.Count != 0){ List languages_used = new List(); foreach(string language in Common.get_keys(languages).Concat( new List{this.language, default_language} ).Concat(sentences.Keys)) if(!languages_used.Contains(language)){ languages_used.Add(language); if(sentences.ContainsKey(language)) foreach(string key in keys) if(sentences[language].ContainsKey(key)) return sentences[language][key] switch{ I18NSentenceType.Text text => text.value, I18NSentenceType.List list => string.Join("", list.value), _ => "" }; } }; return Common.get_strings(strings).FirstOrDefault() ?? ""; } public void add(object? items, int custom_options = 0){} } }