Esempio n. 1
0
        public void LoadFromSource()
        {
            if (Source != null && string.IsNullOrEmpty(Language) == false)
            {
                // Split file into lines, and loop through them all
                var lines = Source.text.Split(newlineCharacters, System.StringSplitOptions.RemoveEmptyEntries);

                for (var i = 0; i < lines.Length; i++)
                {
                    var line        = lines[i];
                    var equalsIndex = line.IndexOf(Separator);

                    // Only consider lines with the Separator character
                    if (equalsIndex != -1)
                    {
                        var title = line.Substring(0, equalsIndex).Trim();
                        var text  = line.Substring(equalsIndex + Separator.Length).Trim();

                        // Does this entry have a comment?
                        if (string.IsNullOrEmpty(Comment) == false)
                        {
                            var commentIndex = text.LastIndexOf(Comment);

                            if (commentIndex != -1)
                            {
                                text = text.Substring(0, commentIndex).Trim();
                            }
                        }

                        // Replace newline markers with actual newlines
                        if (string.IsNullOrEmpty(NewLine) == false)
                        {
                            text = text.Replace(NewLine, System.Environment.NewLine);
                        }

                        // Find or add the translation for this phrase
                        LeanLocalization.AddTranslationToFirst(title, Language, text);
                    }
                }

                // Update translations?
                if (LeanLocalization.CurrentLanguage == Language)
                {
                    LeanLocalization.UpdateTranslations();
                }
            }
        }