Exemplo n.º 1
0
 private static string GetJsOutputFileName(Options options, ResourceFile resourceFile)
 {
     var jsFileName = string.IsNullOrEmpty(options.JavaScriptFileName)
                     ? resourceFile.ResourceFilePathName.Substring(resourceFile.ResourceFilePathName.LastIndexOf("\\") + 1)
                     : options.JavaScriptFileName;
       //var jsFileNameWithoutPath = jsFileName + ".js";
       // CT: Made the file replace the resx with json
       var jsFileNameWithoutPath = jsFileName.Replace("resx","json");
     var outputJsFilePathName = Path.Combine(options.OutputFolder, jsFileNameWithoutPath);
     return outputJsFilePathName;
 }
Exemplo n.º 2
0
        public void Convert(Options options)
        {
            try
            {
                var resourceFiles = this.GetResourceFiles(options);

                var baseResourceFile = this.GetBaseResourceFile(resourceFiles);

                this.GenerateJsResourceFiles(options, resourceFiles, baseResourceFile);
            }
            catch (Exception ex)
            {
                logger.Error("Errors occurred during conversion", ex);
            }
        }
Exemplo n.º 3
0
 private void CheckDuplicateValues(Options options, Dictionary<string, string> valueDict, KeyValuePair<string, string> currentKeyValue, string outputLocation)
 {
     if (options.CheckDuplicatesInResx)
     {
         if (valueDict.ContainsKey(currentKeyValue.Value))
         {
             var message = string.Format(ErrorMessages.DuplicateValueInResX, currentKeyValue.Key, valueDict[currentKeyValue.Value],
                                     currentKeyValue.Value, outputLocation);
             this.appState.ErrorMesssages.Add(message);
         }
         else
         {
             valueDict.Add(currentKeyValue.Value, currentKeyValue.Key);
         }
     }
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure();

            var options = new Options();
            var parseSuccess = CommandLine.Parser.Default.ParseArguments(args, options);
            if (parseSuccess)
            {
                var appState = new ApplicationState();
                var copier = new DeepCopier();
                var resxReader = new ResxReader(appState, null);
                var jsonHelper = new JsonHelper();
                var converter = new ResxToJsConverter(copier, resxReader, jsonHelper, appState, null);
                converter.Convert(options);
                DisplayErrorMessages(appState);
            }
            else
            {
                Console.WriteLine("An error occurred while parsing the options.");
            }

            ////Console.ReadLine();
        }
Exemplo n.º 5
0
        private void GenerateJsResourceFiles(Options options, IEnumerable<ResourceFile> resourceFiles, ResourceFile baseResourceFile)
        {
            ////var baseResourceDict = resxReader.GetKeyValuePairsFromResxFile(baseResourceFile);

            foreach (var resourceFile in resourceFiles)
            {
                var outputJsFilePathName = GetJsOutputFileName(options, resourceFile);
            // CT: Treat all files the same

            //if (resourceFile.IsBaseResourceType)
            //{
            //  this.WriteOutput(options, baseResourceDict, outputJsFilePathName);
            //}
            //else
            //{
            //  var cultureSpecificResourceDict = this.GetCultureSpecificResourceDictFromBaseDict(baseResourceDict, resourceFile);

            //  this.WriteOutput(options, cultureSpecificResourceDict, outputJsFilePathName);
            //}
              Dictionary<string, string> resourceDict = resxReader.GetKeyValuePairsFromResxFile(resourceFile);
              if (resourceDict.Count == 0)
              {
                resourceDict.Add("__comment", "Empty");
              }
              this.WriteOutput(options, resourceDict, outputJsFilePathName);
              }
        }
Exemplo n.º 6
0
        private void WriteOutput(Options options, Dictionary<string, string> resourceDict, string outputLocation)
        {
            var valueDict = new Dictionary<string, string>();
              // CT: Made the format strict JSON
            ////var resourceObjectName = string.IsNullOrEmpty(options.JsResourceObjectName) ? "Resources" : options.JsResourceObjectName.Trim();
            ////var sb = new StringBuilder("/* This is an auto-generated file. Do not hand-edit. Use the Resx2Js tool to generate it from Resx files */");
              var sb = new StringBuilder();
              ////sb.AppendLine();
            ////sb.Append(resourceObjectName);
              ////sb.Append(" = {");
              sb.Append("{");

            foreach (var entry in resourceDict)
            {
                this.CheckDuplicateValues(options, valueDict, entry, outputLocation);

                var escapedValue = EscapeJsonValue(entry.Value.Trim());

                sb.AppendFormat("\"{0}\":\"{1}\",", entry.Key, escapedValue);
            }

            if (sb.Length > 0)
            {
                sb = sb.Remove(sb.Length - 1, 1);
            }
              ////sb.Append("};");
              sb.Append("}");

            var outputJson = sb.ToString();
            if (options.PrettyPrint)
            {
                outputJson = jsonHelper.PrettyPrintJson(outputJson);
            }

            File.WriteAllText(outputLocation, outputJson);
        }
Exemplo n.º 7
0
        private List<ResourceFile> GetResourceFiles(Options options)
        {
            var resourceFiles = this.resxReader.GetResourceFiles(options.InputFolder);

            if (resourceFiles.Count == 0)
            {
                this.appState.AddError(ErrorMessages.ResourceFilesNotFound);
                throw new ApplicationException(ErrorMessages.ResourceFilesNotFound);
            }
            return resourceFiles;
        }