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.
Related
So i understand how to filter values on gremlin console but things like filter, gt etc dont work on gremlin.net. continuously get errors.
I would like to know how to use Filter in gremlin.net to filter out nodes or edges. I cant find documentation pertaining to how to do this in C# using the gremlin.net library
I tried writing the code i write on gremlin console but some of those functions were not recognized
I am trying to filter out all those nodes that have the property idnum greater than 5
: g.V().Has("idnum", gt(5));
it keeps saying gt is not found under the current context.
Gremlin is largely the same regardless of the programming language you use. There are typically only minor differences in syntax as it relates to the idioms of the programming language itself (e.g. in Java we typically see the initial letter in method names lower cased whereas in C# they are upper cased). So, the general step documentation, though demonstrated in Groovy/Java style, typically gives you enough information on how steps work for you to then translate to your language of choice. Also in that same documentation, where necessary, there are specific notes on programming language specific differences that may be relevant.
That said, I assume your issue is related to the importing of P.gt() for C#:
using static Gremlin.Net.Process.Traversal.P;
You can read more about other Common Imports in the Reference Documentation here.
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.
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.
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).
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.