Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET API
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.
 
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 24-Jun-13 2:06am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 Shweta N Mishra 244
3 BillWoodruff 235
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 14 Aug 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100