Exemplo n.º 1
0
        /// <summary>
        /// Returns a valid culture name based on "name" parameter. If "name" is not valid, it returns the default culture "en-US"
        /// </summary>
        /// <param name="name" />Culture's name (e.g. en-US)</param>
        public static string GetImplementedCulture(string name)
        {
            Cultures = Cultures == null ? ValidCultures : Cultures;

            // make sure it's not null
            if (string.IsNullOrEmpty(name))
            {
                return(GetDefaultCulture); // return Default culture
            }
            // make sure it is a valid culture first
            if (ValidCultures.Where(c => c.Equals(name, StringComparison.Ordinal)).Count() == 0) // StringComparison.InvariantCultureIgnoreCase)).Count() == 0)
            {
                return(GetDefaultCulture);                                                       // return Default culture if it is invalid
            }
            // if it is implemented, accept it
            if (Cultures.Where(c => c.Equals(name, StringComparison.Ordinal)).Count() > 0)
            {
                return(name); // accept it
            }
            // Find a close match. For example, if you have "en-US" defined and the user requests "en-GB",
            // the function will return closes match that is "en-US" because at least the language is the same (ie English)
            var n = GetNeutralCulture(name);

            foreach (var c in Cultures)
            {
                if (c.StartsWith(n, StringComparison.Ordinal))
                {
                    return(c);
                }
            }
            // else
            // It is not implemented
            return(GetDefaultCulture); // return Default culture as no match found
        }
Exemplo n.º 2
0
 public override async Task <RepositoryResponse <bool> > RemoveRelatedModelsAsync(ReadMvcViewModel view, SioCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     foreach (var culture in Cultures.Where(c => c.Specificulture != Specificulture))
     {
         var lang = _context.SioLanguage.First(c => c.Keyword == Keyword && c.Specificulture == culture.Specificulture);
         if (lang != null)
         {
             _context.SioLanguage.Remove(lang);
         }
     }
     return(new RepositoryResponse <bool>()
     {
         IsSucceed = (await _context.SaveChangesAsync()) > 0
     });
 }
Exemplo n.º 3
0
 public override RepositoryResponse <bool> RemoveRelatedModels(SystemLanguageViewModel view, MixCmsContext _context = null, IDbContextTransaction _transaction = null)
 {
     foreach (var culture in Cultures.Where(c => c.Specificulture != Specificulture))
     {
         var lang = _context.MixLanguage.First(c => c.Keyword == Keyword && c.Specificulture == culture.Specificulture);
         if (lang != null)
         {
             _context.MixLanguage.Remove(lang);
         }
     }
     return(new RepositoryResponse <bool>()
     {
         IsSucceed = _context.SaveChanges() > 0
     });
 }