Exemplo n.º 1
0
 public UserProfile()
 {
     CreatedAt         = DateTime.Now;
     UpdatedAt         = DateTime.Now;
     PasswordUpdatedAt = DateTime.Now;
     Locale            = _defaultLocale;
 }
Exemplo n.º 2
0
        static UserProfile()
        {
            _defaultLocale = LocaleLanguage.Ru;
            _cultures      = new Dictionary <LocaleLanguage, CultureInfo>();

            foreach (LocaleLanguage language in Enum.GetValues(typeof(LocaleLanguage)))
            {
                _cultures.Add(language, new CultureInfo(language.ToString()));
            }
        }
Exemplo n.º 3
0
 public UserProfile(string locale) : this()
 {
     try
     {
         Locale = (LocaleLanguage)Enum.Parse(typeof(LocaleLanguage), locale, true);
     }
     catch (Exception)
     {
         Locale = _defaultLocale;
     }
 }
Exemplo n.º 4
0
        public string ToString(LocaleLanguage locale)
        {
            string text = Localize(locale, Template);

            for (int i = 0; i < Parameters.Count; i++)
            {
                string parameter = Localize(locale, Parameters[i]);
                text = text.Replace($"{{{i}}}", parameter);
            }
            return(text);
        }
Exemplo n.º 5
0
        private static string Localize(LocaleLanguage locale, string text)
        {
            if (string.IsNullOrEmpty(text) || text[0] != '{')
            {
                return(text ?? string.Empty);
            }
            // '{' '<category>' ':' '<entry>' '}'
            //  0   1            i   i+1       length-1
            int    separatorIndex = text.IndexOf(':');
            string category       = text.Substring(1, separatorIndex - 1);
            string entry          = text.Substring(separatorIndex + 1, text.Length - separatorIndex - 2);

            return(locale.GetText(category, entry));
        }
        private static string SerializeLanguage(LocaleLanguage lang)
        {
            //TODO: Optimization of this function
            var serializer   = new JsonSerializer();
            var stringWriter = new StringWriter();

            using (var writer = new JsonTextWriter(stringWriter))
            {
                serializer.Serialize(writer, lang);
            }
            var json   = stringWriter.ToString();
            var result = json.Replace("\"", "");

            return(result);
        }