Exemplo n.º 1
0
 public static void Init(string localePath)
 {
     defaultService = new Lazy<ILocalizingService>(() =>
         {
             var poFileWatcher = new PoFileWatcher(localePath);
             var genericCache = new GenericCache<IDictionary<string, I18NMessage>>();
             poFileWatcher.OnChange +=
                 (o, e) => genericCache.Reset(new ChangeListParser(e.ChangeList).GetChangedCultures());
             poFileWatcher.Begin();
             return new LocalizingService(genericCache, localePath, new I18NPoFileParser());
         }, true);
 }
Exemplo n.º 2
0
        public void should_reset_cache_when_po_file_changed()
        {
            var parser = new Mock<IPoFileParser>();
             var expectedI18NMessages = new[] { new I18NMessage("translation key", "translation key") };
            var localeEnUsMessagesPo = Path.Combine(TestHelper.GetRuntimePath(),"locale\\en-US\\messages.po");
            parser.Setup(p => p.Parse(localeEnUsMessagesPo)).Returns(expectedI18NMessages.ToDictionary(d => d.MsgId));

            var i18NMessagesCache = new GenericCache<IDictionary<string, I18NMessage>>();

            var actualI18NMessages = i18NMessagesCache.Get("en-US", () => parser.Object.Parse(localeEnUsMessagesPo));

            VerifyResult(expectedI18NMessages, actualI18NMessages);

            expectedI18NMessages = new[] { new I18NMessage("translation key", "new translation") };
            parser.Setup(p => p.Parse(localeEnUsMessagesPo)).Returns(expectedI18NMessages.ToDictionary(d => d.MsgId));

            string[] changedCultures = {"en-US"};
            i18NMessagesCache.Reset(changedCultures);

            actualI18NMessages = i18NMessagesCache.Get("en-US", () => parser.Object.Parse(localeEnUsMessagesPo));
            VerifyResult(expectedI18NMessages, actualI18NMessages);
        }