Exemplo n.º 1
0
 internal TranslateExtension(bool shouldInit)
 {
     if (shouldInit)
     {
         resProvider = DependencyService.Get <IDependencyGetter>().Get <ILocalizedResourceProvider>();
     }
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var d = value as DateTimeOffset?;

            if (value is DateTime)
            {
                d = (DateTime)value;
            }

            ILocalizedResourceProvider res = null;

            try
            {
                res = DependencyService.Get <IDependencyGetter>().Get <ILocalizedResourceProvider>();
            }
            catch
            {
                res = null;
            }

            if (!d.HasValue)
            {
                return(res?.GetText("TimeAgo_NA") ?? "N/A");
            }

            DateTimeOffset now      = DateTime.Now;
            var            timespan = now.Subtract(d.Value);

            if (timespan < TimeSpan.FromSeconds(60))
            {
                return(res?.GetText("TimeAgo_LessThan1Minute") ?? "Just now");
            }
            if (timespan < TimeSpan.FromMinutes(5))
            {
                return(res?.GetText("TimeAgo_LessThan5Minutes") ?? "Few minutes ago");
            }

            if (timespan < TimeSpan.FromMinutes(60))
            {
                return(res?.GetText("TimeAgo_LessThan1Hour", timespan.Minutes) ?? $"{timespan.Minutes} minutes ago");
            }

            if (timespan < TimeSpan.FromHours(24))
            {
                return(res?.GetText("TimeAgo_LessThan1Day", timespan.Hours) ?? $"{timespan.Hours} hours ago");
            }

            if (timespan < TimeSpan.FromDays(2))
            {
                return(res?.GetText("TimeAgo_Yesterday") ?? $"Yesterday");
            }

            if (timespan < TimeSpan.FromDays(7))
            {
                return(res?.GetText("TimeAgo_LessThan1Week", timespan.Days) ?? $"{timespan.Days} days ago");
            }

            return(res?.GetText("TimeAgo_Past", d.Value) ?? d.Value.ToString("MMM dd, YYYY"));
        }
Exemplo n.º 3
0
 public ILocalizedResourceProvider GetProvider()
 {
     if (_provider == null)
     {
         _provider = new ResourceFileProvider(Id, typeof(Resources.LocalizationResources));
     }
     return(_provider);
 }
Exemplo n.º 4
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ILocalizedResourceProvider res = null;

            try
            {
                res = DependencyService.Get <IDependencyGetter>().Get <ILocalizedResourceProvider>();
            }
            catch
            {
                res = null;
            }

            return(res?.GetText(value as string) ?? value);
        }