Conditional logic depens on culture settings. ASP.NET - c#

I have bunch pages and I need to validate data there. If culture for example "es-ES" I should use one validation logic, if culture "en-US" than another validation logic. For example I need validate phone number. Minimum length is 11 digits. For other culture 9 digits. How can I do this? Some patterns or other decisions?

If localizing, you should be using satellite assemblies for localization - this will also allow you to set culture specific RegEx expressions for validation (phone number formats etc).

You can determine the current culture by checking Thread.CurrentThread.CurrentCulture.Name. Is that what you mean?

What if my browser is set to en-US because I'm a us national but I'm in spain with a spanish mobile number?

Related

Stored Number with dot but display with comma in frontend

The data type in database is "decimal", the value is normally like 2.6, 3.8 etc
But when I render it on the front side, it become 2,6
I wondering why it happens and how to handle it correctly.
I try to adjust .Net Globalization Culture in IIS become EN, then display as I want.
Not the setting is Invariant Language.
I had print out culture info by C#, it shows GB
How can I handling it as all display number with dot

Bing translator exception from en-us to 'fr-ca'

i've started using Bing API translator. all the things is ok but when I tried to translate to it with culture code 'fr-ca',fr-FR then it is translating only using language code 'fr' not with culture code (ca, FR) 'fr-ca', 'fr-FR'.
When I called this API method to translate
translationQuery.Execute().ToList();
throws this exception :
--------An error occurred while processing this request.
and the inner exception is :
--------"Parameter: To has an invalid pattern of characters"
source : System.Data.Services.Client
can any one help me about this problem? and tell me how to translate text with culture code with anyway either API or something else ?
Thanks In advance
sunil
Thanks for your response.
I have more than 10 files and each files have 1000 words that needs to transalate into another languages on bases of culture code not only language code.
English en-GB British English
en-US American English
en-CA Canadian English
Spanish es-ES Castilian Spanish (as written and spoken in Spain)
es-MX Mexican Spanish
es-AR Argentine Spanish
es-CO Colombian Spanish
Portuguese pt-PT European Portuguese (as written and spoken in Portugal)
pt-BR Brazilian Portuguese
Chinese zh-CN Mainland China, simplified characters
zh-TW Taiwan, traditional characters
zh-HK Hong Kong, traditional characters
Instead of doing translation manually is there any others way to translate e.g(es-ES,es-MX,es-CO, es-AR ) ?. since its langauge code is same for all eg:-(es) but have different culture code for each languages. So it may be case that some words have different meaning in es-es and have diffent means in es-MX, es-Co etc.
it would be helpful if found a way to translate on bases of culture code?
Thanks in Advance
Sunil
The reason is that Bing translator doesn't support Canadian French, only Standard French:
http://msdn.microsoft.com/en-us/library/hh456380.aspx
Microsoft Translator continually adds to the list of supported languages for the Translation and Text to Speech methods. You can always obtain the current list of available language codes using the
GetLanguagesForTranslate() or GetLanguagesForSpeak() methods. These methods will return a language code. You can translate that language code into a friendly name in any of the supported languages using the GetLanguageNames() method. Below are the friendly names in English - you can retrieve them in any of the listed languages using GetLanguageNames(). Here is the list (as of February 2014):
...
fr French
If you want to use Canadian French, you'll have to perform the relevant word swaps afterwards manually.
Ss an aside, Google Translate also only supports Standard French.

C# program stops working after the language setting in control panel is changed (say, from English to German)

I have a software developed in C#, which is a pure sentefic application. Howver the German users found this software stopped working from time to time, when it is installed on German computers. The temporary solution is to change the Language setting in the control panel, and it works fine after we change the language setting from German to English. This is just a kind of engineering sofware, and the software have nothing relalted to the German or English language. Also, as suggested from other posts in msdn, I have checked the "InitializeComponent()" in the source does several times. There are not strange codes in the "InitializeComponent()" function.
When you change locale, you change the meaning of ',' (comma) and '.' (full-stop) when used in numbers. Could it be that you are trying to parse text containing these characters into numbers?
Does your program attempt to initialize numeric fields with formatted numbers, perhaps?
You need to make sure that your code is sensitive to the user's culture when parsing and formatting text. You also need to make sure you use a consistent culture (e.g. the InvariantCulture) when reading data stored to file or sent over a network.
If you are using .NET Framework 4.5, you might be interested to read about the CultureInfo.DefaultThreadCurrentCulture Property.
In the .NET Framework 4 and previous versions, by default, the culture
of all threads is set to the Windows system culture. For applications
whose current culture differs from the default system culture, this
behavior is often undesirable.
The examples and their explanations on the page could be quite helpful for your issue.
Also, as a side note, try{...}catch{...} blocks are always welcome.

Localising asp.net app to HK with language set to english

I am building a multilingual web app. The client requires the site for HK to be displayed in English. Unfortunately, "en-HK" is not a valid culture in asp.net, so I tried to get around it using "zh-hk". However, this caused the date time strings (with format of dd-MMM-yyyy) to be displayed in Chinese.
Is there any way to display the language in english but localise it to Hk?
CurrentUICulture controls selection of localized resources: set it to an English culture (e.g. "en" or "en-GB").
CurrentCulture controls number and date formats etc., including day and month names. Either set it to "en-GB", or set it to a custom culture based on "en-GB", but with any modifications you want (e.g. your post suggests you want "-" as date separator: dd-MMM-yyyy).
Neither of these affects time zone etc, so I don't really see why it would be a problem simply to use "en-GB".
I don't know much about Hong Kong but given its recent history, the English language conventions used there are probably based on UK English rather than US English. The short date format used in Hong Kong (documented on Wikipedia here) certainly appears to support this assertion: it's day/month/year (British style, unlike the US style where it's month/day/year).
You could always create a custom culture (supported by Windows 7 onwards) for en-HK. This is done by using the CultureAndRegionInfoBuilder class and will allow you to create your en-HK CultureInfo, based on the en-GB culture if my comment above is correct. This would allow you to customize some of the elements of the CultureInfo if you wish to (and more importantly, if you know what is different in Hong Kong). By basing your custom culture on en-GB, your date formats will show month names in English. But creating a custom culture is probably overkill.
More simply, you could use the en-GB Culture name. Your app probably doesn't use some of the more arcane things in the en-GB culture that wouldn't apply to Hong Kong.
Note: In case there is any confusion, for date formatting Thread.CurrentUICulture has no effect whatsoever--it's entirely dependent on what Thread.CurrentCulture is set to (and which must be a specific culture, unlike CurrentUICulture for which a neutral culture such as "en" is OK).
As far as I know you can't combine your culture strings yourself (meaning, en-HK is not valid unless it is listed in .NET).
However, they have two different culture settings per thread:
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentUICulture
Which both controls different things. Maybe that can let you use english as language but HK as localized formats.
You could also override the formatting of dates and such specifically, and maybe find better cultureinfos that will give you the date format that you need.

Need helped understanding .resx variables

I am working on a project for my company, and while tracing previously written code I came upon this:
<value>A payment authorization for {0:C} has been received.</value>
What does {0:C} mean? I have been trying to find out and am having no luck.
This is just a string like any other string. Once loaded into memory, it will be used as the format parameter to string.Format. {0:C} just means to format the number as currency using the current UI culture (or is it just current culture? I can never remember).
It's formatting a number as currency.

Categories