• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Resources.ResXResourceWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Resources.ResXResourceWriter的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceWriter类的具体用法?C# ResXResourceWriter怎么用?C# ResXResourceWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ResXResourceWriter类属于System.Resources命名空间,在下文中一共展示了ResXResourceWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: UpdateResxWithChanges

        public void UpdateResxWithChanges(string newResxPath)
        {
            var newFile = new FileInfo(newResxPath);
            if (newFile.Exists)
                newFile.Delete();

            var addedKeys = _resourcesAdded.Select(pair => pair.Key);
            var removedKeys = _resourcesRemoved.Select(pair => pair.Key);

            using(var reader = new ResXResourceReader(_sourceResxPath))
            using(var writer = new ResXResourceWriter(newResxPath))
            {
                foreach (DictionaryEntry resourceEntry in reader)
                {
                    string currentKey = (string)resourceEntry.Key;
                    if (addedKeys.Contains(currentKey))
                        continue;
                    if (removedKeys.Contains(currentKey))
                        continue;

                    var modifiedResource = _resourcesModified.FirstOrDefault(mod => mod.ResourceName == currentKey);
                    if (modifiedResource != null)
                        writer.AddResource(currentKey, modifiedResource.NewValue);
                    else
                        writer.AddResource(currentKey, resourceEntry.Value);
                }

                _resourcesAdded.ForEach(res => writer.AddResource(res.Key, res.Value));
            }
        }
开发者ID:jboyce,项目名称:SLXToolsContrib,代码行数:30,代码来源:ResxUpdater.cs


示例2: UpdateResourceFile

        public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form)
        {
            form.TextOutput = "Writing " + path + "...";

            Hashtable resourceEntries = new Hashtable();
            bool check = false;

            //Get existing resources
            ResXResourceReader reader = new ResXResourceReader(path);
            if (reader != null)
            {
                IDictionaryEnumerator id = reader.GetEnumerator();
                foreach (DictionaryEntry d in reader)
                {
                    if (d.Value == null)
                        resourceEntries.Add(d.Key.ToString(), "");
                    else
                        resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
                }
                reader.Close();
            }

            //Modify resources here...
            foreach (String key in data.Keys)
            {
                if (!resourceEntries.ContainsKey(key))
                {

                    String value = data[key].ToString();
                    if (value == null) value = "";

                    resourceEntries.Add(key, value);
                }
            }

            //Write the combined resource file
            ResXResourceWriter resourceWriter = new ResXResourceWriter(path);

            foreach (String key in resourceEntries.Keys)
            {
                resourceWriter.AddResource(key, resourceEntries[key]);
            }
            resourceWriter.Generate();
            resourceWriter.Close();

            //Check if entered correctly
            reader = new ResXResourceReader(path);
            if (reader != null)
            {
                foreach (DictionaryEntry d in reader)
                    foreach (String key in resourceEntries.Keys)
                    {
                        if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true;
                    }
                reader.Close();
            }

            if (check) form.TextOutput = path + " written successfully";
            else form.TextOutput = path + " not written !!";
        }
开发者ID:nathanpower,项目名称:resource-translator,代码行数:60,代码来源:Helper.cs


示例3: Shutdown

 public virtual void Shutdown() {
     if (resources != null) {
         using (var resourceWriter = new ResXResourceWriter(resourceFile)) {
             resources.ForEach(kvp => resourceWriter.AddResource(kvp.Key, kvp.Value));
         }
     }
 }
开发者ID:radi4music,项目名称:NakedObjectsFramework,代码行数:7,代码来源:ResourceBasedI18nManager.cs


示例4: Op1_Click

 protected void Op1_Click(object sender, EventArgs e) {
   List<string> files = new List<string>();
   foreach (LocPageGroup grp in groups().Where(g => g != LocPageGroup.newEA)) {
     GenResxContext ctx = new GenResxContext(grp);
     foreach (string s in TradosLib.GenResx(ctx)) files.Add(s);
     LocCfgPageGroupFilter group = LocCfg.Instance().findPageGroup(grp);
     //CSharp resources
     string globalRes = group.GlobalResourcePath;
     if (ctx.toTrans.Count > 0) {
       LowUtils.AdjustFileDir(globalRes);
       using (ResXResourceWriter wr = new ResXResourceWriter(globalRes))
         foreach (TradosLib.resxNameValue nv in ctx.toTrans)
           wr.AddResource(nv.Name, nv.Value);
       files.Add(globalRes);
     } else if (File.Exists(globalRes))
       File.Delete(globalRes);
     //JS resources
     string globalResJS = group.GlobalResourcePathJS;
     if (ctx.toTransJS.Count > 0) {
       LowUtils.AdjustFileDir(globalResJS);
       using (ResXResourceWriter wr = new ResXResourceWriter(globalResJS))
         foreach (TradosLib.resxNameValue nv in ctx.toTransJS)
           wr.AddResource(nv.Name, nv.Value);
       files.Add(globalResJS);
     } else if (File.Exists(globalResJS))
       File.Delete(globalResJS);
   }
   string[] filesArr = (from LocPageGroup grp in groups() from string s in TradosLib.oper1(grp) select s).ToArray();
   CountLab.Text = filesArr.Length.ToString();
   LogRep.DataSource = files; LogRep.DataBind();
 }
开发者ID:PavelPZ,项目名称:REW,代码行数:31,代码来源:Manager.aspx.cs


示例5: Convert

 public static void Convert(string jsonFile, string resxFile)
 {
     resxKey.Clear();
     JObject jsonJObject = JObject.Parse(File.ReadAllText(jsonFile));
     if (jsonJObject != null)
         using (ResXResourceWriter resx = new ResXResourceWriter(resxFile))
         {
             foreach (var property in jsonJObject.Properties())
             {
                 if (property.HasValues)
                 {
                     foreach (var childToken in property.Children())
                     {
                         ProcessJtoken(resx, childToken);
                     }
                 }
                 else
                 {
                     var key = property.Name.ToLower();
                     if (!resxKey.Contains(key))
                     {
                         resxKey.Add(key);
                         resx.AddResource(property.Name, property.Value);
                     }
                 }
             }
         }
 }
开发者ID:RobinHerbots,项目名称:GlobalSauce,代码行数:28,代码来源:JsonResxConverter.cs


示例6: WorkbookToResx

 private void WorkbookToResx(HSSFWorkbook workbook, string sheetName)
 {
     var sheet = NpoiHelper.GetSheet(workbook, sheetName);
     var cultureRow = NpoiHelper.GetRow(sheet, CultureRowNum);
     for (int cultureColumnIndex = 1; cultureColumnIndex < cultureRow.LastCellNum; cultureColumnIndex++)
     {
         string culture = cultureRow.GetCell(cultureColumnIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
         var resourceFile = Path.Combine(_outputPath, sheetName + "." + culture + ".resx");
         if(culture == _rootCulture)
         {
             resourceFile = Path.Combine(_outputPath, sheetName + ".resx");
         }
         using (var resxWriter = new ResXResourceWriter(resourceFile))
         {
             for (var rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
             {
                 var row = NpoiHelper.GetRow(sheet, rowIndex);
                 var valueRow = row.GetCell(cultureColumnIndex);
                 if (valueRow != null)
                 {
                     resxWriter.AddResource(
                         row.GetCell(NameColumnNum, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue,
                         valueRow.StringCellValue);
                 }
             }
         }
     }
 }
开发者ID:luuksommers,项目名称:resourceextractor,代码行数:28,代码来源:ResourceImport.cs


示例7: Test

		public void Test ()
		{
			Thread.CurrentThread.CurrentCulture =
					Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de-DE");

			ResXResourceWriter w = new ResXResourceWriter (fileName);
			w.AddResource ("point", new Point (42, 43));
			w.Generate ();
			w.Close ();

			int count = 0;
			ResXResourceReader r = new ResXResourceReader (fileName);
			IDictionaryEnumerator e = r.GetEnumerator ();
			while (e.MoveNext ()) {
				if ((string) e.Key == "point") {
					Assert.AreEqual (typeof (Point), e.Value.GetType (), "#1");
					Point p = (Point) e.Value;
					Assert.AreEqual (42, p.X, "#2");
					Assert.AreEqual (43, p.Y, "#3");
					count++;
				}
			}
			r.Close ();
			Assert.AreEqual (1, count, "#100");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:CultureTest.cs


示例8: TranslateFile

        private void TranslateFile(string filename, string locale, string newDir)
        {
            string shortName = Path.GetFileName(filename);
            string nameWithoutExt = Path.GetFileNameWithoutExtension(filename);
            string newname = nameWithoutExt + "." + locale + ".resx";
            newname = newDir + "\\" + newname;

            //if file already exists
            bool fileExists = File.Exists(newname);
            Dictionary<string, string> existing = new Dictionary<string, string>();
            if (fileExists)
            {
                Console.WriteLine("File " + newname + " already exists. Existing resources in it will be preserved.");
                //get existing keys list
                ResXResourceReader readerNewFile = new ResXResourceReader(newname);
                foreach (DictionaryEntry d in readerNewFile)
                    existing.Add(d.Key.ToString(), d.Value.ToString());
                readerNewFile.Close();
            }
            else
            {
                Console.WriteLine("Creating file " + newname);
            }

            Console.WriteLine("Translating file " + shortName + " to " + locale + "....");

            Application.DoEvents(); //I know its bad but can't go multithreading, since I have to update UI

            ResXResourceReader reader = new ResXResourceReader(filename);
            ResXResourceWriter writer = new ResXResourceWriter(newname);
            foreach (DictionaryEntry d in reader)
            {
                //leave existing text intact (if its not empty)
                if (fileExists
                    && existing.Keys.Contains(d.Key.ToString())
                    && !string.IsNullOrEmpty(existing[d.Key.ToString()]))
                {
                    writer.AddResource(d.Key.ToString(), existing[d.Key.ToString()]);
                }
                else
                {
                    string originalString = d.Value.ToString();
                    if (!string.IsNullOrEmpty(originalString.Trim()))
                    {
                        string langPair = "hu|" + LanguageNamesList[locale];
                        //string translatedString = GoogleTranslate.TranslateText(originalString, langPair);

                        string translatedString = GoogleTranslate.TranslateGoogle(originalString, "hu", LanguageNamesList[locale]);

                        Console.WriteLine("[" + originalString + " -> " + translatedString + "]");

                        writer.AddResource(d.Key.ToString(), translatedString);
                        //Thread.Sleep(100); //to prevent spam detector at google
                    }
                }
            }
            writer.Close();
            reader.Close();
        }
开发者ID:Gevil,项目名称:Projects,代码行数:59,代码来源:Translator.cs


示例9: generateResourceFile

 public static void generateResourceFile(string sourceDirectory, string targetResrouceFile)
 {
     IEnumerable<string> files = Directory.EnumerateFiles(sourceDirectory,"*.*",SearchOption.AllDirectories);
     ResXResourceWriter rw=new ResXResourceWriter(targetResrouceFile);
     string baseUI = "";
     string baseCOM = "";
     StringBuilder allACE = new StringBuilder();
     StringBuilder allJS = new StringBuilder();
     StringBuilder allCom = new StringBuilder();
     StringBuilder allUI = new StringBuilder();
     StringBuilder allCSS = new StringBuilder();
     StringBuilder jquery = new StringBuilder();
     string jq_timePicker = "";
     foreach(string file in files){
         if(!file.Contains(".svn")){/* don't include subversion files */
             /* only include certain files. Other files don't get included */
             if(file.EndsWith(".png")||file.EndsWith(".jpg")
             ||file.EndsWith(".gif")||file.EndsWith(".ico")) {
                 rw.AddResource(getRscString(file,sourceDirectory),File.ReadAllBytes(file));
             }else if(file.EndsWith(".js")||file.EndsWith(".html")||
             file.EndsWith(".css")||file.EndsWith(".aspx")||file.EndsWith(".sql")
             ||file.EndsWith(".txt")) {
                 string content = File.ReadAllText(file);
                 if(file.EndsWith(".css")){
                     allCSS.Append(content+Environment.NewLine);
                 } else if(file.EndsWith(".js")) {
                     if(file.ToLower().Contains("ui\\ui.js")){
                         baseUI = content+Environment.NewLine+Environment.NewLine;
                     } else if(file.ToLower().Contains("commerce\\commerce.js")) {
                         baseCOM = content+Environment.NewLine+Environment.NewLine;
                     } else if(file.ToLower().Contains("timepicker\\jquery-timepicker.js")) {
                         jq_timePicker = content + Environment.NewLine + Environment.NewLine;
                     } else if(file.ToLower().Contains("jquery\\jquery")) {
                         jquery.Append(content+Environment.NewLine+Environment.NewLine);
                     } else if(file.ToLower().Contains("ui\\")){
                         allUI.Append(content+Environment.NewLine+Environment.NewLine);
                         allJS.Append(content+Environment.NewLine+Environment.NewLine);
                     } else if(file.ToLower().Contains("ace\\")){
                         allACE.Append(content+Environment.NewLine+Environment.NewLine);
                     } else if(file.ToLower().Contains("commerce\\")){
                         allCom.Append(content+Environment.NewLine+Environment.NewLine);
                         allJS.Append(content+Environment.NewLine+Environment.NewLine);
                     }else{
                         allJS.Append(content+Environment.NewLine+Environment.NewLine);
                     }
                 }
                 rw.AddResource(getRscString(file,sourceDirectory),content);
             } else if(file.ToLower() == "thumbs.db") {
                 File.Delete(file); /* evil */
             }
         }
     }
     rw.AddResource("admin__renditionjs", baseUI + baseCOM + allJS.ToString());
     rw.AddResource("admin__acejs", allACE.ToString());
     rw.AddResource("admin__jqueryjs", jquery.ToString());
     rw.AddResource("admin__renditionUIjs", allACE.ToString() + baseUI + allUI.ToString());
     rw.Generate();
     rw.Close();
 }
开发者ID:CorbinDallas,项目名称:Rendition,代码行数:59,代码来源:Program.cs


示例10: Generate

 protected override void Generate()
 {
     using (var resx = new ResXResourceWriter (Writer)) {
         foreach (var resource_string in GetAllResourceStrings ()) {
             resx.AddResource (new ResXDataNode (resource_string.Id, resource_string.Translated));
         }
     }
 }
开发者ID:sam-lippert,项目名称:vernacular,代码行数:8,代码来源:ResxGenerator.cs


示例11: CreateResourceFile

        public static void CreateResourceFile(String path)
        {
            var pathString = Path.GetDirectoryName(path);
            if (!Directory.Exists(pathString)) System.IO.Directory.CreateDirectory(pathString);

            ResXResourceWriter resourceWriter = new ResXResourceWriter(path);
            resourceWriter.Generate();
            resourceWriter.Close();
        }
开发者ID:fujinguyen,项目名称:NBrightBuy,代码行数:9,代码来源:NBrightBuyUtils.cs


示例12: AddResource

 public static void AddResource(string path, string key, string value)
 {
     var dict = ReadAllResources(path);
     using (var writer = new ResXResourceWriter(path))
     {
         dict[key] = value;
         foreach (var item in dict)
             writer.AddResource(item.Key, item.Value);
     }
 }
开发者ID:Yankovsky,项目名称:SeekAndLocalize,代码行数:10,代码来源:ResXManager.cs


示例13: Update

 public static void Update(string resourcePath, string key, string value)
 {
     if (!File.Exists(resourcePath))
     {
         return;
     }
     using (ResXResourceWriter resourceWriter = new ResXResourceWriter(resourcePath))
     {
     }
 }
开发者ID:jiangguang5201314,项目名称:DotNetFramework,代码行数:10,代码来源:ResourceHelper.cs


示例14: Create

		public override void Create(DecompileContext ctx) {
			var list = ReadResourceEntries(ctx);

			using (var writer = new ResXResourceWriter(Filename, TypeNameConverter)) {
				foreach (var t in list) {
					ctx.CancellationToken.ThrowIfCancellationRequested();
					writer.AddResource(t);
				}
			}
		}
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:10,代码来源:ResXProjectFile.cs


示例15: WriteToFile

        public void WriteToFile(string fileName)
        {
            using (var resxWriter = new ResXResourceWriter (fileName)) {

                Resources.ForEach (resxWriter.AddResource);

                if (Resources.Count == 0) {
                    resxWriter.AddMetadata ("", "");
                }
            }
        }
开发者ID:CalebMorris,项目名称:Xamarin-ResxEditor,代码行数:11,代码来源:ResourceHandler.cs


示例16: ExportFromDatabase

        public void ExportFromDatabase(string exportPath)
        {
            var allRecords = new DbFunctions(_connectionString).GetAllResources();

            foreach (ResourceRecord record in allRecords)
            {
                using (ResXResourceWriter writer = new ResXResourceWriter(GetExportPath(exportPath, record)))
                {
                    writer.AddResource(record.Key, record.Value);
                }
            }
        }
开发者ID:reynn,项目名称:DbLocalizer,代码行数:12,代码来源:DbImporterExporter.cs


示例17: BuildResX

 public void BuildResX(string outputPath)
 {
     using (ResXResourceWriter w2 = new ResXResourceWriter(outputPath))
     {
         foreach (Item item in _items)
         {
             ResXDataNode node = new ResXDataNode(item.Name, item.Value);
             node.Comment = item.Comment;
             w2.AddResource(item.Name, node);
         }
     }
 }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:12,代码来源:TestResourceBuilder.cs


示例18: GenerateOutputFile

        public override string GenerateOutputFile(LocalizedEntityBlock[] blocks)
        {
            var ms = new MemoryStream();

            using (var resxw = new ResXResourceWriter(ms))
                foreach (var block in blocks)
                    foreach (var r in block.LocalizationGridRows)
                        resxw.AddResource(r.LocalizableProperty.EntityName, r.Value);

            var array = ms.ToArray();
            return Encoding.UTF8.GetString(array, 3, array.Length - 3);
        }
开发者ID:codaxy,项目名称:dextop-localizer,代码行数:12,代码来源:ResxComposer.cs


示例19: writeModifiedResX

 public void writeModifiedResX(string modifiedResXFile)
 {
     using (var resourceWriter = new ResXResourceWriter(modifiedResXFile))
     {
         foreach (DictionaryEntry resourceEntry in _resourceEntries)
         {
             var dnode = (ResXDataNode)resourceEntry.Value;
             resourceWriter.AddResource(dnode);
         }
         resourceWriter.Generate();
     }
 }
开发者ID:ClementChesnin,项目名称:ResXModifier,代码行数:12,代码来源:Modifier.cs


示例20: Generate

 protected override void Generate()
 {
     using (var resx = new ResXResourceWriter (Writer)) {
         foreach (var localized_string in Strings) {
             foreach (var resource_string in GetResourceStrings (localized_string)) {
                 if (!HasResourceStringBeenGenerated (resource_string)) {
                     MarkResourceStringAsGenerated (resource_string);
                     resx.AddResource (new ResXDataNode (resource_string.Id, resource_string.Translated));
                 }
             }
         }
     }
 }
开发者ID:jorik041,项目名称:vernacular,代码行数:13,代码来源:ResxGenerator.cs



注:本文中的System.Resources.ResXResourceWriter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Resources.ResourceManager类代码示例发布时间:2022-05-26
下一篇:
C# Resources.ResXResourceReader类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap