Using App.config to automate the current country of the user - c#

I'm trying to use the App.config file in my C# console application to automate the country that the user is using the program on. So for instance, if I use the .exe file in the US, the application will recognize the user is the United States.
I'm trying to use this so that way I can validate a list of codes from a file with a full list of country codes from that country.
I found this setting for C++ on MSDN, but could not find a C# equivalent. Does anyone know if C# has an App.config equivalent?
"GetCountryCodeFromCountryName" - http://msdn.microsoft.com/en-us/library/ee785499(v=cs.10).aspx

It sounds like you're looking for the RegionInfo class.
Something like:
System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName
Would return US for a user running in the United States, GB for someone in Great Britain, etc.

Related

C# easiest way of storing strings to external file

C#
TL;DR: I want the user to be able to input text, which is then written to an external file, which then can be called later based on position in the file. What's the easiest way and form to read and write a list of strings to?
Very amateur question, but I can't seem to find an easy anwer on the internet. If I'm missing something obvious, please redirect me. I am writing a very simple program in which the user can input a string which is then written (added) to an external file, from which later a string can be called based on the position in the file. I found things like JSON, Resource file, SQL DB... Problem is that due to my lack of programming experience I have no idea what's the best option to look into.
Example of what I want to achieve:
User inputs strings 'Dog', 'Cat', and 'Horse' into the textbox. Each of these strings are added to the external file. Lateron, the user calls the 2nd number on the list, to which the program returns 'Cat'.
Thanks!
If you already know the kind of data that will be saved I recommend using XML Serialization. This lets you save and read your file very easily. The linked example is from Microsoft and shows a dataset being serialized. If you want to save a generic list instead of a fixed object you might find this link helpful.
Alternatively, you could save data to your application configuration file (search online for "C# application configuration for PROJECT_TYPE" where the project type is winforms/mvc/class library etc..)

How to determine default language for multi lingual countries

I'd like my website (c#) to detect visitor's country and present the website in their local language. This is straight forward for the most part but I've run into problems for the following countries:
Canada
Switzerland
Taiwan
All of which have at least two languages being spoken.
I was wondering if there are ways to detect the language preference for visitors from these countries.
I've thought of a couple of things:
Region based detection, pinpoint which region of the country are they from by capturing IP.
Detect the visitor's OS language and replicate that.
If you have other ideas I'd greatly appreciate it. How does other website do this?
It depends from framework and language (of programming) that you use.
For example in pure PHP there is variable $_SERVER with property 'HTTP_ACCEPT_LANGUAGE', example of usage in the link below:
Detect Browser Language in PHP
In Symphony you can configure translator setting parameter as '%locale%'.
http://symfony.com/doc/current/best_practices/i18n.html
A lot of information about IP and OS there are in $_SERVER.

How to upload applications written in C# onto a website using Drupal?

Please answer for Dummies ;) ... Absolute newbie to web programming, especially new to Drupal. We have some modules written in C#, that access a database in MySQL and works on it (it's a student information system actually. We have some forms created in C#, through which interface student's can enter their details onto the database and we have desktop applications which work on those data). Now we need to create a website so that student's can enter information through the internet. We can not re-write the whole modules in PHP, and we want to use Drupal to create the website. So how to do that?
Not really a direct answer, but some points that you need to consider. How complicated this will be depends on how much interoperability you need between the C# code and Drupal.
Does Drupal need to use the forms written in C# in order to enter the data in the DB, or could data entry be done directly from PHP (As in, is there any validation or processing of data in the C# forms that needs to be done?) If not, it seems like the easiest way would be to build a page in Drupal that can enter the data directly into the MySQL database.
Otherwise, the easiest way to get the programmes to talk to each other might be outputting the data to another format — e.g. XML or JSON. (Here's a similar question with someone using JSON as the intermediary data type) You could have your PHP form create an XML document in a temp folder, with the C# programme polling this folder for new files every X minutes and use them as an input into its application.
It will really depend on your workflow — how immediate does the processing of data need to be? Is the flow of data in/out, or in only — i.e does there need to be a set of results returned to the user?

Translating comments and region names in source code

Does anyone know of a batch processor or a VS 2010 plugin/script that would let me translate comments and region names from Chinese into English?
The only ones I've found either process all strings or only one string at a time.
I have two large C# projects that I am trying to read through.
Thanks.
Use PrepTags to prepare your file for translation. It will allow you to select the text to be translated based on regex.
www.preptags.com
You can work file by file for free, or process the files as batch using the pro version (€39)
In your case, it's pretty simple to prepare. You just mark everything as protected, then unprotect the content of the comments & region names.
Disclosure: I develop PrepTags.
As was noted, you can use Google Translate API or alternatively Bing Translator API. You can detect comments and regions in your files using System.CodeDom.
I'm not too sure if this is possible. What you can do to help would be the following:
1) Make sure that both C# projects have the Properties > Build > Xml document file check box checked.
2.1) Write an application that reads in the generated xml file.
2.2) Parse the file, and for each value make a call to Google Translate to get the translated value.
2.3) Place the translated value within another xml file that has the same structure as the one created from building the project.
This wouldn't solve the your desire to translate the region names, but its a start. At least you would have intelligence when using the two projects.
This is actually a good idea for a small open source project. I may decide to pick it up. If I do, I'll let you know.

Windows App spellcheck

I was wondering if there is another way to spell check a Windows app instead what I've been of using: "Microsoft.Office.Interop.Word". I can't buy a spell checking add-on. I also cannot use open source and would like the spell check to be dynamic..any suggestions?
EDIT:
I have seen several similar questions, the problem is they all suggest using open source applications (which I would love) or Microsoft Word.
I am currently using Word to spell check and it slows my current application down and causes several glitches in my application. Word is not a clean solution so I'm really wanting to find some other way.. Is my only other option to recreate my app as a WPF app so I can take advantage of the SpellCheck Class?
If I were you I would download the data from the English Wiktionary and parse it to obtain a list of all English words (for instance). Then you could rather easily write at least a primitive spell-checker yourself. In fact, I use a parsed version of the English Wiktionary in my own mathematical application AlgoSim. If you'd like, I could send you the data file.
Update
I have now published a parsed word list at english.zip (942 kB, 383735 entries, zip). The data originates from the English Wiktionary, and as such, is licensed under the Creative Commons Attribution/Share-Alike License.
To obtain a list like this, you can either download all articles on Wiktionary as a huge XML file containing all Wiki- and HTML-formatted articles. This is then more or less trivial to parse. Alternatively, you can run a bot on the site. I got help to obtain a parsed file from a user at Wiktionary (I seem to have forgotten his name, though...), and this file (english.txt in english.zip) is a further processed version of the file I got.
http://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck.aspx
I use Aspell-win32, it's old but it's open source, and works as well or better than the Word spell check. Came here looking for a built in solution.

Categories