public void VerifyAllSharedPropsAreInEnglishResx()
        {
            var options = Options.Create(new LocalizationOptions {
                ResourcesPath = "Resources"
            });
            var factory   = new ResourceManagerStringLocalizerFactory(options, NullLoggerFactory.Instance);
            var localizer = new StringLocalizer <SharedResource>(factory);

            var sharedResourceAsm = Assembly.Load("SIL.XForge.Scripture");

            Assert.NotNull(sharedResourceAsm, "Um, what did you refactor?");
            var sharedResourceClass = sharedResourceAsm.GetType("SIL.XForge.Scripture.SharedResource");
            var sharedKeys          = sharedResourceClass?.GetNestedType("Keys");

            Assert.NotNull(sharedKeys, "Um, what did you refactor?");
            // grab all the localization keys from SharedResource.Keys static class
            var publicProps = sharedKeys.GetFields(BindingFlags.Public | BindingFlags.Static);

            foreach (var propInfo in publicProps.Where(x => x.FieldType == typeof(string)))
            {
                var keyValue = (string)propInfo.GetValue(null);
                var englishStringFromResource = localizer.GetString(keyValue);
                // verify that each key is found
                Assert.IsFalse(englishStringFromResource.ResourceNotFound,
                               "Missing english string from .resx for " + propInfo.Name);
            }

            Assert.AreEqual(publicProps.Length, localizer.GetAllStrings().Count(),
                            "There are extra strings in the SharedResources.en.resx which are not in the SharedResource.Keys class");
        }
예제 #2
0
파일: TmpPlugin.cs 프로젝트: qhtml5/system
        public override void InitPlugin()
        {
            Logger.LogInformation($"init tmp plugin {Guid.NewGuid()}");
            Logger.LogInformation(StringLocalizer.GetString("hello"));

            var sb = new StringBuilder("===================\nall strings:\n");

            foreach (var str in StringLocalizer.GetAllStrings(true))
            {
                sb.AppendLine($"{str.Name}: {str.Value} ({str.SearchedLocation})");
            }

            Logger.LogInformation(sb.ToString());

            Logger.LogInformation(StringLocalizer.GetString("bye"));
        }