Exemplo n.º 1
0
        public static async Task <string> TimeSpanStrAsync(TimeSpan ts, ITranslatorProvider1 trans)
        {
            // a translated time span
            string arg;
            string txt = await trans.TranslateAsync(TimeSpanStr2(ts, out arg));

            if (arg == null)
            {
                return(txt);
            }
            return(string.Format(txt, arg));
        }
Exemplo n.º 2
0
        // use [TransRequired] not [Required]

        public override string FormatErrorMessage(string name)
        {
            // override ValidationAttribute
            ITranslatorProvider1 trans = TransValidationAttribute.GetTranslatorProvider();

            if (trans != null)
            {
                Task <string> task = trans.TranslateAsync(base.ErrorMessageString ?? "The {0} field is required.");
                task.Wait();        // Wait for async.
                string errorMsg = task.Result;
                return(string.Format(errorMsg, name));
            }

            return(base.FormatErrorMessage(name));
        }