using System; using System.Collections.ObjectModel; namespace Claunia.Localization.Core { /// /// Represent a localized string /// public sealed class LocalizedString { readonly ObservableCollection plurals; string comments; string locale; internal EventHandler Modified; string singular; int? translator; internal LocalizedString() { plurals = new ObservableCollection(); plurals.CollectionChanged += (sender, args) => Modified?.Invoke(this, EventArgs.Empty); Plurals = new ReadOnlyObservableCollection(plurals); } /// /// Contains the singular, or only, text for this string /// public string Singular { get => singular; set { singular = value; Modified?.Invoke(this, EventArgs.Empty); } } /// /// Which locale this string is in. Format is ll_CC with ll as ISO 639-2 language code and CC as ISO 3166 two letter /// uppercase country code. _CC can be omitted. /// public string Locale { get => locale; set { locale = value; Modified?.Invoke(this, EventArgs.Empty); } } /// /// ID of the translator, in this localization, that wrote this string /// public int? Translator { get => translator; set { translator = value; Modified?.Invoke(this, EventArgs.Empty); } } /// /// Translator comments /// public string Comments { get => comments; set { comments = value; Modified?.Invoke(this, EventArgs.Empty); } } /// /// Plural forms for this string /// public ReadOnlyObservableCollection Plurals { get; } /// /// Initializes a new plural in this message /// /// The newly initialized plural public Plural NewPlural() { Plural parameter = new Plural(); parameter.Modified += Modified; plurals.Add(parameter); return parameter; } /// /// Removes a plural /// /// The plural to remove /// true if the plural string has been removed successfully, false otherwise public bool RemovePlural(Plural parameter) => plurals.Remove(parameter); } }