Exemple #1
0
        public XElement ExportXml()
        {
            return(new XElement("Type",
                                new XAttribute("Name", Type.Name),

                                !Options.IsSetAssert(DescriptionOptions.Description, Type) ||
                                Description == null ||
                                (Assembly.IsDefault && Description == DescriptionManager.DefaultTypeDescription(Type)) ? null :
                                new XAttribute("Description", Description),

                                !Options.IsSetAssert(DescriptionOptions.PluralDescription, Type) ||
                                PluralDescription == null ||
                                (PluralDescription == NaturalLanguageTools.Pluralize(Description, Assembly.Culture)) ? null :
                                new XAttribute("PluralDescription", PluralDescription),

                                !Options.IsSetAssert(DescriptionOptions.Gender, Type) ||
                                Gender == null ||
                                (Gender == NaturalLanguageTools.GetGender(Description, Assembly.Culture)) ? null :
                                new XAttribute("Gender", Gender.ToString()),

                                !Options.IsSetAssert(DescriptionOptions.Members, Type) ? null :
                                (from m in GetMembers(Type)
                                 where DescriptionManager.OnShouldLocalizeMember(m)
                                 orderby m.Name
                                 let value = Members.TryGetC(m.Name)
                                             where value != null && !(Assembly.IsDefault && (DescriptionManager.DefaultMemberDescription(m) == value))
                                             select new XElement("Member", new XAttribute("Name", m.Name), new XAttribute("Description", value)))
                                ));
        }
Exemple #2
0
        public void ExportXml()
        {
            var doc = ToXml();

            string fileName = TranslationFileName(Assembly, Culture);

            doc.Save(fileName);

            DescriptionManager.Invalidate();
        }
Exemple #3
0
        public static DescriptionOptions GetDescriptionOptions(Type type)
        {
            var doa = type.GetCustomAttribute <DescriptionOptionsAttribute>(true);

            if (doa != null)
            {
                return(type.IsGenericTypeDefinition ? doa.Options & DescriptionOptions.Members : doa.Options);
            }

            DescriptionOptions?def = DescriptionManager.OnDefaultDescriptionOptions(type);

            if (def != null)
            {
                return(type.IsGenericTypeDefinition ? def.Value & DescriptionOptions.Members : def.Value);
            }

            return(DescriptionOptions.None);
        }
Exemple #4
0
        internal static LocalizedType ImportXml(Type type, DescriptionOptions opts, LocalizedAssembly assembly, XElement x)
        {
            string description = !opts.IsSetAssert(DescriptionOptions.Description, type) ? null :
                                 (x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("Description")?.Value) ??
                                 (!assembly.IsDefault ? null : DescriptionManager.DefaultTypeDescription(type));

            var xMembers = x == null ? null : x.Elements("Member")
                           .Select(m => KVP.Create(m.Attribute("Name").Value, m.Attribute("Description").Value))
                           .Distinct(m => m.Key)
                           .ToDictionary();

            LocalizedType result = new LocalizedType
            {
                Type     = type,
                Options  = opts,
                Assembly = assembly,

                Description       = description,
                PluralDescription = !opts.IsSetAssert(DescriptionOptions.PluralDescription, type) ? null :
                                    ((x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("PluralDescription")?.Value) ??
                                     (!assembly.IsDefault ? null : type.GetCustomAttribute <PluralDescriptionAttribute>()?.PluralDescription) ??
                                     (description == null ? null : NaturalLanguageTools.Pluralize(description, assembly.Culture))),

                Gender = !opts.IsSetAssert(DescriptionOptions.Gender, type) ? null :
                         ((x == null ? null : x.Attribute("Gender")?.Value.Single()) ??
                          (!assembly.IsDefault ? null : type.GetCustomAttribute <GenderAttribute>()?.Gender) ??
                          (description == null ? null : NaturalLanguageTools.GetGender(description, assembly.Culture))),

                Members = !opts.IsSetAssert(DescriptionOptions.Members, type) ? null :
                          (from m in GetMembers(type)
                           where DescriptionManager.OnShouldLocalizeMember(m)
                           let value = xMembers?.TryGetC(m.Name) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultMemberDescription(m))
                                       where value != null
                                       select KVP.Create(m.Name, value))
                          .ToDictionary()
            };

            return(result);
        }
Exemple #5
0
 internal static string DefaultTypeDescription(Type type)
 {
     return(type.GetCustomAttribute <DescriptionAttribute>()?.Description ?? DescriptionManager.CleanTypeName(type).SpacePascal());
 }