void AddBinding(TextBox box, ILocalizable source, string propertyName) { Binding binding = new Binding(propertyName); binding.Source = source; binding.Mode = BindingMode.TwoWay; box.SetBinding(TextBox.TextProperty, binding); }
/// <summary> /// Construct the exception. /// </summary> /// <param name="specific">Contextual information on what caused the exception.</param> /// <param name="lo">Lower end of the interval.</param> /// <param name="hi">Higher end of the interval.</param> /// <param name="fLo">Value at the lower end of the interval.</param> /// <param name="fHi">Value at the higher end of the interval.</param> /// <param name="args">Additional arguments.</param> public NoBracketingException(ILocalizable specific, double lo, double hi, double fLo, double fHi, params object[] args) : base(specific, lo, hi, fLo, fHi, args) { this.Lo = lo; this.Hi = hi; this.Flo = fLo; this.Fhi = fHi; }
/// <summary> /// Registers a new event handler for the specified object, which must implement the ILocalizable interface. /// </summary> /// <param name="obj">Object implementing the OnCultureChange event handler.</param> public static void Register ( ILocalizable obj ) { try { CultureChangeEvent -= obj. OnCultureChange ; } catch { } CultureChangeEvent += obj. OnCultureChange ; // If current culture has been changed, fire the OnCultureChange event for this newcomer if ( CultureChanged ) obj. OnCultureChange ( null, new LocalizableEventArgs ( LocalizableUI. Culture ) ) ; }
/** * Populates the text property of a single scene object with a new text value. */ public virtual bool PopulateTextProperty(string stringId, string newText) { // Ensure that all localizeable objects have been cached if (localizeableObjects.Count == 0) { CacheLocalizeableObjects(); } ILocalizable localizable = null; localizeableObjects.TryGetValue(stringId, out localizable); if (localizable != null) { localizable.SetStandardText(newText); return(true); } return(false); }
/// <summary> /// Gets a list of menu item objects representing the different /// languages that are supported by the app. /// </summary> public List <MenuItem> GetLanguageMenuItems(ILocalizable target) { List <MenuItem> items = new List <MenuItem>(); foreach (var locInfo in LocalizationExtension.Localizations) { object logo; string prefix = string.Empty; if (LocalizationExtension.CurrentLocalization == locInfo.Key) { logo = new CheckBox() { IsChecked = true, BorderThickness = new Thickness(0) } } ; else { logo = new Image() { Source = locInfo.Value.Image } }; if (locInfo.Key == LocalizationExtension.DEFAULT_LOC) { prefix = GetLocalizationValue("DefaultLanguageMenuItemHeader") + " - "; } MenuItem item = new MenuItem() { Header = prefix + locInfo.Value.CultureInfo.DisplayName, Command = ReactiveCommand.Create <string>(target.SelectLanguage), CommandParameter = locInfo.Key, Icon = logo }; items.Add(item); } return(items); }
/// <summary> /// Gets the edit URL for a <see cref="T:EPiServer.Core.IContent"/>. /// </summary> /// <param name="contentData">The content data.</param><param name="onCurrentHost">if set to <c>true</c> current host are used.</param> /// <returns> /// The edit url. /// </returns> protected virtual string GetEditUrl(IContent contentData, out bool onCurrentHost) { ContentReference contentLink = contentData.ContentLink; ILocalizable localizable = contentData as ILocalizable; string language = localizable != null ? localizable.Language.Name : ContentLanguage.PreferredCulture.Name; string editUrl = EditPath(contentData, contentLink, language); onCurrentHost = true; SiteDefinition definitionForContent = _SiteDefinitionResolver.GetByContent(contentData.ContentLink, true, true); if (definitionForContent?.SiteUrl != SiteDefinition.Current.SiteUrl) { onCurrentHost = false; } //if (Settings.Instance.UseLegacyEditMode && typeof(PageData).IsAssignableFrom(typeof(TContent))) // return UriSupport.Combine(UriSupport.Combine(definitionForContent.SiteUrl, settingsFromContent.UIUrl).AbsoluteUri, editUrl); return(editUrl); }
protected override string GetEditUrl(SettingsBase contentData, out bool onCurrentHost) { onCurrentHost = true; if (contentData == null) { return(string.Empty); } var contentLink = contentData.ContentLink; var language = string.Empty; ILocalizable localizable = contentData; if (localizable != null) { language = localizable.Language.Name; } return ($"/episerver/Foundation.Cms.Settings/settings#context=epi.cms.contentdata:///{contentLink.ID}&viewsetting=viewlanguage:///{language}"); }
/// <summary> /// Gets the edit URL. /// </summary> /// <param name="contentData">The content data.</param> /// <param name="onCurrentHost">if set to <c>true</c> [on current host].</param> /// <returns>The edit url.</returns> protected override string GetEditUrl(SettingsBase contentData, out bool onCurrentHost) { onCurrentHost = true; if (contentData == null) { return(string.Empty); } ContentReference contentLink = ((IContent)contentData).ContentLink; string language = string.Empty; ILocalizable localizable = contentData as ILocalizable; if (localizable != null) { language = localizable.Language.Name; } return ($"/episerver/Epi.Extensions.Settings/settings#context=epi.cms.contentdata:///{contentLink.ID}&viewsetting=viewlanguage:///{language}"); }
/// <summary> /// Change language at all localizable items. /// </summary> /// <param name="localizable">localizable item</param> public void ChangeLanguage(ILocalizable localizable) { if (localizable != null) { foreach (var localizedItem in localizable) { for (int index = 0; index < localizedItem.Count; index++) { string resource; if (TryGetLocalizedString(localizedItem.GetResourceId(index), out resource)) { localizedItem[index] = resource; } else { localizedItem.BackToDefault(index); } } localizedItem.Refresh(); } } }
public FormInformation ReadForm(ContentReference contentLink) { IContent content = contentLoader.Service.Get <IContent>(contentLink); ILocalizable localizable = content as ILocalizable; if (content == null || localizable == null) { return(FormInformation.Empty); } FormIdentity formIdentity = new FormIdentity(content.ContentGuid, localizable.Language.Name); IEnumerable <Submission> submissions = formDataRepository.Service.GetSubmissionData(formIdentity, DateTime.MinValue, DateTime.MaxValue); IEnumerable <FriendlyNameInfo> friendlyNameInfos = this._formRepository.Service.GetDataFriendlyNameInfos(formIdentity); var info = new FormInformation { Submissions = submissions, FriendlyNameInfos = friendlyNameInfos }; return(info); }
private void ClearSearchItem(object sender, ContentEventArgs e) { ISearchable seachable = e.Content as ISearchable; if (seachable?.IsSearchable == true) { return; } CultureInfo language = null; ILocalizable localizable = e.Content as ILocalizable; if (localizable != null) { language = localizable.Language; } string searchId = string.Concat(e.Content.ContentGuid, "|", language); IndexRequestItem indexItem = new IndexRequestItem(searchId, IndexAction.Remove); SearchHandler.Instance.UpdateIndex(indexItem); }
protected IContentNode Create <TContent>(IContentNode <IContentData> parentNode, string name, Action <TContent> populate = null) where TContent : class, IContentData { var parent = parentNode.Content; CultureInfo language; ILocalizable localizable = parent as ILocalizable; if (localizable != null && localizable.Language != null) { language = localizable.Language; } else { language = ContentLanguage.PreferredCulture; } IContent defaultContent = _contentProvider.GetDefaultContent( _contentLoader.Get <IContent>(parentNode.ContentLink), _contentTypeRepository.Load <TContent>().ID, new LanguageSelector(language.Name)); defaultContent.Name = name; defaultContent.ContentLink = GetNextContentLink(); populate?.Invoke((TContent)defaultContent); IContentNode node = new ContentNode <TContent> { Content = (TContent)defaultContent, Parent = parentNode }; parentNode.Children.Add(node); _allContents.Add(node); return(node); }
public static void LoadConfigViewResources( this ILocalizable target) { const string Direcotry = @"resources\styles"; const string Resources = @"ConfigViewResources.xaml"; var element = target as FrameworkElement; if (element == null) { return; } var file = Path.Combine(DirectoryHelper.FindSubDirectory(Direcotry), Resources); if (File.Exists(file)) { element.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(file, UriKind.Absolute) }); } }
private static string GetLanguageString(ILocalizable target, ILocaleProvider rm, string languageEntry, params object[] args) { string str = rm?.GetString(languageEntry, target.Culture) ?? "{{L:" + languageEntry + "}}"; if (args == null) { args = new object[0]; } var newArgs = new object[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i] == null) { newArgs[i] = ""; } else { newArgs[i] = GetLocalizedMessage(target, rm, args[i].ToString()); } } return(string.Format(str, newArgs)); }
protected bool CheckColision(ILocalizable localizable) { foreach (ILocalizable item in fruitsList) { if (item is Grapes) { if (Object.ReferenceEquals(item, this)) { continue; } } if (item.Bounds.Contains(localizable.Location) || localizable.Bounds.Contains(item.Location)) { return(true); } } foreach (ILocalizable item in obstacles) { if (item.Bounds.Contains(localizable.Location) || localizable.Bounds.Contains(item.Location)) { return(true); } } if (this.Bounds.Contains(snake.SnakeHead.Location) || snake.SnakeHead.Contains(this.location)) { return(false); } if (snake.CheckColsion(localizable)) { return(true); } return(false); }
/// <summary> /// Construct an exception from the mismatched dimensions. /// </summary> /// <param name="specific">Message pattern providing the specific context of the error.</param> /// <param name="wrong">Wrong dimensions.</param> /// <param name="expected">Expected dimensions.</param> public MultiDimensionMismatchException(ILocalizable specific, int[] wrong, int[] expected): base(specific, wrong, expected) { this.WrongDimensions = wrong.Clone() as int[]; this.ExpectedDimensions = expected.Clone() as int[]; }
public static string GetIndexId(this IContent content) { ILocalizable localizable = content as ILocalizable; return(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}_{1}{2}", (object)DataFactory.Instance.GetProvider(content.ContentLink).ProviderKey, (object)content.ContentGuid, localizable != null ? (object)("_" + localizable.Language.Name) : (object)string.Empty)); }
/// <summary> /// Construct the exception with a specific context and arguments. /// </summary> /// <param name="pattern">Message pattern providing the specific context of the error.</param> /// <param name="args">Arguments.</param> public ConvergenceException(ILocalizable pattern, params object[] args) { Context.AddMessage(pattern, args); }
public static string LanguageName(this ILocalizable content) { return(content.Language.Name); }
/// <summary> /// Constructor accepting a localized message. /// </summary> /// <param name="pattern">Message pattern explaining the cause of the error.</param> /// <param name="args">Arguments.</param> public MathInternalError(ILocalizable pattern, params object[] args) : base(pattern, args) { }
/// <summary> /// Simple constructor. /// </summary> /// <param name="pattern">Message pattern providing the specific context of the error.</param> /// <param name="args">Arguments</param> public MathUnsupportedOperationException(ILocalizable pattern, params object[] args) { this.context = new ExceptionContext(this); this.context.AddMessage(pattern, args); }
public static string GetLocalizedMessage(this ILocalizable target, ILocaleProvider rm, string message, params object[] paramaters) { message = FindLanguageRegex.Replace(message, match => GetLanguageString(target, rm, match.Groups[1].Value, paramaters)); return(message); }
/** * Add two long integers, checking for overflow. * * @param a Addend. * @param b Addend. * @param pattern Pattern to use for any thrown exception. * @return the sum {@code a + b}. * @throws MathArithmeticException if the result cannot be represented * as a {@code long}. * @since 1.2 */ private static long addAndCheck(long a, long b, ILocalizable pattern) { long ret; if (a > b) { // use symmetry to reduce boundary cases ret = addAndCheck(b, a, pattern); } else { // assert a <= b if (a < 0) { if (b < 0) { // check for negative overflow if (Int64.MinValue - b <= a) { ret = a + b; } else { throw new MathArithmeticException(pattern, a, b); } } else { // opposite sign addition is always safe ret = a + b; } } else { // assert a >= 0 // assert b >= 0 // check for positive overflow if (a <= Int64.MaxValue - b) { ret = a + b; } else { throw new MathArithmeticException(pattern, a, b); } } } return ret; }
public static Point? PercentilePositionOnMap(this Map This, ILocalizable loc) { if (This == null || loc == null || !loc.Latitude.HasValue || !loc.Longitude.HasValue) return null; Point? p = PercentilePositionOnMapImpl(This, loc.Latitude.Value, loc.Longitude.Value); if (p == null || p.Value.X < 0 || p.Value.X > 1 || p.Value.Y < 0 || p.Value.Y > 1) return null; return p; }
/// <summary> /// Unregisters an existing culture change event handler. /// </summary> /// <param name="obj">Object implementing the OnCultureChange event handler.</param> public static void Unregister ( ILocalizable obj ) { CultureChangeEvent -= obj. OnCultureChange ; }
public static string GetText(this ILocalizable entity, string property, CultureInfo culture) { var texts = GetText(entity, new[] { property }, culture); return(texts[property]); }
public static IEnumerable <string> ExistingLanguages(this ILocalizable localizable) { return(Enumerable.Select <CultureInfo, string>(localizable.ExistingLanguages, (Func <CultureInfo, string>)(x => x.Name))); }
public static string GetPropertyValue(ILocalizable target, string propertyName) { PropertyInfo info = target.GetType().GetProperty(propertyName); return(info.GetValue(target, null) as string); }
protected ContentNode <TContent> Create <TContent>(IContentNode <IContent> parentNode, string name, Action <TContent> populate = null) where TContent : class, IContentData { var parent = parentNode.Content; CultureInfo language; ILocalizable localizableParent = parent as ILocalizable; if (localizableParent != null && localizableParent.Language != null) { language = localizableParent.Language; } else { language = ContentLanguage.PreferredCulture; } IContent defaultContent = GetDefaultContent( parent, _contentTypeRepository.Load <TContent>().ID, new LanguageSelector(language.Name)); defaultContent.Name = name; var contentLink = GetNextContentLink(); defaultContent.ContentLink = contentLink; defaultContent.ContentGuid = GetOrCreateGuid(contentLink); DateTime date = DateTime.Now.AddDays(-7); var versionable = defaultContent as IVersionable; if (versionable != null) { versionable.StartPublish = date; versionable.Status = VersionStatus.Published; versionable.IsPendingPublish = false; } var changeTrackable = defaultContent as IChangeTrackable; if (changeTrackable != null) { changeTrackable.Changed = date; changeTrackable.Created = date; changeTrackable.Saved = date; changeTrackable.ChangedBy = "Static"; changeTrackable.CreatedBy = "Static"; } var routable = defaultContent as IRoutable; if (routable != null) { routable.RouteSegment = name.ToLower().Replace(" ", "-"); } populate?.Invoke((TContent)defaultContent); var localizable = defaultContent as ILocalizable; if (localizable != null) { localizable.ExistingLanguages = new[] { localizable.MasterLanguage }; } // Normally we make the content read only here, but we need to update it later var node = new ContentNode <TContent> { Content = (TContent)defaultContent, Parent = parentNode }; parentNode.Children.Add(node); _allContents.Add(node); return(node); }
/// <summary> /// Construct the exceptions. /// </summary> /// <param name="pattern">Message pattern providing the specific context of the error.</param> /// <param name="args">Arguments.</param> public NullArgumentException(ILocalizable pattern, params object[] args) : base(pattern, args) { }
public EntityResourceValidator(ILocalizable <T> model, EntityResourceKind kind, IStringLocalizer localizer) { RuleFor(m => m.CultureId).NotEmpty().WithMessage(localizer["The culture is required."]); RuleFor(m => m.CultureId).IsUnique(model.Resources.Where(r => r.ResourceKind == kind)).WithMessage(localizer["The culture must be unique."]); }
private void appendLocalization(ILocalizable localizable, string id, List <(XmlString xmlString, bool hasRead)> strings)
/// <summary> /// Simple constructor. /// </summary> /// <param name="inner">The root cause.</param> /// <param name="pattern">Message pattern explaining the cause of the error.</param> /// <param name="args">Arguments.</param> public MathIllegalStateException(Exception inner, ILocalizable pattern, params object[] args): base("", inner) { context = new ExceptionContext(this); context.AddMessage(pattern, args); }
/// <summary> /// Adds a message. /// </summary> /// <param name="pattern">Message pattern.</param> /// <param name="arguments">Values for replacing the placeholders in the message patterns.</param> public virtual void AddMessage(ILocalizable pattern, params object[] arguments) { messagePatterns.Add(pattern); messageArguments.Add(arguments.Flatten()); }
/// <summary> /// Constructor that add a message. /// </summary> /// <param name="pattern">Message pattern explaining the cause of the error.</param> /// <param name="args">Arguments.</param> public MathIllegalArgumentException(ILocalizable pattern, params object[] args) { context = new ExceptionContext(this); context.AddMessage(pattern, args); }
public ClientResourceUriValidator(ILocalizable <ClientLocalizedResource> model, EntityResourceKind kind, IStringLocalizer localizer) : base(model, kind, localizer) { RuleFor(m => m.Value).Uri().WithMessage(m => localizer["{0} is not a valid uri.", m.Value]); }
public static TLocale GetCurrentLocale <TLocale>(this ILocalizable <TLocale> localizable) where TLocale : class, ILocale { return(localizable.GetLocale(CultureHelper.CurrentCultureId)); }
/// <summary> /// Constructor with a specific message. /// </summary> /// <param name="pattern">Message pattern providing the specific context of the error.</param> /// <param name="args">Arguments.</param> public MathArithmeticException(ILocalizable pattern, params object[] args) { context = new ExceptionContext(this); context.AddMessage(pattern, args); }
protected virtual string LocalizeEntityProperty <TEntityResource>(ILocalizable <TEntityResource> entity, string value, EntityResourceKind kind) where TEntityResource : IEntityResource { return(entity.Resources.FirstOrDefault(r => r.ResourceKind == kind && r.CultureId == CultureInfo.CurrentCulture.Name)?.Value ?? value); }
/// <summary> /// Construct the exception with a specific context. /// </summary> /// <param name="specific">Contextual information on what caused the exception.</param> public NoDataException(ILocalizable specific) : base(specific) { }
/// <summary> /// Construct the exception with a specific context. /// </summary> /// <param name="specific">Specific context pattern.</param> /// <param name="max">The maximum</param> /// <param name="args">Additional arguments.</param> public MaxCountExceededException(ILocalizable specific, int max, params object[] args) { Context.AddMessage(specific, max, args); this.Max = max; }
public string GetLocalizedValue(object value, string suffix, CultureIdentifier culture, params object[] args) { if (value == null) { return("<!! NULL !!>"); } ILocalizable localizableValue = value as ILocalizable; string localizedValue; object valueKey = Tuple.Create(value, suffix); if (!localizedValueMap.TryGetValue(valueKey, out localizedValue)) { string valueType = value.GetType().Name; string valueName = value.ToString(); Enum enumValue = value as Enum; bool isFlags = enumValue != null && enumValue.GetType().GetTypeInfo().GetCustomAttributes <FlagsAttribute>().Any(); if (isFlags && ((int)value) != 0) { List <string> localizedEnumParts = new List <string>(); foreach (var flag in Enum.GetValues(enumValue.GetType())) { if (((int)flag != 0) && enumValue.HasFlag((Enum)flag)) { localizedEnumParts.Add(GetRawLocalizedValue(flag, culture)); } } localizedValue = string.Join(", ", localizedEnumParts); } else if (localizableValue != null) { // If it's localized, then we'll let them determine // the appropriate way to get the raw localized value localizedValue = localizableValue.ToString(this); } else { string localizedValueKey = string.Format("{0}_{1}", valueType, valueName); if (!string.IsNullOrWhiteSpace(suffix)) { localizedValueKey = localizedValueKey + "_" + suffix; } #if NETFX_CORE ResourceContext context = new ResourceContext(); context.Languages = new string[] { ResolveCulture(culture).ToString() }; ResourceCandidate localizedCandidate = map.GetValue(localizedValueKey, context); if (localizedCandidate == null) { System.Diagnostics.Debug.WriteLine($"Unable to find localized value {localizedValueKey}"); } localizedValue = localizedCandidate?.ValueAsString ?? "!! Missing Resource for " + localizedValueKey + " !!"; #else localizedValue = this.ResourceLoader.GetString(localizedValueKey, ResolveCulture(culture)) ?? "!! Missing Resource for " + localizedValueKey + " !!"; #endif } localizedValueMap[valueKey] = localizedValue; } if (localizableValue != null) { args = args == null || args.Length == 0 ? localizableValue.LocalizedContext : args; } if (args != null && args.Length > 0) { return(string.Format(localizedValue, args)); } return(localizedValue); }
internal static void Register(ILocalizable localizable) { localizables.Add(localizable); }
public static TLocale GetLocale <TLocale>(this ILocalizable <TLocale> localizable, int cultureId) where TLocale : class, ILocale { return(localizable != null?localizable.Localizations.SingleOrDefault(a => a.CultureId == cultureId) : Activator.CreateInstance <TLocale>()); }
internal static void UnRegister(ILocalizable localizable) { localizables.Remove(localizable); }