Exemple #1
0
	    public TextLocalizer(
            i18nSettings settings,
            ITranslationRepository translationRepository)
	    {
            _settings = settings;
		    _translationRepository = translationRepository;
	    }
        public void FileNuggetFinder_disable_references()
        {
            var settingService = new SettingService_Mock();
            settingService.SetSetting("i18n.WhiteList", "ReferencesTest.txt");
            {
                i18nSettings settings = new i18nSettings(settingService);
                FileNuggetFinder finder = new FileNuggetFinder(settings);
                var templates = finder.ParseAll();

                var item = templates.Values.First();

                Assert.AreEqual(5, item.References.Count());
            }
            {
                //Disabling references
                settingService.SetSetting("i18n.DisableReferences", "true");
                i18nSettings settings = new i18nSettings(settingService);
                FileNuggetFinder finder = new FileNuggetFinder(settings);
                var templates = finder.ParseAll();

                var item = templates.Values.First();

                Assert.AreEqual(1, item.References.Count());
            }
        }
        public void FileNuggetFinder_blacklist_wildcards()
        {
            var settingService = new SettingService_Mock();
            var root = Path.GetDirectoryName(settingService.GetConfigFileLocation());
            {
                //"*" wildcard
                settingService.SetSetting("i18n.BlackList", "./TestDir/*");
                i18nSettings settings = new i18nSettings(settingService);
                //FileNuggetFinder finder = new FileNuggetFinder(settings);
                List<string> expected = new List<string>()
                {
                    Path.Combine(root, "TestDir", "Dir02"),
                    Path.Combine(root, "TestDir", "Dir1"),
                };

                CollectionAssert.AreEqual(expected, settings.BlackList.ToList());
            }
            {
                //"?" wildcard
                settingService.SetSetting("i18n.BlackList", "./TestDir/Dir?");
                i18nSettings settings = new i18nSettings(settingService);
                List<string> expected = new List<string>()
                {
                    Path.Combine(root, "TestDir", "Dir1"),
                };

                CollectionAssert.AreEqual(expected, settings.BlackList.ToList());
            }
        }
Exemple #4
0
 public FileNuggetFinder(i18nSettings settings)
 {
     _settings     = settings;
     _nuggetParser = new NuggetParser(new NuggetTokens(
                                          _settings.NuggetBeginToken,
                                          _settings.NuggetEndToken,
                                          _settings.NuggetDelimiterToken,
                                          _settings.NuggetCommentToken),
                                      NuggetParser.Context.SourceProcessing);
 }
Exemple #5
0
		public FileNuggetFinder(i18nSettings settings)
		{
            _settings = settings;
            _nuggetParser = new NuggetParser(new NuggetTokens(
			    _settings.NuggetBeginToken,
			    _settings.NuggetEndToken,
			    _settings.NuggetDelimiterToken,
			    _settings.NuggetCommentToken),
                NuggetParser.Context.SourceProcessing);
		}
 public StringNuggetFinder(i18nSettings settings, Dictionary <string, string> strings)
 {
     _settings     = settings;
     _nuggetParser = new NuggetParser(new NuggetTokens(
                                          _settings.NuggetBeginToken,
                                          _settings.NuggetEndToken,
                                          _settings.NuggetDelimiterToken,
                                          _settings.NuggetCommentToken),
                                      NuggetParser.Context.SourceProcessing);
     _strings = strings;
 }
Exemple #7
0
        public NuggetLocalizer(
            i18nSettings settings,
            ITextLocalizer textLocalizer)
        {
            _settings = settings;
            _textLocalizer = textLocalizer;

            _nuggetParser = new NuggetParser(new NuggetTokens(
                _settings.NuggetBeginToken,
                _settings.NuggetEndToken,
                _settings.NuggetDelimiterToken,
                _settings.NuggetCommentToken),
                NuggetParser.Context.ResponseProcessing);
        }
Exemple #8
0
        static void Main(string[] args)
        {
			//TestCode
	        //args = new string[] {@"C:\viducate2\Viducate\Viducate.WebUI\Web.config"};

			string configPath;
			if (args.Length == 0)
			{
				System.Console.WriteLine("You have to specify path to web.config.");
				return;
			}

	        try
	        {
		        configPath = args[0];
				using (FileStream fs = File.Open(configPath, FileMode.Open))
		        {
			        
		        }
	        }
	        catch (Exception)
	        {
				System.Console.WriteLine("Failed to open config file at path.");
				return;
	        }

			//todo: this assumes PO files, if not using po files then other solution needed.
			i18nSettings settings = new i18nSettings(new WebConfigSettingService(configPath));
			POTranslationRepository rep = new POTranslationRepository(settings);

			FileNuggetFinder nugget = new FileNuggetFinder(settings);
	        var items = nugget.ParseAll();
	        rep.SaveTemplate(items);

			TranslationMerger ts = new TranslationMerger(rep);
			ts.MergeAllTranslation(items);
			

            Console.WriteLine("i18n.PostBuild completed successfully.");
        }
 public POTranslationRepository(i18nSettings settings)
 {
     _settings = settings;
 }
Exemple #10
0
 public POTranslationRepository(i18nSettings settings)
 {
     _settings = settings;
 }
Exemple #11
0
        public void NuggetLocalizer_can_visualize_nugget()
        {
            ITextLocalizer textLocalizer = new TextLocalizer_Mock_PrefixSuffix("xxx", "yyy");
            var settings = new i18nSettings(new WebConfigSettingService())
            {
                VisualizeMessages = true
            };

            i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(settings, textLocalizer);

            string pre = "[[[123]]] [[[456]]]";
            string post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("!xxx123yyy! !xxx456yyy!", post);
        }
Exemple #12
0
        private void Run()
        {
            ThrowIfConfigFileNotFound();

            ReferenceContext.ShowSourceContext = ShowSourceContext;

            //todo: this assumes PO files, if not using po files then other solution needed.
            var settings = new i18nSettings(new WebConfigSettingService(ConfigPath));
            settings.LocaleOtherFiles = Enumerable.Empty<string>();
            var repository = new POTranslationRepository(settings);

            var nuggetFinder = new FileNuggetFinder(settings);
            var items = nuggetFinder.ParseAll();
            repository.SaveTemplate(items);

            var merger = new TranslationMerger(repository);
            merger.MergeAllTranslation(items);

            Console.WriteLine("i18n.PostBuild completed successfully.");
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void _menuItemCallback(object sender, EventArgs e)
        {
            dynamic currentProject = _getCurrentProject();
            
            if (currentProject != null)
            {
                var dir = new DirectoryInfo((string) currentProject.FullName).Parent;

                // ReSharper disable PossibleNullReferenceException
                var configPath = dir.FullName + "\\web.config";
                // ReSharper restore PossibleNullReferenceException. Can't be null as is being picked from project
                if (!File.Exists(configPath))
                {
                    throw new Exception("Project does not have a web.config file");
                }

                var settings = new i18nSettings(new WebConfigSettingService(configPath));
                var rep = new POTranslationRepository(settings);

                var nugget = new FileNuggetFinder(settings);
                var items = nugget.ParseAll();
                rep.SaveTemplate(items);

                var ts = new TranslationMerger(rep);
                ts.MergeAllTranslation(items);
                var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                var clsid = Guid.Empty;
                int result;
                ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                           0,
                           ref clsid,
                           "i18n.POTGenerator",
                           string.Format(CultureInfo.CurrentCulture, "POT File generated correctly"),
                           string.Empty,
                           0,
                           OLEMSGBUTTON.OLEMSGBUTTON_OK,
                           OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                           OLEMSGICON.OLEMSGICON_INFO,
                           0,        // false
                           out result));

            }
        }