// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. #pragma warning disable 8632 // TODO: can be #nullable enable when Bindables are updated to also be. using osu.Framework.Bindables; namespace osu.Framework.Localisation { public partial class LocalisationManager { private class LocalisedBindableString : Bindable, ILocalisedBindableString { private IBindable parameters; private LocalisableString text; private readonly LocalisationManager manager; public LocalisedBindableString(LocalisableString text, LocalisationManager manager) { this.text = text; this.manager = manager; updateValue(); } private void updateValue() { switch (text.Data) { case string plain: Value = plain; break; case ILocalisableStringData data: if (parameters == null) { parameters = new Bindable(); parameters.BindTo(manager.currentParameters); parameters.BindValueChanged(_ => updateValue()); } Value = data.GetLocalised(parameters.Value); break; default: Value = string.Empty; break; } } LocalisableString ILocalisedBindableString.Text { set { if (text.Equals(value)) return; text = value; updateValue(); } } internal override void UnbindAllInternal() { base.UnbindAllInternal(); // optimisation to ensure cleanup happens aggressively. // without this, the central parameters bindable's internal WeakList can balloon out of control due to the // weak reference cleanup only occurring on Value retrieval (which rarely/never happens in this case). parameters?.UnbindAll(); } } } }