public LocalizedString this[string name] { get { var str = _localizedStringManager.GetLocalizedString(CultureInfo.CurrentUICulture.Name, name); return(new LocalizedString(name, str ?? name, str != null)); } }
public LocalizedString Get(string textHint, params object[] args) { Logger.Debug("{0} localizing '{1}'", _scope, textHint); var workContext = _workContextAccessor.GetContext(); var currentCulture = workContext.CurrentCulture; var localizedFormat = _localizedStringManager.GetLocalizedString(_scope, textHint, currentCulture); return(args.Length == 0 ? new LocalizedString(localizedFormat, _scope, textHint, args) : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), _scope, textHint, args)); }
public LocalizedString Get(string textHint, params object[] args) { var workContext = workContextAccessor.GetContext(); var currentCulture = workContext.CurrentCulture; var localizedFormat = localizedStringManager.GetLocalizedString(textHint, currentCulture); if (string.IsNullOrEmpty(localizedFormat)) { return(new LocalizedString(textHint)); } return(args.Length == 0 ? new LocalizedString(localizedFormat, textHint, args) : new LocalizedString( string.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), textHint, args)); }
public LocalizedString Get(string textHint, params object[] args) { // Logger.Debug("{0} localizing '{1}'", _scope, textHint); // return new LocalizedString(textHint, _scope, textHint, args); var workContext = _workContext.WorkingLanguage;// _workContextAccessor.GetContext(); if (workContext != null) { var currentCulture = workContext.Name; var localizedFormat = _localizedStringManager.GetLocalizedString(_scope, textHint, currentCulture); return(args.Length == 0 ? new LocalizedString(localizedFormat, _scope, textHint, args) : new LocalizedString(string.Format(GetFormatProvider(currentCulture), localizedFormat, args), _scope, textHint, args)); } return(new LocalizedString(textHint, _scope, textHint, args)); }
public LocalizedString Get(string textHint, params object[] args) { //string currentCulture = Thread.CurrentThread.CurrentUICulture.Name; string currentCulture = EngineContext.Current.Resolve <IWorkContext>().CurrentCultureCode; string localizedFormat = localizedStringManager.GetLocalizedString(textHint, currentCulture); if (string.IsNullOrEmpty(localizedFormat)) { return(new LocalizedString(textHint)); } return(args.Length == 0 ? new LocalizedString(localizedFormat, textHint, args) : new LocalizedString( string.Format( GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), textHint, args)); }
public LocalizedString Get(string textHint, params object[] args) { Logger.Debug("{0} localizing '{1}'", _scope, textHint); var workContext = _workContextAccessor.GetContext(); if (workContext != null) { var currentCulture = workContext.CurrentCulture; var localizedFormat = _localizedStringManager.GetLocalizedString(_scope, textHint, currentCulture); // localization arguments are HTML-encoded unless they implement IHtmlString return(args.Length == 0 ? new LocalizedString(localizedFormat, _scope, textHint, args) : new LocalizedString( String.Format(GetFormatProvider(currentCulture), localizedFormat, args.Select(Encode).ToArray()), _scope, textHint, args)); } return(new LocalizedString(textHint, _scope, textHint, args)); }
/// <summary> /// esempio http://localhost/Laser.Orchard/expoincitta/api/Laser.Orchard.ContentExtension/Content?ContentType=User /// da richiamare come application/json e non come form /// </summary> /// <param name="ContentType"></param> /// <param name="Language"></param> /// <returns></returns> public dynamic Get(string ContentType, string Language = "it-IT") { ContentTypeDefinition contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(ContentType); if (contentTypeDefinition == null) { Response resp = new Response() { Success = false, Message = T("ContentType not exist").ToString(), ErrorCode = ErrorCode.Validation }; return(resp); } var eObj = new ExpandoObject() as IDictionary <string, Object>; #region Tutti i field foreach (ContentTypePartDefinition ctpd in contentTypeDefinition.Parts) { var fields = ctpd.PartDefinition.Fields.ToList(); string tipofield = ""; foreach (ContentPartFieldDefinition singleField in fields) { tipofield = singleField.FieldDefinition.Name; if (tipofield == typeof(TaxonomyField).Name) { #region Tassonomia in Lingua var taxobase = _taxonomyService.GetTaxonomyByName(singleField.Settings["TaxonomyFieldSettings.Taxonomy"]); int idmaster = taxobase.Id; if (taxobase.ContentItem.As <LocalizationPart>() != null) { if (((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem != null) { idmaster = ((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem.Id; } if (((dynamic)taxobase.ContentItem).LocalizationPart.Culture != null) { if (((dynamic)taxobase.ContentItem).LocalizationPart.Culture.Culture != Language) { taxobase = _taxonomyService.GetTaxonomies().Where(x => (x.Id == idmaster || (((dynamic)x.ContentItem).LocalizationPart.MasterContentItem != null && ((dynamic)x.ContentItem).LocalizationPart.MasterContentItem.Id == idmaster)) && ((dynamic)x.ContentItem).LocalizationPart.Culture.Culture == Language).FirstOrDefault(); } } } List <TermPart> cata = _taxonomyService.GetTerms(taxobase.Id).ToList();//.GetTermsForContentItem(currentUser.Id, singleField.Name).ToList(); List <string> ListCategory = new List <string>(); ListCategory = cata.Select(x => x.Id.ToString()).ToList(); List <ElementDetail> elements = new List <ElementDetail>(); foreach (var term in taxobase.Terms) { Int32?valore = term.Id; Int32?mediaid = null; try { MediaLibraryPickerField mpf = (MediaLibraryPickerField)(term.Fields.Where(x => x.FieldDefinition.Name == "MediaLibraryPickerField").FirstOrDefault()); mediaid = mpf.Ids[0]; } catch { } if (!term.Selectable) { valore = null; } if (term.FullPath == "/" + term.Id.ToString() || term.FullPath == term.Id.ToString()) { elements.Add(new ElementDetail() { Name = term.Name, Value = valore, ImageId = mediaid }); } else { Int32 idtermfather = Convert.ToInt32(term.FullPath.Split('/')[term.FullPath.Split('/').Length - 2]); FindTaxoVM(elements, idtermfather).Children.Add(new ElementDetail() { Name = term.Name, Value = valore, ImageId = mediaid }); } } ResponseElement re = new ResponseElement(); bool solofoglie = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.LeavesOnly"]); if (solofoglie) { ElementDetail TempElement = new ElementDetail(); //elemento fittizzio per procedura ricorsiva TempElement.Children = elements; AnnullaNonFoglie(TempElement); elements = TempElement.Children; } re.Values = elements; re.Setting = new ResponseSetting { Type = "Taxonomie", Required = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.Required"]), SingleChoice = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.SingleChoice"]) }; eObj.Add(ctpd.PartDefinition.Name + "." + singleField.Name, re); #endregion Tassonomia in Lingua } else if (tipofield == typeof(EnumerationField).Name) { string[] elencovalori = singleField.Settings["EnumerationFieldSettings.Options"].Split(new string[] { "\r\n" }, StringSplitOptions.None); List <string> elencoValoriInLingua = new List <string>(); List <ElementDetail> ele = new List <ElementDetail>(); foreach (string val in elencovalori) { ElementDetail tvm = new ElementDetail(); tvm.Value = val; tvm.Name = _localizedStringManager .GetLocalizedString(new string[] { "UserEnumeratore" }, val, Language) .Format; ele.Add(tvm); } ResponseElement re = new ResponseElement(); re.Values = ele; bool singlechoise = true; if (singleField.Settings["EnumerationFieldSettings.ListMode"] == "Listbox" || singleField.Settings["EnumerationFieldSettings.ListMode"] == "Checkbox") { singlechoise = false; } re.Setting = new ResponseSetting { Type = "Enumerator", Required = Convert.ToBoolean(singleField.Settings["EnumerationFieldSettings.Required"]), SingleChoice = singlechoise }; eObj.Add(ctpd.PartDefinition.Name + "." + singleField.Name, re); } } } #endregion Tutti i field return(Json(eObj)); }
public dynamic Get(string Language = "it-IT") { var eObj = new ExpandoObject() as IDictionary <string, Object>; var currentUser = _authenticationService.GetAuthenticatedUser(); // var currentUser = _orchardServices.WorkContext.CurrentUser; if (currentUser == null) { return(_utilsServices.GetResponse(ResponseType.InvalidUser)); // { Message = "Error: No current User", Success = false,ErrorCode=ErrorCode.InvalidUser,ResolutionAction=ResolutionAction.Login }); } #region Tutti i field var fields = currentUser.ContentItem.Parts.SelectMany(x => x.Fields); string tipofield = ""; foreach (ContentField singleField in fields) { tipofield = singleField.GetType().Name; if (tipofield == typeof(DateTimeField).Name) { eObj.Add(singleField.Name, ((dynamic)singleField).DateTime); } else if (tipofield == typeof(ContentPickerField).Name || tipofield == typeof(MediaLibraryPickerField).Name) { eObj.Add(singleField.Name, ((dynamic)singleField).Ids); } else if (tipofield == typeof(TaxonomyField).Name) { #region Tassonomia in Lingua var taxobase = _taxonomyService.GetTaxonomyByName(singleField.PartFieldDefinition.Settings["TaxonomyFieldSettings.Taxonomy"]); // seleziono la tassonomia in lingua int idmaster = taxobase.Id; if (((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem != null) { idmaster = ((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem.Id; } if (((dynamic)taxobase.ContentItem).LocalizationPart.Culture.Culture != Language) { taxobase = _taxonomyService.GetTaxonomies().Where(x => (x.Id == idmaster || (((dynamic)x.ContentItem).LocalizationPart.MasterContentItem != null && ((dynamic)x.ContentItem).LocalizationPart.MasterContentItem.Id == idmaster)) && ((dynamic)x.ContentItem).LocalizationPart.Culture.Culture == Language).FirstOrDefault(); } List <TermPart> cata = _taxonomyService.GetTermsForContentItem(currentUser.Id, singleField.Name).ToList(); List <string> ListCategory = new List <string>(); ListCategory = cata.Select(x => x.Id.ToString()).ToList(); List <TaxoVM> elements = new List <TaxoVM>(); foreach (var term in taxobase.Terms) { if (term.FullPath == "/" + term.Id) { elements.Add(new TaxoVM() { Id = term.Id, testo = term.Name, valore = term.Id.ToString(), flag = ListCategory.Contains(term.Id.ToString()) }); } else { Int32 idtermfather = Convert.ToInt32(term.FullPath.Split('/')[term.FullPath.Split('/').Length - 2]); FindTaxoVM(elements, idtermfather).child.Add(new TaxoVM() { Id = term.Id, testo = term.Name, valore = term.Id.ToString(), flag = ListCategory.Contains(term.Id.ToString()) }); } } eObj.Add(singleField.Name, elements); #endregion Tassonomia in Lingua } else if (tipofield == typeof(EnumerationField).Name) { eObj.Add(singleField.Name, ((dynamic)singleField).Value); string[] elencovalori = singleField.PartFieldDefinition.Settings["EnumerationFieldSettings.Options"].Split(new string[] { "\r\n" }, StringSplitOptions.None); // Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); List <string> elencoValoriInLingua = new List <string>(); foreach (string val in elencovalori) { elencoValoriInLingua.Add(_localizedStringManager.GetLocalizedString("UserEnumeratore", val, Language)); //T.Target.(elencovalori[0],) } eObj.Add(singleField.Name + "valori", singleField.PartFieldDefinition.Settings["EnumerationFieldSettings.Options"]); eObj.Add(singleField.Name + "valoriLang", String.Join("\r\n", elencoValoriInLingua)); } else { eObj.Add(singleField.Name, ((dynamic)singleField).Value); } } #endregion Tutti i field return(eObj); }