amateur
amateur

Reputation: 44635

What is the standard way to name a file based on CultureInfo?

Looking a recommendation for my criteria.

I need to create a file for different countries and looking at the best naming strategy for this.

I am working with .net 4.5. So example I need to create a file with Russian data, should it be named

rus_myfile.txt [ThreeLetterISOLanguageName]

ru_myfile.txt [TwoLetterISOLanguageName]

or another?

Is there any standard for naming conventions based on the .Net CultureInfo object? Any gotchas in this area?

Upvotes: 0

Views: 1275

Answers (2)

Larry
Larry

Reputation: 968

For the official naming convention rules of ".resx" files (which is really the standard), see http://msdn.microsoft.com/en-us/library/w24xty37(v=vs.100).aspx. If you want the "neutral" culture only, see "CultureInfo.Parent". You may want to have a look at "CultureInfo.IsNeutralCulture" as well (you may need it). You can even write a "CultureInfo" extension method if you want (to retrieve the neutral culture), but be careful if it's called on an instance of the invariant culture (maybe return null or an empty string in this case). Also, for Chinese, watch out for "zh-CHS" vs "zh-Hans" (both are "Chinese Simplified"), and "zh-CHT" vs "zh-Hant" (both are "Chinese Traditional"). The latter name in each case is the newer version, which MSFT changed from the old version in support of something called the IETF standard (don't ask). Both the old and new are still supported however (MSFT officially says to use the new name if you're able), so you may sometimes see the word "Legacy" appended when you invoke "CultureInfo.DislayName" (depending on the version of .NET you're using). Also be careful about which version of .NET you're using in general. New cultures are sometimes added, and there are significantly more in V4.0 compared to earlier versions, though not really mainstream ones. IOW, if you try to instantiate a "CultureInfo" by passing the culture name to its constructor, it might work on one version of .NET but throw an "ArgumentException" on another. This may or may not affect your particular app, but it's something to be aware of (it affects mine for instance).

Upvotes: 0

david.s
david.s

Reputation: 11403

You can follow the naming conventions for resource files (.resx):

<file basename>.<culture>.txt

Your example would look like this:

myfile.ru-RU.txt

Upvotes: 3

Related Questions