예제 #1
0
	    public TextLocalizer(
            i18nSettings settings,
            ITranslationRepository translationRepository)
	    {
            _settings = settings;
		    _translationRepository = translationRepository;
	    }
예제 #2
0
        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());
            }
        }
예제 #3
0
        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());
            }
        }
예제 #4
0
 public FileNuggetFinder(i18nSettings settings)
 {
     _settings     = settings;
     _nuggetParser = new NuggetParser(new NuggetTokens(
                                          _settings.NuggetBeginToken,
                                          _settings.NuggetEndToken,
                                          _settings.NuggetDelimiterToken,
                                          _settings.NuggetCommentToken),
                                      NuggetParser.Context.SourceProcessing);
 }
예제 #5
0
		public FileNuggetFinder(i18nSettings settings)
		{
            _settings = settings;
            _nuggetParser = new NuggetParser(new NuggetTokens(
			    _settings.NuggetBeginToken,
			    _settings.NuggetEndToken,
			    _settings.NuggetDelimiterToken,
			    _settings.NuggetCommentToken),
                NuggetParser.Context.SourceProcessing);
		}
예제 #6
0
 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;
 }
예제 #7
0
파일: NuggetLocalizer.cs 프로젝트: uQr/i18n
        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);
        }
예제 #8
0
파일: Program.cs 프로젝트: neo725/i18n
        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.");
        }
예제 #9
0
 public POTranslationRepository(i18nSettings settings)
 {
     _settings = settings;
 }
예제 #10
0
 public POTranslationRepository(i18nSettings settings)
 {
     _settings = settings;
 }
예제 #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);
        }
예제 #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.");
        }
예제 #13
0
        /// <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));

            }
        }