本文整理汇总了C#中System.Resources.ResXResourceWriter类的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceWriter类的具体用法?C# ResXResourceWriter怎么用?C# ResXResourceWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResXResourceWriter类属于System.Resources命名空间,在下文中一共展示了ResXResourceWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例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 !!";
}
示例3: Shutdown
public virtual void Shutdown() {
if (resources != null) {
using (var resourceWriter = new ResXResourceWriter(resourceFile)) {
resources.ForEach(kvp => resourceWriter.AddResource(kvp.Key, kvp.Value));
}
}
}
示例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();
}
示例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);
}
}
}
}
}
示例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);
}
}
}
}
}
示例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");
}
示例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();
}
示例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();
}
示例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));
}
}
}
示例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();
}
示例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);
}
}
示例13: Update
public static void Update(string resourcePath, string key, string value)
{
if (!File.Exists(resourcePath))
{
return;
}
using (ResXResourceWriter resourceWriter = new ResXResourceWriter(resourcePath))
{
}
}
示例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);
}
}
}
示例15: WriteToFile
public void WriteToFile(string fileName)
{
using (var resxWriter = new ResXResourceWriter (fileName)) {
Resources.ForEach (resxWriter.AddResource);
if (Resources.Count == 0) {
resxWriter.AddMetadata ("", "");
}
}
}