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.
Related
I am developing one application where the client wants to see contents in both arabic and english. The displayed data is retrieving from database SQL.
The question here is If the user saves his details in database in english language, how can i show that data in arabic from database?
How can i achieve this part?
You have to use a translator API and save both the languages to database.
I don't know how you can do that without using some sort of translation service, there is nothing in .NET or SQL server (or any other RDBMS that I know of) that will do that for you.
Here's one (API) that is from Microsoft if you need a place to start: https://www.microsoft.com/en-us/translator/translatorapi.aspx
Depending on your requirements, you may want to translate data immediately and store it into the opposite database; however it may end up being expensive, so if you're able you might choose to translate things on demand to save some costs.
i think An effective way to create localized Web pages is to use resource objects for your page's text and controls. By using properties placed in resource objects, ASP.NET can select the correct property at run time according to the user's language and culture. The process is straightforward:
Resource Files and ASP.NET MVC Projects
fore more info
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.
I am writing a desktop application using MVVM and Prism and I have the following problem. As well as the labels etc it is also necessary to store data in different languages.
For example, in the USA a user might be able to login using either English or Spanish (as they are a native speaker).
If the user logs in using Spanish when they go into a product details
form the product description will be saved to the database against
the Spanish language.
If they log in using English the product description will be saved to
the database and related to the English language.
At the moment my only ideas is as below:-
- a globally accessible ApplicationViewModel that contains a
CurrentLoggedInUser property
What I would like to know is how I go about saving the currently logged in user's chosen language when using MVVM, particularly in a desktop application?
N.B the chosen language can be different to the language and locale that the operating system is in
How do other people go about resolving this and maintaining the user's "session" across different windows / user controls when using MVVM?
All you need to do is store the current language somewhere, maybe as an LCID.
Generally this is used to load a language specific resource file, which takes care of most language dependant situations. Controls etc just store all their strings in resources, so they don't need direct access to the current language.
For situations where you do need access to the language, such as knowing where to save your database string, then yes, the language should be exposed either as some static/singleton, or more desirably, should be injected into whatever ViewModels need it.
Requirement is that i want to identify that the text written in PDF or Doc is english or non english. if i got a single word of (turiskh, french,arabic and etc.) have to avoid the whole documnet
its urgent plz give me sample code for this functionality
Have a look on Google Translate API, only free service who could do this for you what I know. Otherwise I can only see the solution of having your own dictionary etc.. But thats a different story
I guess you could use LangId. However there are some restrictions:
To use our API in live websites or services we suggest you to apply for a free API key, using the below form. The API key expands your developing possibilities allowing you to do up till 1,000 requests per hour (~720,000 per month).
I don't think this will solve your 'single word' issue however. I believe if the text has 6 words English and 4 words in another language it will see the text as English since that language is mainly used in the file. I haven't looked at the API myself though so there might be some solutions for that.
Hope it is of use to you.
Maybe the detect function of Google's Translate API could help you:
http://code.google.com/apis/language/translate/v2/getting_started.html#language_detect
This is not possible for single words.
Is "the" an English word? Well, yes, but it's also a Danish word (meaning tea). Does the word Schadenfreude indicate a non-english text? Not necessarily, it all depends on the context.
Adding to the list of APIs that support language determination, Bing API has a call that will determine the language for an array of strings.
http://msdn.microsoft.com/en-us/library/ff512412.aspx
Hope this helps somewhat.
I am building a website using Asp.net with C# and back end support is SQL server.How to add multilingual support to it?Like in google or facebook there are various link button for various languages?I want to implement the same thing.Please help.Thanks in advance.
Google and Facebook employ the help of translators to produce their various language features. This is a process called localization is often a very complicated and difficult process. If you are working by yourself, I would be wary of actually doing your own localization unless you are a native speaker or are fluent in the languages you want to translate your pages to.
If you would like users from around the world to be able to use your page in their native language, you may consider placing a link on your site that uses Google Translator or another translation service to convert your page text for you. It is not a perfect solution, but may help you get up and running.
If this doesn't suit your needs, you will need to do the localization yourself. I'm no expert on the process, but there is a simple pattern you can follow. Take blocks of text on your website and translate them into the different languages you want to support, and depending on which language the user specifies in their preferences, pick that block of text that matches that language.
This Wikipedia Article may help you better understand the processes and the complications that are involved.
This MSDN Article discusses best practices and tips for doing localization in ASP.net.
You'll have to define somewhere all text and choose on a request the language you want to use.
Translating and maintaining translated texts is a non trivial task, maybe String | Create a multi-language website or app will help you a lot.