Is Culture in C# equivalent to Locale in Java? - c#

C# uses the concept of Culture. Is this operationally similar to Locale in Java or are there significant differences in the underlying concepts?

Working in terms of Culture rather than Locale is an attempt at finding the correct level of abstraction — considering things in terms of groups of people who do things in similar ways, rather than talking about geographic areas and languages and somewhat derangedly thinking those correspond reliably to sets of cultural conventions.
They're similar in intent, just "Culture" is trying to find the abstraction sweet spot that "Locale" dramatically missed.

I am not particularly familiar with Java, but from what I can tell CultureInfo is roughly equivalent Locale in Java.
In short, it provides functionalty for formatting of numbers and dates, writing systems, string sorting and calendar functionality according to regional rules, regional meaning a combination of language or language and geographical region (and in some cases language, geographical region and alphabet).

Related

Full string comparison rules in C#

Where do I find the exact and complete string comparison rules for a certain culture in C#?
Example:
With StringComparer.InvariantCulture the strings "Masse" and "Maße" are equal.
There needs to be list of rules.
There have been similar questions, like:
Difference between InvariantCulture and Ordinal string comparison
This explains the concepts and gives examples. But I would like to have the source where the actual rules are defined.
For C#, this has historically varied depending on which version and flavor of C# and what OS you're running on.
Olivier's comment is an excellent current source of information: Behavior changes when comparing strings on .NET 5+.
I expect this unification of C# on all platforms based on ICU to be stable.
ICU is an API that is driven by data from the Unicode CLDR project. So the precise mappings and equivalences in your example are ultimately derived from CLDR.

Is it ok to use a default UI language other than English in C#?

We have started to work on a C# project that was originally created by German speaking developers for German users. Most of the code, including class names, comments and debug messages is written in German and so is the user interface. As one of our major goals is globalization, we decided to leave the default language to German and add language resource libraries for other languages, including English, as any other option would have turned too costly in terms of time at first.
My question is: is this a good idea, or is it better to switch the default to US English at least for the user interface like everybody else is doing? Are there any drawbacks in using a default language other than US English?
Although there is no reason for the default to be English, the way I would approach this is to imagine what you want to happen when people visit the site from a place you don't have a translation for.
For example, all of your German speaking visitors can be given the German translation, and all of your US English speakers would get the US English translation, but what happens when an French speaker visits the site? Is it better for them to get German or English as a default?
You would need to think in these terms really and decide based on who you think need to support.
It should affect your German speakers if you had a different default as they should still get the German version.
There is nothing at all wrong with using a default language other than English. All the default language (culture, actually) does is supply resources for use when the current culture doesn't have them.
The text and image resources for the default language should be for the culture you intend to market to first - add others as time allows.

Translation and localization issue

Does Microsoft implementation of C# runtime offer some localization mechanism to translate common strings like Overflow, Stack overflow, Underflow, etc...
See the code below - it's a part of Mono and Mono itself has a Locale.GetText routine for making such translations.
// Added to avoid possible integer overflow.
if (inputOffset > inputBuffer.Length - inputCount)
throw new ArgumentException("inputOffset" +
Locale.GetText("Overflow");
Now - how is it done in Microsoft version of runtime and how can I use it, for example, to get the localized equivalent of Overflow without adding resource files?
.NET provides a framework that makes it easy to localize your content (ResourceManager) and while it internally maintains some translations for its own purpose (for example DateTime.ToString gives you a textual representation for the date/time that is locally appropriate, which includes the translated month and day names), it does not provide you with any ready-made translations, be they common strings or not. It could hardly do this reliably anyway, as there is a plethora of human languages out there and words can have different translations depending on context etc.
In your example, I would say that you are OK with untranslated exception messages. Although Microsoft recommends that you localize exception descriptions and they do localize their own (at least for major languages), this advice seems ill-thought at it's not only a waste of effort to translate all this text that users probably should never see, but it can make debugging a nightmare.
Yes, it does and it's a terrible idea. It makes debugging so much harder.
without adding resource files
What do you have against resource files? Resources are the prescribed way to provide localized and localizable strings, images, and other data for a .NET app or assembly.
Note that single word substitution as shown in your example code will result in poor quality translations. Different languages have different sentence structure and word order which your single word substitution won't accommodate. Non-English languages often involve genders for nouns and declension of words to properly reflect their role and number in a phrase. Single word substitution fails miserably at this.
Your non-English customers will most likely prefer that you not butcher their language by attempting to partially translate text a word here and a word there. If you're going to go to the trouble of supporting localizable messages, do it right and allow the entire string to be translated so that word ordering and declension can be done properly by translators. In cases where the content is variable, make the format string a resource so that the translator can set off the variable data using the conventions of the language.

Why isn't there a culture enum?

Greetings,
I was wondering why there isn't a pre-set enum for cultures in C#?
Since the cultures never change and are always like "nl-NL, en-GB, en-US".. why not make a enum for it to make things just a little bit easy'r ?
[edit]
As stated cultures do change.. but not all. Why not make a enum / class type which holds all the cultures and gives the possibility to add / change them ?
"Since the cultures never change"
Don't they? This article (Microsoft .NET Framework 4: What is New in Globalization) disagrees. In the past 5 years alone, a lot has changed in the region of Serbia for example, leading to new Cultures.
In the real world, the globalization information is constantly changing because of cultural developments in the local markets, because of new standards which update the culture sensitive information frequently, or because Microsoft finds more accurate information about different markets or expands into more markets.
Microsoft .NET Framework 4 supports a minimum of 354 cultures compared to a minimum of 203 cultures in the previous release. Many of those cultures are neutrals that were added to complete the parent chain to the root neutral culture.
For example, three Inuktitut neutrals were added to the already existing cultures Inuktitut (Syllabics, Canada) and Inuktitut (Latin, Canada)
Also, I guess an enum itself does not make sense. A CultureInfo is much more than just a name, and a lookup offers more flexibility and independence from any political changes, of which there are many more than we usually realize.
Enumerations are fixed at compile time.
But the set of cultures varies at runtime:
Different OS versions support different cultures
OS updates (Service Packs, Language Interface Packs, ...) can add cultures
Later .NET versions support more cultures (build assembly for one version and use it with another).
They do change, albeit slowly. In any case, they predate C#, so making them into an enum at this point would be kludgery. Like making POSIX system calls into an enum, which I did in postForth, but knew it was wrong when I did it.
In addition to them changing, as suggested by others, you can create your own cultures and they would be conspicuously absent from the enum since you can't add items to it.

Globalization in C#

Can somebody explain to me what is the use of globalization in C#?
Is it used for conversion purposes? I mean I want to convert any English word into a selected language.
So will this globalization or cultureinfo help me?
Globalization is a means of formatting text for specific cultures. E.g. a string representation of the number 1000 may be 1,000.00 for the UK or 1'000,00 for France. It is quite an in depth subject but that is the essential aim.
It is NOT a translation service, but it does allow you to determine the culture under which your application is running and therefore allow you to choose the language you want to display. You will have to provide text translation yourself, however, usually by means of resource files.
Globalization is a way of allowing the user to customize the application that he or she may be using to fit the standards where they may be. Cusomtization allows for the:
Money Formatting
Time
Date
Text orientation
To be culturally appropriate. The region that is currently set is handled by the OS and passed to your application. Globalization/Internationalization(I18n) also typically motivates the developer to separate the displayed text of the program from the implementation its self.
From MSDN:
System.Globalization - contains
classes that define culture-related
information, including the language,
the country/region, the calendars in
use, the format patterns for dates,
currency and numbers, and the sort
order for strings.
This assembly helps in making your application culture-aware, and is used heavily internally within the .NET framework. For example, when converting from Date to String, Globalization is used to determine what format to use, such as "11/28/2009" or "28-11-2009". Generally this determination is done automatically within the framework without you ever using the assembly directly. However, if you need to, you can use Globalization directly to look up culture-specific information for your own use.
To clear even more confusion
Localization (or Localisation for non-US people), L10n for short: process of adapting program for a specific location. It consist of translating resources, adapting UI (if necessary), etc.
Internationalization, i18n for short: process of adapting program to support localization, regional characters, formats and so on and so forth, but most importantly, the process of allowing program to work correctly regardless of current locale settings and OS language version.
Globalization, g11n for short: consist of both i18n and L10n.
To clear some confusion:
Globalisation: Allowing your program to use locale specific resources loaded from an external resource DLL at runtime. This means putting all your strings in resource files rather than hard coding them into the source code.
Localisation: Adapting your program for a specific locale. This could be translating Strings and making dialog boxes read right-to-left for languages such as Arabic.
Here is a link to creating Satellite DLLs. Its says C++ but it the same principle applies to C#.
Globalization:-
Globalization is the process of designing and developing applications for multiple cultures regions.
Localization:-
Localization is the process of customizing application for a given culture and locale.

Categories