protected void ShowDialog(ErrorBase error, LocalizationKeys leftButtonText, LocalizationKeys rightButtonText, Action <UIAlertAction> leftButtonAction = null, Action <UIAlertAction> rightButtonAction = null)
        {
            if (error == null || error is CanceledError)
            {
                return;
            }

            var message = error.Message;

            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            var lm = AppSettings.LocalizationManager;

            if (!lm.ContainsKey(message))
            {
                if (error is BlockchainError blError)
                {
                    AppSettings.Reporter.SendMessage($"New message: {LocalizationManager.NormalizeKey(blError.Message)}{Environment.NewLine}Full Message:{blError.FullMessage}");
                }
                else
                {
                    AppSettings.Reporter.SendMessage($"New message: {LocalizationManager.NormalizeKey(message)}");
                }
                message = nameof(LocalizationKeys.UnexpectedError);
            }

            var alert = UIAlertController.Create(null, lm.GetText(message), UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(lm.GetText(leftButtonText), UIAlertActionStyle.Cancel, leftButtonAction));
            alert.AddAction(UIAlertAction.Create(lm.GetText(rightButtonText), UIAlertActionStyle.Default, rightButtonAction));
            PresentViewController(alert, true, null);
        }
        protected void ShowAlert(LocalizationKeys key)
        {
            var message = AppSettings.LocalizationManager.GetText(key);
            var alert   = UIAlertController.Create(null, Regex.Replace(message, @"[^\w\s-]", "", RegexOptions.None), UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(AppSettings.LocalizationManager.GetText(LocalizationKeys.Ok), UIAlertActionStyle.Cancel, null));
            PresentViewController(alert, true, null);
        }
Пример #3
0
        public static void ShowAlert(this Context context, LocalizationKeys key)
        {
            var lm    = AppSettings.LocalizationManager;
            var btnOk = lm.GetText(LocalizationKeys.Ok);
            var msg   = lm.GetText(key);

            CreateAndShowDialog(context, msg, btnOk);
        }
Пример #4
0
 /// <summary>
 /// Get all <see cref="LocalizationKey"/> that do no have a localization in a culture.
 /// </summary>
 /// <param name="culture">The culture</param>
 /// <returns>All keys with missing localizations</returns>
 public IQueryable <LocalizationKey> GetMissingLocalizationsForCulture(SupportedCulture culture)
 => LocalizationKeys
 .Where(k => !SupportedCultures
        .Where(c => c.Id == culture.Id)
        .SelectMany(s => s.Records
                    .Where(r => r.Status != RecordStatus.New)
                    .Select(r => r.LocalizationKey.Id)
                    )
        .Contains(k.Id)
        );
Пример #5
0
        public static async Task <string> GetLocalizationAsync(LocalizationKeys key, Language lang, DataContext db)
        {
            var localization = await db.Localization.FirstOrDefaultAsync(l => l.Name == key.ToString());

            if (localization != null)
            {
                return(localization.Texts.FirstOrDefault(t => t.Language == lang)?.Value ?? localization.Texts.First(t => t.Language == lang).Value);
            }

            return(String.Empty);
        }
Пример #6
0
        public static void ShowAlert(this Context context, LocalizationKeys key)
        {
            var lm    = AppSettings.LocalizationManager;
            var alert = new AlertDialog.Builder(context);

            alert.SetMessage(lm.GetText(key));
            alert.SetPositiveButton(lm.GetText(LocalizationKeys.Ok), (senderAlert, args) => { });
            Dialog dialog = alert.Create();

            dialog.Show();
        }
Пример #7
0
        public static void ShowAlert(this Context context, LocalizationKeys keys, ToastLength length)
        {
            if (IsDestroyed(context))
            {
                return;
            }

            var message = AppSettings.LocalizationManager.GetText(keys);

            Toast.MakeText(context, message, length).Show();
        }
        protected void ShowDialog(Exception exception, LocalizationKeys leftButtonText, LocalizationKeys rightButtonText, Action <UIAlertAction> leftButtonAction = null, Action <UIAlertAction> rightButtonAction = null)
        {
            if (IsSkeepError(exception))
            {
                return;
            }

            var message = GetMsg(exception);

            var alert = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(AppSettings.LocalizationManager.GetText(leftButtonText), UIAlertActionStyle.Cancel, leftButtonAction));
            alert.AddAction(UIAlertAction.Create(AppSettings.LocalizationManager.GetText(rightButtonText), UIAlertActionStyle.Default, rightButtonAction));
            PresentViewController(alert, true, null);
        }
        public void SetLocale(string languageKey)
        {
            this.languageKey = languageKey;
            string filename = languageKey + "/LocalizationKeys";

            TextAsset languageAsset = Resources.Load <TextAsset>(filename);

            if (languageAsset != null)
            {
                currentKeys = JsonUtility.FromJson <LocalizationKeys>(languageAsset.text);

                // Set to active scene name.
                currentKeys.Title = FormattedSceneName();

                // Read from file
                currentKeys.OverviewDescription = LoadTextFromFile(currentKeys.OverviewDescription, "Overview");
                currentKeys.ControlsDescription = LoadTextFromFile(currentKeys.ControlsDescription, "Controls");
                currentKeys.StatusDescription   = LoadTextFromFile(currentKeys.StatusDescription, "Status");
            }
        }
        protected void ShowCustomAlert(LocalizationKeys key, UIView viewToStartEditing)
        {
            var message = AppSettings.LocalizationManager.GetText(key);
            var popup   = new UIView();

            popup.Frame                  = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
            popup.BackgroundColor        = UIColor.Black.ColorWithAlpha(0.5f);
            popup.UserInteractionEnabled = true;

            var blur     = UIBlurEffect.FromStyle(UIBlurEffectStyle.ExtraLight);
            var blurView = new UIVisualEffectView(blur);

            blurView.ClipsToBounds      = true;
            blurView.Layer.CornerRadius = 15;
            popup.AddSubview(blurView);

            blurView.AutoCenterInSuperview();
            blurView.AutoSetDimension(ALDimension.Width, _alertWidth);

            var okButton = new UIButton();

            okButton.SetTitle("Ok", UIControlState.Normal);
            okButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            blurView.ContentView.AddSubview(okButton);

            okButton.AutoPinEdge(ALEdge.Bottom, ALEdge.Bottom, blurView);
            okButton.AutoPinEdge(ALEdge.Left, ALEdge.Left, blurView);
            okButton.AutoPinEdge(ALEdge.Right, ALEdge.Right, blurView);
            okButton.AutoSetDimension(ALDimension.Height, 50);

            var textView = new UITextView();

            textView.DataDetectorTypes      = UIDataDetectorType.Link;
            textView.UserInteractionEnabled = true;
            textView.Editable        = false;
            textView.Font            = Constants.Semibold16;
            textView.TextAlignment   = UITextAlignment.Center;
            textView.Text            = message;
            textView.BackgroundColor = UIColor.Clear;
            blurView.ContentView.AddSubview(textView);

            textView.AutoPinEdge(ALEdge.Top, ALEdge.Top, blurView, 7);
            textView.AutoPinEdge(ALEdge.Left, ALEdge.Left, blurView, _textSideMargin);
            textView.AutoPinEdge(ALEdge.Right, ALEdge.Right, blurView, -_textSideMargin);

            var size = textView.SizeThatFits(new CGSize(_alertWidth - _textSideMargin * 2, 0));

            textView.AutoSetDimension(ALDimension.Height, size.Height + 7);

            var separator = new UIView();

            separator.BackgroundColor = UIColor.LightGray;
            blurView.ContentView.AddSubview(separator);

            separator.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, textView, 0);
            separator.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, okButton);
            separator.AutoPinEdge(ALEdge.Left, ALEdge.Left, blurView);
            separator.AutoPinEdge(ALEdge.Right, ALEdge.Right, blurView);
            separator.AutoSetDimension(ALDimension.Height, 1);

            ((InteractivePopNavigationController)NavigationController).IsPushingViewController = true;

            okButton.TouchDown += (sender, e) =>
            {
                viewToStartEditing?.BecomeFirstResponder();
                ((InteractivePopNavigationController)NavigationController).IsPushingViewController = false;
                popup.RemoveFromSuperview();
            };

            NavigationController.View.EndEditing(true);
            NavigationController.View.AddSubview(popup);

            blurView.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.001f, 0.001f);

            UIView.Animate(0.1, () =>
            {
                blurView.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 1.1f, 1.1f);
            }, () =>
            {
                UIView.Animate(0.1, () =>
                {
                    blurView.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.9f, 0.9f);
                }, () =>
                {
                    UIView.Animate(0.1, () =>
                    {
                        blurView.Transform = CGAffineTransform.MakeIdentity();
                    }, null);
                });
            });
        }
Пример #11
0
 public ValidationException(LocalizationKeys key, params object[] parameters)
 {
     Key        = key;
     Parameters = parameters;
 }
Пример #12
0
 public InternalException(LocalizationKeys key, Exception ex) : base(key.ToString(), ex)
 {
     Key = key;
 }
Пример #13
0
 /// <summary>
 /// Returns list of all available keys
 /// </summary>
 /// <returns></returns>
 public List <LocalizationKey> GetAllKeys(CultureInfo culture = null)
 {
     return(LocalizationKeys.ToList());
 }
Пример #14
0
        /// <summary>
        /// Sets new translation for the provided key and language (or current culture language if not provided)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="collection"></param>
        /// <param name="category"></param>
        /// <param name="culture"></param>
        public void Set(string key, string value, string collection, string category, CultureInfo culture = null)
        {
            lock (Lock)
            {
                // Get the localization key Id. If it does not exist, create it first
                var localizationKey = LocalizationKeys.FirstOrDefault(x => x.Name.ToLower() == key.ToLower());
                if (localizationKey == null)
                {
                    localizationKey = new LocalizationKey {
                        Name = key
                    };
                    Provider.InsertLocalizationKey(localizationKey);
                    LocalizationKeys = Provider.LoadLocalizationKeys();
                    localizationKey  = LocalizationKeys.FirstOrDefault(x => x.Name.ToLower() == key.ToLower());
                }
                if (localizationKey == null)
                {
                    return;
                }

                // Get the localization language. If it does not exist, create it first
                var langName             = GetLanguageNameFromCulture(culture).ToLower();
                var langDisplayName      = GetLanguageDisplayNameFromCulture(culture);
                var localizationLanguage = LocalizationLanguages.FirstOrDefault(x => x.Name.ToLower() == GetLanguageNameFromCulture(culture).ToLower());
                if (localizationLanguage == null)
                {
                    localizationLanguage = new LocalizationLanguage
                    {
                        Name  = langName,
                        Value = langDisplayName
                    };
                    Provider.InsertLocalizationLanguage(localizationLanguage);
                    LocalizationLanguages = Provider.LoadLocalizationLanguages();
                    localizationLanguage  = LocalizationLanguages.FirstOrDefault(x => x.Name.ToLower() == GetLanguageNameFromCulture(culture).ToLower());
                }
                if (localizationLanguage == null)
                {
                    return;
                }

                // Get the localization collection. If it does not exist, create it first
                var localizationCategory = LocalizationCategories.FirstOrDefault(x => x.Name.ToLower() == category.ToLower());
                if (localizationCategory == null)
                {
                    localizationCategory = new LocalizationCategory
                    {
                        Name = category
                    };
                    Provider.InsertOrUpdateLocalizationCategory(localizationCategory);
                    LocalizationCategories = Provider.LoadLocalizationCategories();
                    localizationCategory   = LocalizationCategories.FirstOrDefault(x => x.Name.ToLower() == category.ToLower());
                }
                if (localizationCategory == null)
                {
                    return;
                }

                // Get the localization collection. If it does not exist, create it first
                var localizationCollection = LocalizationCollections.FirstOrDefault(x =>
                                                                                    x.Name.ToLower() == collection.ToLower() &&
                                                                                    x.LocalizationCategoryId == localizationCategory.Id);

                if (localizationCollection == null)
                {
                    localizationCollection = new LocalizationCollection
                    {
                        Name = collection,
                        LocalizationCategoryId = localizationCategory.Id
                    };
                    Provider.InsertOrUpdateLocalizationCollection(localizationCollection);
                    LocalizationCollections = Provider.LoadLocalizationCollections();
                    localizationCollection  = LocalizationCollections.FirstOrDefault(x =>
                                                                                     x.Name.ToLower() == collection.ToLower() &&
                                                                                     x.LocalizationCategoryId == localizationCategory.Id);
                }
                if (localizationCollection == null)
                {
                    return;
                }
                localizationCollection.LocalizationCategory   = localizationCategory;
                localizationCollection.LocalizationCategoryId = localizationCategory.Id;

                // Don't check the collection since only one combination of key and language is allowed across collections
                var entry = LocalizationEntries.FirstOrDefault(x => x.LocalizationKeyId == localizationKey.Id &&
                                                               x.LocalizationLanguageId == localizationLanguage.Id);

                if (entry == null)
                {
                    // Create
                    entry = new LocalizationEntry
                    {
                        Value = value,
                        LocalizationCollectionId = localizationCollection.Id,
                        LocalizationKeyId        = localizationKey.Id,
                        LocalizationLanguageId   = localizationLanguage.Id,
                        CreatedOn = DateTime.UtcNow,
                        UpdatedOn = DateTime.UtcNow
                    };
                    Provider.InsertLocalizationEntry(entry);
                    LocalizationEntries = Provider.LoadLocalizationEntries();
                }
            }
        }
Пример #15
0
 public ValidationException(LocalizationKeys key)
 {
     Key = key;
 }
Пример #16
0
 public BlockchainError(LocalizationKeys key) : base(key)
 {
 }
        public string GetText(LocalizationKeys key, params object[] args)
        {
            var ks = key.ToString();

            return(GetText(ks, args));
        }
Пример #18
0
 public ClientError(LocalizationKeys key) : base(key)
 {
 }
Пример #19
0
 public AppError(LocalizationKeys key) : base(key)
 {
 }
Пример #20
0
 public ErrorBase(LocalizationKeys key)
     : base(key.ToString())
 {
 }
Пример #21
0
 protected ErrorBase(LocalizationKeys key)
     : base(key.ToString())
 {
 }