पता लगाने के लिए अपने आवेदन स्थानीय बनाना करने की कोशिश में असमर्थ है, मैं यहां दिए गए चरणों का पालन किया है:स्थानीयकरण काम नहीं कर रहा - संसाधन फ़ाइल
स्टार्टअप: https://docs.asp.net/en/latest/fundamentals/localization.html
यहाँ मेरी कोड है .cs
public List<IRequestCultureProvider> RequestCultureProviders { get; private set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
services.AddOptions();
services.AddTransient<IViewRenderingService, ViewRenderingService>();
services.AddTransient<IEmailSender, EmailSender>();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory())),
EnableDirectoryBrowsing = true
});
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("fr"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures,
RequestCultureProviders = new List<IRequestCultureProvider>
{
new QueryStringRequestCultureProvider
{
QueryStringKey = "culture",
UIQueryStringKey = "ui-culture"
}
}
});
}
MyController.cs
public class MyController : Controller
{
private readonly IViewRenderingService _viewRenderingService;
private IStringLocalizer<MyController> _localizer;
private MyOptions _options;
//Constructor for dependency injection principle
public MyController(IViewRenderingService viewRenderingService, IStringLocalizer<MyController> localizer, IOptions<MyOptions> options)
{
_viewRenderingService = viewRenderingService;
_localizer = localizer;
_options = options.Value;
}
[HttpGet]
public string Get()
{
// _localizer["Name"]
return _localizer["Product"];
}
}
*.resx
फ़ाइल नाम Controllers.MyController.fr.resx
(जो "उत्पाद" प्रविष्टि मौजूद होती है) के साथ Resources
फ़ोल्डर में संग्रहीत किया जाता है।
हालांकि, यह संसाधन फ़ाइल नहीं ढूंढ पा रहा है, और "उत्पाद" कभी फ्रेंच में वापस नहीं आ जाता है।
localhost:3333/my?culture=fr
भी देखें,
@Localizer["Product"]
रिटर्न "उत्पाद" में
: मैं क्वेरी स्ट्रिंग का उपयोग कर रहा है, तो यहां क्वेरी स्ट्रिंग है।
क्या कोई मुझे याद रखने में मदद कर सकता है?
संपादित करें:
कुछ जांच के बाद, मैंने पाया कि संस्कृति बदल रही है, लेकिन यह संसाधन फ़ाइल पता लगाने में असमर्थ है। मैं वीएस2015 का उपयोग कर रहा हूँ। क्या कोई मदद कर सकता है?
फ्रांस के लिए संस्कृति स्ट्रिंग 'fr-FR' –
@JK है। फिर भी वही परिणाम और यदि आपने प्रदान किया गया लिंक चेक किया है, तो उन्होंने केवल "fr" संस्कृति का भी उपयोग किया है। – genericuser
क्या आपने यह पता लगाया है कि समस्या क्या है? – Simon