public void GetResourceCultureNameTest(string fileName, string expectedCulture) { var resourceDescriptor = new ResourceDescriptor(); resourceDescriptor.FileName = fileName; var culture = ResourcesForCulture.GetResourceCultureName(resourceDescriptor); Assert.Equal(expectedCulture, culture); }
public static string GetResourceCultureName(ResourceDescriptor res) { var ext = Path.GetExtension(res.FileName); if (string.Equals(ext, ".resx", StringComparison.OrdinalIgnoreCase) || string.Equals(ext, ".restext", StringComparison.OrdinalIgnoreCase) || string.Equals(ext, ".resources", StringComparison.OrdinalIgnoreCase)) { var resourceBaseName = Path.GetFileNameWithoutExtension(res.FileName); var cultureName = Path.GetExtension(resourceBaseName); if (string.IsNullOrEmpty(cultureName) || cultureName.Length < 3) { return string.Empty; } // Path.Extension adds a . to the file extension name; example - ".resources". Removing the "." with Substring cultureName = cultureName.Substring(1); if (CultureInfoCache.KnownCultureNames.Contains(cultureName)) { return cultureName; } } return string.Empty; }