string resource is not working properly

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 anos atrás
I am trying to add Confirm Email field to Register form. Nop is not displaying proper title for that it shows
"Account.Fields.ConfirmEmail" as the title on Register form.


In RegisterModel.cs I have added the following field

        [NopResourceDisplayName("Account.Fields.ConfirmEmail")]
        [AllowHtml]
        public string ConfirmEmail { get; set; }

In Register.cshtml i have added the following block just below email

                    
                    <div class="inputs">
                        @Html.LabelFor(model => model.ConfirmEmail, new { }, ":")
                        @Html.EditorFor(model => model.ConfirmEmail)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.ConfirmEmail)
                    </div>

In defaultResources.public.nopres i have added the code under Account-->Fields

                  <LocaleResource Name="ConfirmEmail">
                    <Value>Confirm email</Value>
                  </LocaleResource>
10 anos atrás
The files defaultResources.public.nopres.xml and defaultResources.admin.nopres.xml are only used during install. Adding new resources to these files will not affect an already installed site.

You can add new locale string resources to an installed site via Admin > Configuration > Languages > click 'View string resources' for your language > click the 'Add new record' button at the top of the grid > enter values for the 'Resource name' and 'Value' columns and click the 'Insert' button.

Note that Resource names must be unique -an error is displayed if you try to enter a duplicate. You can find existing resources to edit via the funnel icon in the 'Resource name' and 'Value' columns' header.

.
1 ano atrás
---Install Resource using localization---
-----PluginDefaults for install resources----

public static string LANGUAGES_TEXT = "Language";

public static string LANGUAGES_TEXT_ENGLISH = "English";

public static string LOCALIZATION_RESOURCE_PATH = "~/Plugins/PluginSystemName/Localization/ResourceString/";

public static string ATTRIBUTE_TEXT_NAME = "Name";

/////Call below this method into a install method (using install feature)

private void InstallLocaleResources()
        {
            var languages = _languageService.GetAllLanguages(true);
            var defaultLanguage = languages.Where(x => x.Name == PluginDefaults.LANGUAGES_TEXT_ENGLISH).FirstOrDefault();
            //save resources
            var directoryPath = _fileProvider.MapPath(PluginDefaults.LOCALIZATION_RESOURCE_PATH);
            var pattern = $"*.{NopInstallationDefaults.LocalizationResourcesFileExtension}";
            foreach (var filePath in _fileProvider.EnumerateFiles(directoryPath, pattern))
            {
                using (var streamReader = new StreamReader(filePath))
                {
                    var languageNames = from name in XDocument.Load(filePath).Document.Descendants(PluginDefaults.LANGUAGES_TEXT)
                                        select name.Attribute(PluginDefaults.ATTRIBUTE_TEXT_NAME);
                    foreach (var languageName in languageNames)
                    {
                        var language = languages.Where(x => x.Name.ToLowerInvariant().Equals(languageName.Value,
                            StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                        if (language == null)
                            language = defaultLanguage;
                        _localizationService.ImportResourcesFromXml(language, streamReader);
                    }
                }
            }
        }

/////call this below method using button click from setting page

public IActionResult InstallResourceString()
        {
            var resourceStringPath = _fileProvider.MapPath(PluginDefaults.LOCALIZATION_RESOURCE_PATH +                 "ResourceString_en.nopres.xml");
            var englishLanguage = _languageService.GetAllLanguages(true).FirstOrDefault(x => x.Name == "English");

            try
            {
                using (var reader = new StreamReader(resourceStringPath, Encoding.UTF8))
                {
                    _localizationService.ImportResourcesFromXml(englishLanguage, reader);
                }
            }
            catch (Exception exc)
            {
                _notificationService.ErrorNotification(exc);
                return RedirectToAction("Configure");
            }

            _notificationService.SuccessNotification(_localizationService.GetResource                                   (PluginDefaults.CONFIGURATION_RESTORED_RESOURCES_NOTIFICATION));
            return RedirectToAction("Configure");
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.