Fluently Localizing Strings in .NET without using Resource Files

Igor Krupin
Nov 1 · 1 min read
Translation will be picked according to Thread.CurrentThread.CurrentCulture

Resource files are great, for larger blocks of text. Often, however, you have shorter pieces of text (such as labels, short sentences, etc) and you don’t want to go through the hassle of dealing with resource files. LocalizedString can help.

Using the library is simple. Define a variable and set the invariant text value. Then, you can add any additional translations, in-line. Calling ToString() method will return the translation according to the current Thread.CurrentThread.CurrentCulture value. If no appropriate translation can be found — the invariant value will be used, or the closest match.

If you’ve defined a translation for say 'FR-ca' and the current culture is 'FR', then'FR'translation will be used.

When using FluentValidation, you can further use LocalizedString.FluentValidation package to enable in-line translation definitions for error messages and fields.

Here’s and example usage with FluentValidation:

Example usage of FluentValidation /w LocalizedString.FluentValidation

- Enjoy responsibly!

Igor Krupin

Written by

Learner. Dreamer. Degustator of fine code.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade