Open Closed

Bug in Localization logic causes feature management to fail #8169


User avatar
0
ahmednfwela@bdaya-dev.com created

The bug described here: https://github.com/abpframework/abp/issues/21191

Is causing our production app to fail Please provide us with a workaround until it's fixed


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks. I will check it asap.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to replace the ILocalizableStringSerializer with MyLocalizableStringSerializer?

    if (value.IsNullOrEmpty())
    {
        return new FixedLocalizableString(string.Empty);
    }
    
    if (value.Length < 3 ||
        value[1] != ':')
    {
        return new FixedLocalizableString(value);
    }
    
    using System;
    using Microsoft.Extensions.Options;
    using Volo.Abp.DependencyInjection;
    
    namespace Volo.Abp.Localization;
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(ILocalizableStringSerializer))]
    public class MyLocalizableStringSerializer : ILocalizableStringSerializer, ITransientDependency
    {
        protected AbpLocalizationOptions LocalizationOptions { get; }
    
        public MyLocalizableStringSerializer(IOptions<AbpLocalizationOptions> localizationOptions)
        {
            LocalizationOptions = localizationOptions.Value;
        }
    
        public virtual string? Serialize(ILocalizableString? localizableString)
        {
            if (localizableString == null)
            {
                return null;
            }
    
            if (localizableString is LocalizableString realLocalizableString)
            {
                return $"L:{realLocalizableString.ResourceName},{realLocalizableString.Name}";
            }
    
            if (localizableString is FixedLocalizableString fixedLocalizableString)
            {
                return $"F:{fixedLocalizableString.Value}";
            }
    
            throw new AbpException($"Unknown {nameof(ILocalizableString)} type: {localizableString.GetType().FullName}");
        }
    
        public virtual ILocalizableString Deserialize(string value)
        {
            if (value.IsNullOrEmpty())
            {
                return new FixedLocalizableString(string.Empty);
            }
    
            if (value.Length < 3 ||
                value[1] != ':')
            {
                return new FixedLocalizableString(value);
            }
    
            var type = value[0];
            switch (type)
            {
                case 'F':
                    return new FixedLocalizableString(value.Substring(2));
                case 'L':
                    var commaPosition = value.IndexOf(',', 2);
                    if (commaPosition == -1)
                    {
                        throw new AbpException("Invalid LocalizableString value: " + value);
                    }
    
                    var resourceName = value.Substring(2, commaPosition - 2);
                    var name = value.Substring(commaPosition + 1);
                    if (name.IsNullOrWhiteSpace())
                    {
                        throw new AbpException("Invalid LocalizableString value: " + value);
                    }
    
                    return LocalizableString.Create(name, resourceName);
                default:
                    return new FixedLocalizableString(value);
            }
        }
    }
    
    
  • User Avatar
    0
    ahmednfwela@bdaya-dev.com created

    I am using this right now and it solves my issue:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(LocalizableStringSerializer), typeof(ILocalizableStringSerializer), typeof(FixedLocalizableStringSerializer))]
    public class FixedLocalizableStringSerializer(IOptions<AbpLocalizationOptions> localizationOptions) : LocalizableStringSerializer(localizationOptions), ITransientDependency
    {
        public override ILocalizableString Deserialize(string? value)
        {
            if (value == null)
            {
                return new FixedLocalizableString("");
            }
            return base.Deserialize(value);
        }
    }
    

    is there a problem with my workaround ?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    No problem, Its same way.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://github.com/abpframework/abp/pull/21206

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11