{"record":{"id":"ccb7df4a9d8df8f5","repo":"nopSolutions/nopCommerce","slug":"titlerequiredlocale-localized-formatted-with-l","errorCode":null,"errorMessage":"{titleRequiredLocale} (localized, formatted with languageName)","messagePattern":"(.+?) \\(localized, formatted with languageName\\)","errorType":"validation","errorClass":"NopException","httpStatus":null,"severity":"warning","filePath":"src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceService.cs","lineNumber":275,"sourceCode":"    #region Methods\n\n    /// <summary>\n    /// Validates title and text\n    /// </summary>\n    /// <param name=\"languageName\">Target language name</param>\n    /// <param name=\"textRequiredLocale\">Locale for raising an exception about the title field required</param>\n    /// <param name=\"titleRequiredLocale\">Locale for raising an exception about the text field required</param>\n    /// <param name=\"title\">Title for validate</param>\n    /// <param name=\"text\">Text for validate</param>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the validated title and text\n    /// </returns>\n    public virtual async Task<(string title, string text)> ValidateTitleAndTextAsync(string languageName,\n        string textRequiredLocale, string titleRequiredLocale, string title, string text)\n    {\n        if (string.IsNullOrEmpty(title))\n            throw new NopException(string.Format(await _localizationService.GetResourceAsync(titleRequiredLocale), languageName));\n\n        if (!string.IsNullOrEmpty(text))\n            text = Regex.Replace(text, \"<.*?>\", string.Empty);\n\n        if (string.IsNullOrEmpty(text))\n            throw new NopException(string.Format(await _localizationService.GetResourceAsync(textRequiredLocale), languageName));\n\n        return (title, text);\n    }\n\n    /// <summary>\n    /// Create product description by artificial intelligence\n    /// </summary>\n    /// <param name=\"productName\">Product name</param>\n    /// <param name=\"keywords\">Features and keywords</param>\n    /// <param name=\"toneOfVoice\">Tone of voice</param>\n    /// <param name=\"instruction\">Special instruction</param>\n    /// <param name=\"customToneOfVoice\">Custom tone of voice (applicable only for ToneOfVoiceType.Custom)</param>","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceService.cs#L257-L293","documentation":"ValidateTitleAndTextAsync throws NopException when 'title' is null or empty. The message is a localized resource (titleRequiredLocale) formatted with languageName, e.g. 'Admin.ArtificialIntelligence.ProductNameRequired'. This guards AI generation so it never runs without source text to base output on.","triggerScenarios":"Calling CreateMetaTags/CreateProductDescription flows where the entity's title/name field (localized or not) resolves to an empty string — e.g. a Product with no Name, a BlogPost with no Title, in the target language.","commonSituations":"Generating meta tags for a new product/category/topic that has no name yet; localized entity missing the name in the target language (languageId resolves to empty); passing languageId that has no localized value.","solutions":["Ensure the entity has a non-empty title/name in the target language before requesting AI meta generation.","Pre-check the localized name: if empty, prompt the user to fill it rather than invoking AI.","Validate the chosen languageId resolves to a language that has the localized name."],"exampleFix":"// before\nvar (t,k,d) = await _aiService.CreateMetaTagsAsync(entity, languageId); // throws if name empty\n\n// after\nvar name = languageId == 0 ? entity.Name : await _localizationService.GetLocalizedAsync(entity, e => e.Name, languageId, false);\nif (string.IsNullOrWhiteSpace(name))\n    return; // skip AI generation until name is set","handlingStrategy":"validation","validationCode":"var name = languageId == 0\n    ? entity.Name\n    : await _localizationService.GetLocalizedAsync(entity, e => e.Name, languageId, false);\nif (string.IsNullOrWhiteSpace(name))\n    // do not call AI meta generation; prompt user to set the name\n    return;","typeGuard":"static bool HasTitleInLanguage<TEntity>(TEntity entity, int languageId, Func<TEntity,string> sel, ILocalizationService loc) where TEntity:BaseEntity,ILocalizedEntity\n{\n    var v = languageId == 0 ? sel(entity) : loc.GetLocalizedAsync(entity, sel, languageId, false).GetAwaiter().GetResult();\n    return !string.IsNullOrWhiteSpace(v);\n}","tryCatchPattern":"try { await _aiService.CreateMetaTagsAsync(entity, languageId); }\ncatch (NopException ex) { /* title missing — prompt user to fill the name field */ }","preventionTips":["Require a non-empty name/title in the target language before exposing AI generation.","Validate localized fields per language before invoking AI.","Show inline validation on the name field before the AI button is enabled."],"tags":["ai","validation","localization","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}