Esempio n. 1
0
        private static ResourceBase CreateResource(string resourceName, CultureInfo culture, string resourceLocation)
        {
            Func <string, string> fixResourceName = c => resourceName + ((c != null) ? "." + c : string.Empty) + ".resx";

            IVirtualPathProvider vpp = DI.Current.Resolve <IVirtualPathProvider>();

            // First try the file path Resource.fr-CA.resx
            string fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.ToString()));
            bool   exists           = vpp.FileExists(fullResourcePath);

            // If not found, try Resource.fr.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(culture.TwoLetterISOLanguageName));
                exists           = vpp.FileExists(fullResourcePath);
            }

            // If nothing is found try Resource.resx
            if (!exists)
            {
                fullResourcePath = vpp.CombinePaths(resourceLocation, fixResourceName(null));
                exists           = vpp.FileExists(fullResourcePath);
            }

            ResourceBase resource = exists ?
                                    new ResXResource(DI.Current.Resolve <IPathResolver>().Resolve(fullResourcePath)) :
                                    new EmbeddedResource(resourceName, culture) as ResourceBase;

            return(resource);
        }
Esempio n. 2
0
        public LocalizationService(string resourceName, CultureInfo culture)
        {
            Guard.IsNotNullOrEmpty(resourceName, "resourceName");
            Guard.IsNotNull(culture, "culture");

            resource = DetectResource("~/App_GlobalResources", resourceName, culture);
        }
        public LocalizationService(string resourceName, CultureInfo culture)
        {
            Guard.IsNotNullOrEmpty(resourceName, "resourceName");
            Guard.IsNotNull(culture, "culture");

            resource = DetectResource("~/App_GlobalResources", resourceName, culture);
        }
        public LocalizationService(string resourceLocation, string resourceName, CultureInfo culture)
        {
            Guard.IsNotNullOrEmpty(resourceLocation, "resourceLocation");
            Guard.IsNotNullOrEmpty(resourceName, "resourceName");
            Guard.IsNotNull(culture, "culture");

            resource = DetectResource(resourceLocation, resourceName, culture);
        }
Esempio n. 5
0
        private static ResourceBase DetectResource(string resourceLocation, string resourceName, CultureInfo culture)
        {
            string cacheKey = resourceName + ":" + culture;

            ResourceBase resource;

            using (syncLock.ReadAndWrite())
            {
                if (!cache.TryGetValue(cacheKey, out resource))
                {
                    using (syncLock.Write())
                    {
                        if (!cache.TryGetValue(cacheKey, out resource))
                        {
                            resource = CreateResource(resourceName, culture, resourceLocation);

                            cache.Add(cacheKey, resource);
                        }
                    }
                }
            }

            return(resource);
        }
        private static ResourceBase DetectResource(string resourceLocation, string resourceName, CultureInfo culture)
        {
            string cacheKey = resourceName + ":" + culture;

            ResourceBase resource;

            using (syncLock.ReadAndWrite())
            {
                if (!cache.TryGetValue(cacheKey, out resource))
                {
                    using (syncLock.Write())
                    {
                        if (!cache.TryGetValue(cacheKey, out resource))
                        {
                            resource = CreateResource(resourceName, culture, resourceLocation);

                            cache.Add(cacheKey, resource);
                        }
                    }
                }
            }

            return resource;
        }