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

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

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

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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());
            }
        }
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    Yes it is the same.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    The value of the MyProjectConsts.LocalizationSourceName = "MyProject"

    Here is a screenshot of my project:

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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
    {
    }
       
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    @ryancyq Thanks the EmbeddedResource did the trick.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)