Beispiel #1
0
        public static string Parse(string original, Dictionary <string, string> replace)
        {
            Dictionary <string, string> localizationStrings = new Dictionary <string, string>();


            try
            {
                localizationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(_provider.GetCurrentTranscript());
            }
            catch
            {
                localizationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(Utils.ReadAllText(Paths.GetPath("english.local"))); //if no provider fall back to english
            }

            foreach (var kv in localizationStrings.Where(x => original.Contains(x.Key)))
            {
                original = original.Replace(kv.Key, kv.Value); // goes through and replaces all the localization blocks
            }

            //string original2 = Parse(original);

            string usernameReplace = "";
            string domainReplace   = "";

            // if the user has saved then store their username and systemname in these string variables please
            if (SaveSystem.CurrentSave != null)
            {
                try
                {
                    usernameReplace = SaveSystem.CurrentUser.Username;
                }
                catch
                {
                    usernameReplace = "user";
                }

                try
                {
                    domainReplace = SaveSystem.CurrentSave.SystemName;
                }
                catch
                {
                    domainReplace = "system";
                }
            }

            string namespaceReplace = "";
            string commandReplace   = "";

            // if the user did a command in the terminal and it had a period in it then split it up into the part before the period and the part after and then store them into these two string variables please
            if (TerminalBackend.latestCommmand != "" && TerminalBackend.latestCommmand.IndexOf('.') > -1)
            {
                namespaceReplace = TerminalBackend.latestCommmand.Split('.')[0];
                commandReplace   = TerminalBackend.latestCommmand.Split('.')[1];
            }

            // if you see these then replace them with what you need to
            Dictionary <string, string> defaultReplace = new Dictionary <string, string>()
            {
                { "%username", usernameReplace },
                { "%domain", domainReplace },
                { "%ns", namespaceReplace },
                { "%cmd", commandReplace },
#if LOCALIZE_CODEPOINTS
                { "%cp", SaveSystem.CurrentSave?.Codepoints.ToString() },
#endif
            };

            // actually do the replacement
            foreach (KeyValuePair <string, string> replacement in replace.Where(x => original.Contains(x.Key)))
            {
                original = original.Replace(replacement.Key, Parse(replacement.Value));
            }

            // do the replacement but default
            foreach (KeyValuePair <string, string> replacement in defaultReplace.Where(x => original.Contains(x.Key)))
            {
                original = original.Replace(replacement.Key, replacement.Value);
            }

            return(original); // returns the now replaced string
        }
Beispiel #2
0
        public static string Parse(string original, Dictionary <string, string> replace)
        {
            Dictionary <string, string> localizationStrings = new Dictionary <string, string>();



            try
            {
                localizationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(_provider.GetCurrentTranscript());
            }
            catch
            {
                localizationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(Utils.ReadAllText(Paths.GetPath("english.local")));
            }

            foreach (var kv in localizationStrings)
            {
                original = original.Replace(kv.Key, kv.Value);
            }

            List <string> orphaned = new List <string>();

            if (Utils.FileExists("0:/dev_orphaned_lang.txt"))
            {
                orphaned = JsonConvert.DeserializeObject <List <string> >(Utils.ReadAllText("0:/dev_orphaned_lang.txt"));
            }


            int  start_index = 0;
            int  length      = 0;
            bool indexing    = false;

            foreach (var c in original)
            {
                if (c == '{')
                {
                    start_index = original.IndexOf(c);
                    indexing    = true;
                }

                if (indexing == true)
                {
                    length++;
                    if (c == '}')
                    {
                        indexing = false;
                        string o = original.Substring(start_index, length);
                        if (!orphaned.Contains(o))
                        {
                            orphaned.Add(o);
                        }
                        start_index = 0;
                        length      = 0;
                    }
                }
            }

            if (orphaned.Count > 0)
            {
                Utils.WriteAllText("0:/dev_orphaned_lang.txt", JsonConvert.SerializeObject(orphaned, Formatting.Indented));
            }

            //string original2 = Parse(original);

            string usernameReplace = "";
            string domainReplace   = "";

            if (SaveSystem.CurrentSave != null)
            {
                usernameReplace = SaveSystem.CurrentSave.Username;
                domainReplace   = SaveSystem.CurrentSave.SystemName;
            }

            string namespaceReplace = "";
            string commandReplace   = "";

            if (TerminalBackend.latestCommmand != "" && TerminalBackend.latestCommmand.IndexOf('.') > -1)
            {
                namespaceReplace = TerminalBackend.latestCommmand.Split('.')[0];
                commandReplace   = TerminalBackend.latestCommmand.Split('.')[1];
            }

            Dictionary <string, string> defaultReplace = new Dictionary <string, string>()
            {
                { "%username", usernameReplace },
                { "%domain", domainReplace },
                { "%ns", namespaceReplace },
                { "%cmd", commandReplace },
                { "%cp", SaveSystem.CurrentSave?.Codepoints.ToString() },
            };

            foreach (KeyValuePair <string, string> replacement in replace)
            {
                original = original.Replace(replacement.Key, Parse(replacement.Value));
            }

            foreach (KeyValuePair <string, string> replacement in defaultReplace)
            {
                original = original.Replace(replacement.Key, replacement.Value);
            }

            return(original);
        }