With different resource files (*.resx), how can I retrieve localized values by giving explicit localization.
That is, normally I can directly reference the attribute with custom-tool-namespace.Resource.localizedAttribute.
The value it will give depends on what localization has been set to CurrentCulture (thread-wise). But unlike this, I'd like to hand the localization to the resource getter. Is this possible?
Localizing Static Text If a page includes static text, you can use ASP.NET localization by including it in a Localize control, and then using explicit localization to set the static text. The Localize control renders no markup; its only function is to act as a placeholder for localized text.
App localization involves the following: Make the app's content localizable. Provide localized resources for the languages and cultures you support. Implement a strategy to select the language/culture for each request.
Assuming you have multiple resource files:
Messages.resx
Messages.fr-FR.resx
...
Messages.xx-XX.resx
all containing some string value you could retrieve the value for a specific culture:
var culture = new CultureInfo("fr-FR");
string value = Messages.ResourceManager.GetString("SomeKey", culture);
and this will be independently of the value of the current thread culture.
Better practice is to use nameof to mantain intellisense and avoid typing errors
var culture = new CultureInfo("fr-FR");
string value = Messages.ResourceManager.GetString(nameof(Messages.SomeKey), culture);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With