public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int count;

            if (value is int)
            {
                count = (int)value;
            }
            else
            {
                return(null);
            }

            return(Language.Declension(
                       count,
                       NominativeSingular,
                       NominativePlural,
                       GenitiveSingular,
                       GenitivePlural).ToLower(CultureInfo.CurrentUICulture));
        }
Ejemplo n.º 2
0
        private void UpdateSubtitles()
        {
            var allowCount = _selectedAllowUsers.Users.Count;

            AllowUsersSubtitle = allowCount == 0
                ? AppResources.NoUsers
                : Language.Declension(
                allowCount,
                AppResources.UserNominativeSingular,
                AppResources.UserNominativePlural,
                AppResources.UserGenitiveSingular,
                AppResources.UserGenitivePlural).ToLower(CultureInfo.CurrentUICulture);

            var disallowCount = _selectedDisallowUsers.Users.Count;

            DisallowUsersSubtitle = disallowCount == 0
                ? AppResources.NoUsers
                : Language.Declension(
                disallowCount,
                AppResources.UserNominativeSingular,
                AppResources.UserNominativePlural,
                AppResources.UserGenitiveSingular,
                AppResources.UserGenitivePlural).ToLower(CultureInfo.CurrentUICulture);
        }
Ejemplo n.º 3
0
        private void UpdateConfirmWaitString()
        {
            var interval = _confirmWait.TotalSeconds - (DateTime.Now - _startTime).TotalSeconds;

            if (interval <= 1.0)
            {
                IsTimerVisible = false;
                NotifyOfPropertyChange(() => IsTimerVisible);
            }
            else if (interval < 0.0)
            {
                interval = 0.0;
                _timer.Stop();
            }
            else if (interval < 3600.0)
            {
                _timer.Interval = TimeSpan.FromSeconds(0.25);
            }

            var confirmWait = TimeSpan.FromSeconds(interval);

            var builder = new StringBuilder();

            if (confirmWait.Days > 0)
            {
                var days = Language.Declension(
                    confirmWait.Days,
                    AppResources.DayNominativeSingular,
                    AppResources.DayNominativePlural,
                    AppResources.DayGenitiveSingular,
                    AppResources.DayGenitivePlural,
                    confirmWait.Days < 2
                        ? string.Format("**{1}** {0}", AppResources.DayNominativeSingular, Math.Abs(confirmWait.Days)).ToLowerInvariant()
                        : string.Format("**{1}** {0}", AppResources.DayNominativePlural, Math.Abs(confirmWait.Days))).ToLowerInvariant();

                builder.Append(string.Format("{0} ", days));
            }
            if (confirmWait.Hours > 0 || confirmWait.Days > 0)
            {
                var hours = Language.Declension(
                    confirmWait.Hours,
                    AppResources.HourNominativeSingular,
                    AppResources.HourNominativePlural,
                    AppResources.HourGenitiveSingular,
                    AppResources.HourGenitivePlural,
                    confirmWait.Hours < 2
                        ? string.Format("**{1}** {0}", AppResources.HourNominativeSingular, Math.Abs(confirmWait.Hours)).ToLowerInvariant()
                        : string.Format("**{1}** {0}", AppResources.HourNominativePlural, Math.Abs(confirmWait.Hours))).ToLowerInvariant();

                builder.Append(string.Format("{0} ", hours));
            }
            if (confirmWait.Minutes > 0 || confirmWait.Hours > 0 || confirmWait.Days > 0)
            {
                var minutes = Language.Declension(
                    confirmWait.Minutes,
                    AppResources.MinuteNominativeSingular,
                    AppResources.MinuteNominativePlural,
                    AppResources.MinuteGenitiveSingular,
                    AppResources.MinuteGenitivePlural,
                    confirmWait.Minutes < 2
                        ? string.Format("**{1}** {0}", AppResources.MinuteNominativeSingular, Math.Abs(confirmWait.Minutes)).ToLowerInvariant()
                        : string.Format("**{1}** {0}", AppResources.MinuteNominativePlural, Math.Abs(confirmWait.Minutes))).ToLowerInvariant();

                builder.Append(string.Format("{0} ", minutes));
            }
            if (confirmWait.TotalSeconds < 3600)
            {
                var seconds = Language.Declension(
                    confirmWait.Seconds,
                    AppResources.SecondNominativeSingular,
                    AppResources.SecondNominativePlural,
                    AppResources.SecondGenitiveSingular,
                    AppResources.SecondGenitivePlural,
                    confirmWait.Seconds < 2
                        ? string.Format("**{1}** {0}", AppResources.SecondNominativeSingular, Math.Abs(confirmWait.Seconds)).ToLowerInvariant()
                        : string.Format("**{1}** {0}", AppResources.SecondNominativePlural, Math.Abs(confirmWait.Seconds))).ToLowerInvariant();

                builder.Append(string.Format("{0} ", seconds));
            }

            ConfirmWaitString = builder.ToString();
            NotifyOfPropertyChange(() => ConfirmWaitString);
            NotifyOfPropertyChange(() => CanResetAccount);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var messagesContainer = value as TLMessagesContainter;

            if (messagesContainer != null)
            {
                if (messagesContainer.FwdMessages != null)
                {
                    var count = messagesContainer.FwdMessages.Count;
                    if (count == 1)
                    {
                        var mediaPhoto = messagesContainer.FwdMessages[0].Media as TLMessageMediaPhoto;
                        if (mediaPhoto != null)
                        {
                            return(AppResources.ForwardedPhotoNominativeSingular);
                        }

                        var mediaAudio = messagesContainer.FwdMessages[0].Media as TLMessageMediaAudio;
                        if (mediaAudio != null)
                        {
                            return(AppResources.ForwardedAudioNominativeSingular);
                        }

                        var mediaDocument = messagesContainer.FwdMessages[0].Media as TLMessageMediaDocument;
                        if (mediaDocument != null)
                        {
                            if (messagesContainer.FwdMessages[0].IsSticker())
                            {
                                return(AppResources.ForwardedStickerNominativeSingular);
                            }

                            return(AppResources.ForwardedFileNominativeSingular);
                        }

                        var mediaVideo = messagesContainer.FwdMessages[0].Media as TLMessageMediaVideo;
                        if (mediaVideo != null)
                        {
                            return(AppResources.ForwardedVideoNominativeSingular);
                        }

                        var mediaLocation = messagesContainer.FwdMessages[0].Media as TLMessageMediaGeo;
                        if (mediaLocation != null)
                        {
                            return(AppResources.ForwardedLocationNominativeSingular);
                        }

                        var mediaContact = messagesContainer.FwdMessages[0].Media as TLMessageMediaContact;
                        if (mediaContact != null)
                        {
                            return(AppResources.ForwardedContactNominativeSingular);
                        }

                        return(AppResources.ForwardedMessage);
                    }
                    if (count > 1)
                    {
                        var sameMedia = true;
                        var media     = messagesContainer.FwdMessages[0].Media;
                        for (var i = 1; i < messagesContainer.FwdMessages.Count; i++)
                        {
                            if (messagesContainer.FwdMessages[i].Media.GetType() != media.GetType())
                            {
                                sameMedia = false;
                                break;
                            }
                        }

                        if (sameMedia)
                        {
                            if (media is TLMessageMediaPhoto)
                            {
                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedPhotoNominativeSingular,
                                           AppResources.ForwardedPhotoNominativePlural,
                                           AppResources.ForwardedPhotoGenitiveSingular,
                                           AppResources.ForwardedPhotoGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }

                            if (media is TLMessageMediaAudio)
                            {
                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedAudioNominativeSingular,
                                           AppResources.ForwardedAudioNominativePlural,
                                           AppResources.ForwardedAudioGenitiveSingular,
                                           AppResources.ForwardedAudioGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }

                            if (media is TLMessageMediaDocument)
                            {
                                if (messagesContainer.FwdMessages[0].IsSticker())
                                {
                                    return(Language.Declension(
                                               count,
                                               AppResources.ForwardedStickerNominativeSingular,
                                               AppResources.ForwardedStickerNominativePlural,
                                               AppResources.ForwardedStickerGenitiveSingular,
                                               AppResources.ForwardedStickerGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                                }

                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedFileNominativeSingular,
                                           AppResources.ForwardedFileNominativePlural,
                                           AppResources.ForwardedFileGenitiveSingular,
                                           AppResources.ForwardedFileGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }

                            if (media is TLMessageMediaVideo)
                            {
                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedVideoNominativeSingular,
                                           AppResources.ForwardedVideoNominativePlural,
                                           AppResources.ForwardedVideoGenitiveSingular,
                                           AppResources.ForwardedVideoGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }

                            if (media is TLMessageMediaGeo)
                            {
                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedLocationNominativeSingular,
                                           AppResources.ForwardedLocationNominativePlural,
                                           AppResources.ForwardedLocationGenitiveSingular,
                                           AppResources.ForwardedLocationGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }

                            if (media is TLMessageMediaContact)
                            {
                                return(Language.Declension(
                                           count,
                                           AppResources.ForwardedContactNominativeSingular,
                                           AppResources.ForwardedContactNominativePlural,
                                           AppResources.ForwardedContactGenitiveSingular,
                                           AppResources.ForwardedContactGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                            }
                        }

                        return(Language.Declension(
                                   count,
                                   AppResources.ForwardedMessageNominativeSingular,
                                   AppResources.ForwardedMessageNominativePlural,
                                   AppResources.ForwardedMessageGenitiveSingular,
                                   AppResources.ForwardedMessageGenitivePlural).ToLower(CultureInfo.CurrentUICulture));
                    }
                }
            }

            return(value);
        }