示例#1
0
        private static string GenerateLanguageXml(Localization project, SupportedLanguage language, bool fillGaps)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<resources>");
            sb.AppendLine();

            sb.AppendLine(String.Format("<string id=\"lang_name\">{0}</string>", language.ToDisplayName()));
            sb.AppendLine(String.Format("<string id=\"lang_index\">{0}</string>", (int)language));
            sb.AppendLine();

            for (int i = 0; i < project.Terms.Count; i++)
            {
                string           langValue = null;
                LocalizationTerm term      = project.Terms.ElementAt(i);
                IOrderedEnumerable <LocalizationEntry> entries = project.Entries.Where(x => x.TermId == term.Id && x.Language == language).OrderBy(x => x.Accepted);

                if (entries.Any())
                {
                    LocalizationEntry lastAccepted = entries.LastOrDefault(x => !x.Accepted.HasValue || x.Accepted == true);
                    if (lastAccepted != null)
                    {
                        langValue = lastAccepted.Value;
                    }
                }
                else
                {
                    if (fillGaps)
                    {
                        langValue = term.Value;
                    }
                }

                if (!string.IsNullOrWhiteSpace(langValue))
                {
                    sb.AppendLine(String.Format("<string id=\"{0}\">{1}</string>", term.Key, langValue));
                }
            }

            sb.AppendLine();
            sb.AppendLine("</resources>");

            return(sb.ToString());
        }