Base solution for your next web application
Open Closed

Add extra xml file #6759


User avatar
0
antonis created

Hi I have created an extra xml file for localisation. This was done to help me when updating aspnetzero to latest version to avoid losing changes to MyProject.xml language file.

I named this MyProjectExtended.xml

However I dont know how the aspnetzero will read this.

How can it be done?

Thanks in advance


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Are you talking about Extending Localization Sources? https://aspnetboilerplate.com/Pages/Documents/Localization#extending-localization-sources

  • User Avatar
    0
    antonis created

    I followed the instructions there but they are not very clear and I can't make it work

    namespace MyProject.Core.Extended
    {
        public class MyProjectCoreExtendedModule : AbpModule
        {
            public override void PreInitialize()
            {
                Configuration.Localization.Sources.Extensions.Add(
                    new LocalizationSourceExtensionInfo(MyProjectConsts.LocalizationSourceName,
                        new XmlEmbeddedFileLocalizationDictionaryProvider(Assembly.GetExecutingAssembly(),
                            "MyProject.Core.Extended.Localization.MyProject"
                        )
                    )
                );
            }
    
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(typeof(MyProjectCoreExtendedModule).GetAssembly());
            }
        }
    }
    
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, is your xml under MyProject.Core.Extended.Localization.MyProject having the same name as MyProjectConsts.LocalizationSourceName?

    The xml filename has to be the same as MyProjectConsts.LocalizationSourceName for the extension to work.

  • User Avatar
    0
    antonis created

    Yes it is the same.

  • User Avatar
    0
    ryancyq created
    Support Team

    please share the value of MyProjectConsts.LocalizationSourceName and the screenshot of the structure of MyProject.Core.Extended.Localization.MyProject in visual studio

  • User Avatar
    0
    antonis created

    The value of the MyProjectConsts.LocalizationSourceName = "MyProject"

    Here is a screenshot of my project:

  • User Avatar
    0
    ryancyq created
    Support Team

    have you added the xml as embedded resource?

    in your MyProject.Core.Extended.csproj

    <ItemGroup>
        <EmbeddedResource Include="Localization\MyProject\*.xml" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
    </ItemGroup>
    

    also, you should add module dependency on your MyProjectCoreExtendedModule

    [DependsOn(typeof(MyProjectCoreModule))]
    public class MyProjectCoreExtendedModule : AbpModule
    {
    }
       
    
  • User Avatar
    0
    antonis created

    @ryancyq Thanks the EmbeddedResource did the trick.