c# - Resourcemanager is returning same resource, although CultureInfo is specified -
a simple thing, , can't work. want globalise dll i'm using resource files + resourcemanager.
i call resourcemanager this:
var p = new resourcemanager("appname.default", assembly.getexecutingassembly()); get strings this
system.diagnostics.debug.writeline(p.getstring("greeting")); system.diagnostics.debug.writeline(p.getstring("greeting", new cultureinfo("nl"))); system.diagnostics.debug.writeline(p.getstring("greeting", new cultureinfo("nl-nl"))); system.diagnostics.debug.writeline(p.getstring("greeting", new cultureinfo("en"))); and returns 4 times same string. files called
default.resx default.en.resx default.nl.resx default.nl-nl.resx all file settings same, mentioned - resource in default file used.
what overlooking here?
there few ways of using resource files, 1 of using .resx files. these files localized automatically, based on value of thread.currentthread.currentuiculture. default .resx file gets compiled assembly part of (for example main executable), while localized resources (default.nl-nl.resx) compiled own directory (based on culture identifier, nl-nl in case) assembly, called <assemblyname>.resources.dll.
addressing values resources easy <resourcename>.<keyname>, example default.greeting. test it, change culture, using:
thread.currentthread.currentuiculture = cultureinfo.getcultureinfo("en-us"); console.writeline(default.greeting); thread.currentthread.currentuiculture = cultureinfo.getcultureinfo("nl-nl"); console.writeline(default.greeting); which output
hello hallo on program startup, ui culture set culture of computer it's running on, won't have specify language present localized resources. so, .resx files seem way go.
when using resourcemanager var p = new resourcemanager("appname.default", assembly.getexecutingassembly());, have read .resources files. if there no (in case) appname.default.resources file, p.getstring fail. guess have created 1 .resources file earlier, haven't converted localized .resx files .resources files.
if want use resourcemanager able specify culture, can use:
default.resourcemanager.getstring("greeting", new cultureinfo("en-us"));
Comments
Post a Comment