jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Collections;
using System.IO;
 
namespace HH.WMS.Utils
{
    public class ZResxToJs
    {
        public static void RenderJsResource(string RsPath,string JsPath)
        {
            //var RsPath = "~//App_GlobalResources//resource1.resx";
            //var JsPath = "~//common//js//abc.js";
            RsPath = HttpContext.Current.Server.MapPath(RsPath);
            JsPath = HttpContext.Current.Server.MapPath(JsPath);
            var script = new StringBuilder();
            using (var resourceReader = new System.Resources.ResXResourceReader(RsPath))
            {
                foreach (DictionaryEntry entry in resourceReader)
                {
                    var key = ZConvert.ToString(entry.Key).Replace('.', '_');
                    var value = ZConvert.ToString(entry.Value);
                    script.Append(",");
                    script.Append(key);
                    script.Append(":");
                    script.Append('"' + value + '"');
                    script.Append("\r\n");
                }
            }
 
            try
            {
                var str = "var lang = {\r\n " + script.ToString().Trim(',') + "}";
                ZFiles.DeleteFiles(JsPath);
                ZFiles.WriteStrToTxtFile(JsPath, str, FileMode.CreateNew);
            }
            catch
            {
 
            }
        }
    }
}