Creating a custom CultureInfo program for a country, language combination

I am working on a .net 4.5 application which should be multilingual, supporting multiple cultures, etc.

Below is an example of a list of countries / languages

  • Russia russian
  • Belgium / French
  • Belgium / Holland

For all of the above, there is a CultureInfo object that can be created based on the names of the names of the culture

  • ru-RU
  • FR-BE
  • n-BE

When a user logs into the site, I install Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture in the culture created with the above names, for example.

Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE", false) Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE", false) 

All of the above names are valid cultural names.

No, however, I need to add another name for the culture, English in Russia. But the problem in the en-RU code is invalid, so when I create new CultureInfo("en-RU", false) , I get a CultureNotFoundException exception because en-RU is invalid.

With this culture, I want formatting, etc. Russia was occupied by numbers, dates, etc., but I want the language on the site to be English. Is it possible to create custom CultureInfo objects for invalid crop names with country behavior (Russia)?

+6
source share
3 answers

Is it possible to create custom CultureInfo objects for an invalid culture name

Yes.

Use CultureAndRegionInfoBuilder to create a custom CultureInfo . (NB. Once you have the code to create the culture, the settings for this can be saved in XML and then loaded, for example, from a resource that needs to have less code at runtime.)

+5
source

You may have to mix and mix and match - there is a cultural object for the English language that you use for text in English, but a cultural object ru-Ru (Russian) for numerical formatting.

Or even better, create a custom culture by combining the two

Create custom culture in ASP.NET

+4
source

You must use the CultureInfo.InvariantCulture Property

Invariant culture is insensitive to culture; This is due to the English language, but not in any country / region. You specify an invariant culture by name using an empty string ("") in the CultureInfo instance method call. Culture An investment culture extracts an instance of an invariant culture. It can be used in almost any method in the System.Globalization namespace that requires culture. Objects returned by properties such as CompareInfo, DateTimeFormat, and NumberFormat also reflect string comparison and invariant culture formatting conventions.

CultureInfo.InvariantCulture Property

This is another option. Custom Global Application Culture

0
source

Source: https://habr.com/ru/post/927853/


All Articles