Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am Working on a multilingual Web application which is developed in Asp.net 4.0 with C#. I am creating a resource file for each language in which i have to translate whole application. For this First i create a Main resource file in English Language. Now We Fetch Key value pair of Language.resx file and Translate value into desired language and insert this value in another resx file.(e.g. Language.hi.resx). For the conversion of value i am using Google Language translator API for each value of language.resx file and use following function to translate this value.

C#
public static string TranslateText(string Text, string tragetlan, string sourceLang)
    {
        try
        {
            LanguagesListResponse ls = new LanguagesListResponse();
            Google.Apis.Translate.v2.Data.LanguagesResource ss = new Google.Apis.Translate.v2.Data.LanguagesResource();
            ss.Language = tragetlan;

            // GetLanguageCode
            string googlekey = "Axxxxxxxxxxxxxxxxxxxxxxxxxxxxw";

            var service = new TranslateService(new BaseClientService.Initializer()
            {
                ApiKey = googlekey
            });
            //new TranslateService { Key = googlekey };
            ICollection<string> data = new Collection<string>();
            string[] srcText = new[] { Text };
            TranslationsListResponse response = service.Translations.List(srcText, tragetlan).Fetch();
            var translations = new List<string>();

            // We need to change this code...
            // currently this code 
            foreach (Google.Apis.Translate.v2.Data.TranslationsResource translation in response.Translations)
            {
                translations.Add(translation.TranslatedText);
            }
            return translations[0];
        }
        catch (Exception ex)
        {
            return Text;
        }
    }


Above function is Working fine for me, but for some values this function through an exception says "Google.Apis.Requests.RequestError Access Not Configured [403] The remote server returned an error: (403) Forbidden.". This Exception occur in random manner that means for same sentence (Value) it translate correctly in all languages but through exception for one or two languages. This problem is occur after 8-12 requests. Note : The Character length of my Input values are always less than 500 characters and this problem occur for all size sentences (i.e. Small 10-20 Characters and large 250-400 Characters) I am not sure why google API behaving like this.
Posted

1 solution

CSS
Increase quota of Google Translator API by increasing characters/second/user Limit.
Steps to go to this page:
1. Login to Google
2. Go to url : code.google.com/apis/console
3. Click on Quotas
4. Increase Translate API Quote Up to 100000
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900