Base solution for your next web application

Activities of "jeromevoxteneo"

Yeah didn't know about this existing attribute

It's working, I was tired and set a wrong key in the attribute key value :oops:

Do you have similar attribute for required and string length attributes that can be localized ?

Thank for the help

any idea ?

Hello,

I'm trying to make my custom attribute that extend DisplayNameAttribute to make it localized. But I cannot get the value from the languageTextManager nor from the localizationManager.

Here is my attribute for LocalizedDisplayName

using System;
using System.ComponentModel;
using System.Globalization;
using Abp.Dependency;
using Abp.Localization;
using Abp.Runtime.Session;

namespace iExpertise.Localization
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = false)]
    public class LocalizedDisplayNameAttribute : DisplayNameAttribute
    {
        private IApplicationLanguageTextManager _languageTextManager;
        private ILocalizationManager _localizationManager;
        //private IAbpSession _abpSession;
        private string _originalName;
        public LocalizedDisplayNameAttribute(string displayName)
            : base()
        {
            _originalName = displayName;
        }

        public override string DisplayName
        {
            get
            {
                if (_languageTextManager == null)
                {
                    _languageTextManager = IocManager.Instance.Resolve<IApplicationLanguageTextManager>();
                    _localizationManager = IocManager.Instance.Resolve<ILocalizationManager>();
                    //_abpSession = IocManager.Instance.Resolve<IAbpSession>();
                }
                var translation = _localizationManager.GetString(iExpertiseConsts.LocalizationSourceName,
                    _originalName);
                var translation2 = _languageTextManager.GetStringOrNull(null, iExpertiseConsts.LocalizationSourceName,
                    CultureInfo.CurrentCulture, _originalName);
                return translation;
            }
        }
    }
}

I put a breakpoint at the return translation and it results that: translation is [Task type id_Label] translation2 is null

I wanted to be sure that my key that was added in the xml file was ok, so I navigated to the languages list and see my entry and put a breakpoint inside of the EditTextModal of LanguagesController, the translation here is ok.

In PreInitialize method of Core module I have:

//Add/remove localization sources
            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    iExpertiseConsts.LocalizationSourceName,
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        Assembly.GetExecutingAssembly(),
                        "iExpertise.Localization.iExpertise"
                        )
                    )
                );

I cannot understand why my localization is ok in LanguagesController and not in my custom attribute in Core project.

Thanks for help

Showing 21 to 23 of 23 entries