示例#1
0
        /**
         * Implementation of StringSubstituter.ISubstitutionHandler.
         * Relaces tokens of the form {$KeyName} with the localized value corresponding to that key.
         */
        public virtual bool SubstituteStrings(StringBuilder input)
        {
            // This method could be called from the Start method of another component, so we
            // may need to initilize the localization system.
            Init();

            // Instantiate the regular expression object.
            Regex r = new Regex("{\\$.*?}");

            bool modified = false;

            // Match the regular expression pattern against a text string.
            var results = r.Matches(input.ToString());

            foreach (Match match in results)
            {
                string key = match.Value.Substring(2, match.Value.Length - 3);

                // Next look for matching localized string
                string localizedString = Localization.GetLocalizedString(key);
                if (localizedString != null)
                {
                    input.Replace(match.Value, localizedString);
                    modified = true;
                }
            }

            return(modified);
        }
示例#2
0
        public virtual string SubstituteVariables(string text)
        {
            string subbedText = text;

            // Instantiate the regular expression object.
            Regex r = new Regex("{\\$.*?}");

            // Match the regular expression pattern against a text string.
            var results = r.Matches(text);

            foreach (Match match in results)
            {
                string key = match.Value.Substring(2, match.Value.Length - 3);

                // Look for any matching variables in this Flowchart first (public or private)
                foreach (Variable variable in variables)
                {
                    if (variable.key == key)
                    {
                        string value = variable.ToString();
                        subbedText = subbedText.Replace(match.Value, value);
                    }
                }

                // Now search all public variables in all scene Flowcharts in the scene
                foreach (Flowchart flowchart in cachedFlowcharts)
                {
                    if (flowchart == this)
                    {
                        // We've already searched this flowchart
                        continue;
                    }

                    foreach (Variable variable in flowchart.variables)
                    {
                        if (variable.scope == VariableScope.Public &&
                            variable.key == key)
                        {
                            string value = variable.ToString();
                            subbedText = subbedText.Replace(match.Value, value);
                        }
                    }
                }

                // Next look for matching localized string
                string localizedString = Localization.GetLocalizedString(key);
                if (localizedString != null)
                {
                    subbedText = subbedText.Replace(match.Value, localizedString);
                }
            }

            return(subbedText);
        }
        public virtual string SubstituteVariables(string text)
        {
            string subbedText = text;

            // Instantiate the regular expression object.
            Regex r = new Regex("{\\$.*?}");

            // Match the regular expression pattern against a text string.
            var results = r.Matches(text);

            foreach (Match match in results)
            {
                string key = match.Value.Substring(2, match.Value.Length - 3);

                // Look for matching variable first
                foreach (Variable variable in variables)
                {
                    if (variable.key == key)
                    {
                        string value = variable.ToString();
                        subbedText = subbedText.Replace(match.Value, value);
                        return(subbedText);
                    }
                }

                // Next look for matching localized string
                string localizedString = Localization.GetLocalizedString(key);
                if (localizedString != null)
                {
                    subbedText = subbedText.Replace(match.Value, localizedString);
                    return(subbedText);
                }
            }

            return(subbedText);
        }