/// <summary> /// Returns the translation for the given language code /// </summary> /// <param name="languageCode">A language code</param> /// <returns></returns> private ProductTranslation GetTranslation(String languageCode) { TargetLanguage targetLanguage = this.TargetLanguages.SingleOrDefault(p => p.LanguageCode == languageCode); if (targetLanguage == null) { throw new ArgumentException(string.Format("LanguageCode {0} is not one of the target languages for this product", languageCode), "languageCode"); } ProductTranslation translation = null; if (this.TranslationsMap.ContainsKey(languageCode)) { translation = this.TranslationsMap[languageCode]; } ////TODO Fix this //else if (targetLanguage.Status == TranslatedFileStatus.Complete) //FileStatus.Translated else { if (this.Client == null) { throw new InvalidOperationException("The product does not have an APIClient to communicate with"); } translation = this.Client.GetProductTranslation(this.AssetID, languageCode); this.TranslationsMap.Add(languageCode, translation); } return(translation); }
/// <summary> /// Retrieves the translation of an item /// </summary> /// <param name="assetID"></param> /// <param name="languageCode"></param> /// <returns></returns> public ProductTranslation GetProductTranslation(Int32 assetID, String languageCode) { ProductTranslation result = null; Uri uri = new Uri(this.EndPoint.AbsoluteUri + "api/products/" + assetID.ToString()+ "/" + languageCode); HttpWebRequest request = CreateRequestGET(uri); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { XDocument document = XDocument.Load(reader); XElement element = document.Element("Translation"); result = new ProductTranslation(element); } } else { this.HandleError(response); } } return result; }