diff --git a/Aaru.CommonTypes/AaruMetadata/ReleaseType.cs b/Aaru.CommonTypes/AaruMetadata/ReleaseType.cs index eb621518d..388f32e0a 100644 --- a/Aaru.CommonTypes/AaruMetadata/ReleaseType.cs +++ b/Aaru.CommonTypes/AaruMetadata/ReleaseType.cs @@ -41,6 +41,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; +using Aaru.Localization; namespace Aaru.CommonTypes.AaruMetadata; @@ -48,16 +49,28 @@ namespace Aaru.CommonTypes.AaruMetadata; [SuppressMessage("ReSharper", "InconsistentNaming")] public enum ReleaseType { + [LocalizedDescription(nameof(UI.ReleaseType_Retail))] Retail, + [LocalizedDescription(nameof(UI.ReleaseType_Bundle))] Bundle, + [LocalizedDescription(nameof(UI.ReleaseType_Coverdisc))] Coverdisc, + [LocalizedDescription(nameof(UI.ReleaseType_Subscription))] Subscription, + [LocalizedDescription(nameof(UI.ReleaseType_Demo))] Demo, + [LocalizedDescription(nameof(UI.ReleaseType_OEM))] OEM, + [LocalizedDescription(nameof(UI.ReleaseType_Shareware))] Shareware, + [LocalizedDescription(nameof(UI.ReleaseType_FOSS))] FOSS, + [LocalizedDescription(nameof(UI.ReleaseType_Adware))] Adware, + [LocalizedDescription(nameof(UI.ReleaseType_Donationware))] Donationware, + [LocalizedDescription(nameof(UI.ReleaseType_DigitalDownload))] DigitalDownload, + [LocalizedDescription(nameof(UI.ReleaseType_SaaS))] SaaS } \ No newline at end of file diff --git a/Aaru.Gui/Helpers/LocalizedEnumHelper.cs b/Aaru.Gui/Helpers/LocalizedEnumHelper.cs new file mode 100644 index 000000000..3fde32ec0 --- /dev/null +++ b/Aaru.Gui/Helpers/LocalizedEnumHelper.cs @@ -0,0 +1,90 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : LocalizedEnumHelper.cs +// Author(s) : Natalia Portillo +// +// Component : GUI helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Helper class for working with localized enum values. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General public License for more details. +// +// You should have received a copy of the GNU General public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2025 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using JetBrains.Annotations; + +namespace Aaru.Gui.Helpers; + +/// Helper class for working with localized enum values +public static class LocalizedEnumHelper +{ + /// Gets the localized description for an enum value + /// The enum value + /// The localized description, or the enum value's name if no description is found + [NotNull] + public static string GetLocalizedDescription([NotNull] Enum value) + { + FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); + + if(fieldInfo == null) return value.ToString(); + + var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); + + return attributes.Length > 0 ? attributes[0].Description : value.ToString(); + } + + /// Gets all values of an enum type wrapped with their localized descriptions + /// The enum type + /// A collection of LocalizedEnumValue wrappers + [NotNull] + public static IEnumerable> GetLocalizedValues() where T : struct, Enum + { + return Enum.GetValues().Select(static value => new LocalizedEnumValue(value)); + } +} + +/// Wrapper class for an enum value with its localized description +/// The enum type +public class LocalizedEnumValue where T : struct, Enum +{ + /// Initializes a new instance of the LocalizedEnumValue class + /// The enum value + public LocalizedEnumValue(T value) + { + Value = value; + Description = LocalizedEnumHelper.GetLocalizedDescription(value); + } + + /// Gets the enum value + public T Value { get; } + + /// Gets the localized description + public string Description { get; } + + /// Returns the localized description as the string representation + public override string ToString() => Description; +} \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/Windows/MetadataEditorViewModel.cs b/Aaru.Gui/ViewModels/Windows/MetadataEditorViewModel.cs index 35b809da7..045f25cf5 100644 --- a/Aaru.Gui/ViewModels/Windows/MetadataEditorViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MetadataEditorViewModel.cs @@ -37,6 +37,7 @@ using System.Linq; using System.Text.Json; using System.Threading.Tasks; using Aaru.CommonTypes.AaruMetadata; +using Aaru.Gui.Helpers; using Aaru.Gui.Localization; using Aaru.Localization; using Avalonia; @@ -128,7 +129,7 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase ObservableCollection _requiredOperatingSystems = []; [ObservableProperty] - ReleaseType? _selectedReleaseType; + LocalizedEnumValue _selectedReleaseType; [ObservableProperty] string _serialNumber; @@ -159,13 +160,14 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase // Available enum values for ComboBoxes [NotNull] - public IEnumerable AvailableReleaseTypes => Enum.GetValues(); + public IEnumerable> AvailableReleaseTypes => + LocalizedEnumHelper.GetLocalizedValues(); [NotNull] - public IEnumerable AvailableLanguages => Enum.GetValues(); + public IEnumerable AvailableLanguages => Enum.GetValues(); [NotNull] public IEnumerable AvailableArchitectures => Enum.GetValues(); [NotNull] - public IEnumerable AvailableBarcodeTypes => Enum.GetValues(); + public IEnumerable AvailableBarcodeTypes => Enum.GetValues(); void LoadMetadata([NotNull] string path) { @@ -179,12 +181,16 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase Metadata metadata = metadataJson.AaruMetadata; // Basic fields - Name = metadata.Name; - Version = metadata.Version; - SelectedReleaseType = metadata.Release; - ReleaseDate = metadata.ReleaseDate; - PartNumber = metadata.PartNumber; - SerialNumber = metadata.SerialNumber; + Name = metadata.Name; + Version = metadata.Version; + + SelectedReleaseType = metadata.Release.HasValue + ? new LocalizedEnumValue(metadata.Release.Value) + : null; + + ReleaseDate = metadata.ReleaseDate; + PartNumber = metadata.PartNumber; + SerialNumber = metadata.SerialNumber; // String lists LoadStringList(metadata.Developers, Developers); @@ -202,19 +208,16 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase // Complex objects if(metadata.Barcodes != null) - { - foreach(Barcode barcode in metadata.Barcodes) Barcodes.Add(new BarcodeViewModel(barcode)); - } + foreach(Barcode barcode in metadata.Barcodes) + Barcodes.Add(new BarcodeViewModel(barcode)); if(metadata.Magazines != null) - { - foreach(Magazine magazine in metadata.Magazines) Magazines.Add(new MagazineViewModel(magazine)); - } + foreach(Magazine magazine in metadata.Magazines) + Magazines.Add(new MagazineViewModel(magazine)); if(metadata.Books != null) - { - foreach(Book book in metadata.Books) Books.Add(new BookViewModel(book)); - } + foreach(Book book in metadata.Books) + Books.Add(new BookViewModel(book)); if(metadata.RequiredOperatingSystems != null) { @@ -223,39 +226,32 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase } if(metadata.UserManuals != null) - { - foreach(UserManual manual in metadata.UserManuals) UserManuals.Add(new UserManualViewModel(manual)); - } + foreach(UserManual manual in metadata.UserManuals) + UserManuals.Add(new UserManualViewModel(manual)); if(metadata.OpticalDiscs != null) - { - foreach(OpticalDisc disc in metadata.OpticalDiscs) OpticalDiscs.Add(new OpticalDiscViewModel(disc)); - } + foreach(OpticalDisc disc in metadata.OpticalDiscs) + OpticalDiscs.Add(new OpticalDiscViewModel(disc)); if(metadata.Advertisements != null) - { - foreach(Advertisement ad in metadata.Advertisements) Advertisements.Add(new AdvertisementViewModel(ad)); - } + foreach(Advertisement ad in metadata.Advertisements) + Advertisements.Add(new AdvertisementViewModel(ad)); if(metadata.LinearMedias != null) - { - foreach(LinearMedia media in metadata.LinearMedias) LinearMedias.Add(new LinearMediaViewModel(media)); - } + foreach(LinearMedia media in metadata.LinearMedias) + LinearMedias.Add(new LinearMediaViewModel(media)); if(metadata.PciCards != null) - { - foreach(Pci pci in metadata.PciCards) PciCards.Add(new PciViewModel(pci)); - } + foreach(Pci pci in metadata.PciCards) + PciCards.Add(new PciViewModel(pci)); if(metadata.BlockMedias != null) - { - foreach(BlockMedia media in metadata.BlockMedias) BlockMedias.Add(new BlockMediaViewModel(media)); - } + foreach(BlockMedia media in metadata.BlockMedias) + BlockMedias.Add(new BlockMediaViewModel(media)); if(metadata.AudioMedias != null) - { - foreach(AudioMedia media in metadata.AudioMedias) AudioMedias.Add(new AudioMediaViewModel(media)); - } + foreach(AudioMedia media in metadata.AudioMedias) + AudioMedias.Add(new AudioMediaViewModel(media)); } catch(Exception ex) { @@ -292,7 +288,7 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase { Name = Name, Version = Version, - Release = SelectedReleaseType, + Release = SelectedReleaseType?.Value, ReleaseDate = ReleaseDate, PartNumber = PartNumber, SerialNumber = SerialNumber, @@ -313,16 +309,13 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase RequiredOperatingSystems.Any() ? [..RequiredOperatingSystems.Select(static os => os.ToModel())] : null, - UserManuals = UserManuals.Any() ? [..UserManuals.Select(static um => um.ToModel())] : null, - OpticalDiscs = - OpticalDiscs.Any() ? [..OpticalDiscs.Select(static od => od.ToModel())] : null, - Advertisements = - Advertisements.Any() ? [..Advertisements.Select(static a => a.ToModel())] : null, - LinearMedias = - LinearMedias.Any() ? [..LinearMedias.Select(static lm => lm.ToModel())] : null, - PciCards = PciCards.Any() ? [..PciCards.Select(static p => p.ToModel())] : null, - BlockMedias = BlockMedias.Any() ? [..BlockMedias.Select(static bm => bm.ToModel())] : null, - AudioMedias = AudioMedias.Any() ? [..AudioMedias.Select(static am => am.ToModel())] : null + UserManuals = UserManuals.Any() ? [..UserManuals.Select(static um => um.ToModel())] : null, + OpticalDiscs = OpticalDiscs.Any() ? [..OpticalDiscs.Select(static od => od.ToModel())] : null, + Advertisements = Advertisements.Any() ? [..Advertisements.Select(static a => a.ToModel())] : null, + LinearMedias = LinearMedias.Any() ? [..LinearMedias.Select(static lm => lm.ToModel())] : null, + PciCards = PciCards.Any() ? [..PciCards.Select(static p => p.ToModel())] : null, + BlockMedias = BlockMedias.Any() ? [..BlockMedias.Select(static bm => bm.ToModel())] : null, + AudioMedias = AudioMedias.Any() ? [..AudioMedias.Select(static am => am.ToModel())] : null }; var metadataJson = new MetadataJson @@ -346,10 +339,7 @@ public sealed partial class MetadataEditorViewModel : ViewModelBase [ new FilePickerFileType(GUI.FileType_JSON) { - Patterns = - [ - "*.json" - ] + Patterns = ["*.json"] } ], DefaultExtension = "json" @@ -601,6 +591,7 @@ public sealed partial class BookViewModel : ObservableObject [ObservableProperty] string _editorial; + [ObservableProperty] string _name; @@ -610,6 +601,7 @@ public sealed partial class BookViewModel : ObservableObject [ObservableProperty] string _pageSize; + [ObservableProperty] DateTime? _publicationDate; diff --git a/Aaru.Localization/UI.Designer.cs b/Aaru.Localization/UI.Designer.cs index 0f593eaa8..43fe73798 100644 --- a/Aaru.Localization/UI.Designer.cs +++ b/Aaru.Localization/UI.Designer.cs @@ -6891,5 +6891,77 @@ namespace Aaru.Localization { return ResourceManager.GetString("AaruFormat_images_version_1_x_are_read_only", resourceCulture); } } + + public static string ReleaseType_Retail { + get { + return ResourceManager.GetString("ReleaseType_Retail", resourceCulture); + } + } + + public static string ReleaseType_Bundle { + get { + return ResourceManager.GetString("ReleaseType_Bundle", resourceCulture); + } + } + + public static string ReleaseType_Coverdisc { + get { + return ResourceManager.GetString("ReleaseType_Coverdisc", resourceCulture); + } + } + + public static string ReleaseType_Subscription { + get { + return ResourceManager.GetString("ReleaseType_Subscription", resourceCulture); + } + } + + public static string ReleaseType_Demo { + get { + return ResourceManager.GetString("ReleaseType_Demo", resourceCulture); + } + } + + public static string ReleaseType_OEM { + get { + return ResourceManager.GetString("ReleaseType_OEM", resourceCulture); + } + } + + public static string ReleaseType_Shareware { + get { + return ResourceManager.GetString("ReleaseType_Shareware", resourceCulture); + } + } + + public static string ReleaseType_FOSS { + get { + return ResourceManager.GetString("ReleaseType_FOSS", resourceCulture); + } + } + + public static string ReleaseType_Adware { + get { + return ResourceManager.GetString("ReleaseType_Adware", resourceCulture); + } + } + + public static string ReleaseType_Donationware { + get { + return ResourceManager.GetString("ReleaseType_Donationware", resourceCulture); + } + } + + public static string ReleaseType_DigitalDownload { + get { + return ResourceManager.GetString("ReleaseType_DigitalDownload", resourceCulture); + } + } + + public static string ReleaseType_SaaS { + get { + return ResourceManager.GetString("ReleaseType_SaaS", resourceCulture); + } + } } } diff --git a/Aaru.Localization/UI.es.resx b/Aaru.Localization/UI.es.resx index e7f4c6069..ae56f376d 100644 --- a/Aaru.Localization/UI.es.resx +++ b/Aaru.Localization/UI.es.resx @@ -3446,4 +3446,40 @@ Probadores: Las imágenes AaruFormat versión 1.x son de sólo lectura, conviértala primero a una versión más moderna. + + Comercial + + + Paquete + + + Disco de Portada + + + Suscripción + + + Demostración + + + OEM + + + Shareware + + + FOSS (Software Libre/Código Abierto) + + + Adware + + + Donationware + + + Descarga Digital + + + SaaS (Software como Servicio) + \ No newline at end of file diff --git a/Aaru.Localization/UI.resx b/Aaru.Localization/UI.resx index 65d466108..34fb5c847 100644 --- a/Aaru.Localization/UI.resx +++ b/Aaru.Localization/UI.resx @@ -3524,4 +3524,40 @@ Do you want to continue? AaruFormat images version 1.x are read-only, convert it to a newer version first. + + Retail + + + Bundle + + + Cover Disc + + + Subscription + + + Demo + + + OEM + + + Shareware + + + FOSS (Free/Open Source) + + + Adware + + + Donationware + + + Digital Download + + + SaaS (Software as a Service) + \ No newline at end of file diff --git a/Aaru.sln.DotSettings b/Aaru.sln.DotSettings index 4b458a120..3336dd61f 100644 --- a/Aaru.sln.DotSettings +++ b/Aaru.sln.DotSettings @@ -1,7 +1,4 @@ - + Null ExplicitlyExcluded @@ -1046,6 +1043,7 @@ True True True + True True True True