public void BuildMasterResx()
        {
            var iOSResourceFileHandler     = new iOSResourceFileHandler(GetFullPath(iOSRelativePath), "");
            var androidResourceFileHandler = new AndroidResourceFileHandler(GetFullPath(AndroidRelativePath), "");

            var resourceFileHandlerDiff = CompareResourceFileHandlers(iOSResourceFileHandler, androidResourceFileHandler);

            if (!resourceFileHandlerDiff.Diff.Any())
            {
                using (var rw = new ResXResourceWriter(GetFullPath(MasterResxRelativePath)))
                {
                    foreach (var key in resourceFileHandlerDiff.Keys.Except(resourceFileHandlerDiff.GetProblematicKeys()))
                    {
                        rw.AddResource(key, iOSResourceFileHandler[key]);
                    }

                    foreach (var androidMissgingKey in resourceFileHandlerDiff.RightResourceFileHandlerMissgingKeys)
                    {
                        rw.AddResource(androidMissgingKey, iOSResourceFileHandler[androidMissgingKey]);
                    }

                    foreach (var iOSMissgingKey in resourceFileHandlerDiff.LeftResourceFileHandlerMissgingKeys)
                    {
                        rw.AddResource(iOSMissgingKey, androidResourceFileHandler[iOSMissgingKey]);
                    }
                }
            }

            var report = BuildCompareReportCsv(resourceFileHandlerDiff);
        }
Exemplo n.º 2
0
        private static void ConvertResourceFile(string commonFile, string masterFile, string target, string destination, bool backup)
        {
            var resourceManager = new ResourceManager();
            ResourceFileHandlerBase handler;

            if (!string.IsNullOrWhiteSpace(commonFile))
            {
                resourceManager.AddSource(new ResxResourceFileHandler(commonFile));
            }

            resourceManager.AddSource(new ResxResourceFileHandler(masterFile));

            switch (target)
            {
            case "android":
                resourceManager.AddDestination(handler = new AndroidResourceFileHandler(destination));
                break;

            case "ios":
                resourceManager.AddDestination(handler = new iOSResourceFileHandler(destination));
                break;

            default:
                throw new InvalidOperationException("Invalid program arguments");
            }

            resourceManager.Update();
            handler.Save(backup);
        }
        public void UpdateAndroidClientResourceFiles()
        {
            var resxResourceFileHandler = new ResxResourceFileHandler(GetFullPath(MasterResxRelativePath));

            var androidResourceFileHandler = new AndroidResourceFileHandler(GetFullPath(AndroidRelativePath), resxResourceFileHandler, "");

            androidResourceFileHandler.Save();
        }
Exemplo n.º 4
0
        public void AddValue_Save_FileUpdated_Escaped()
        {
            var sut = new AndroidResourceFileHandler(AndroidFileName, false);

            sut["anotherkey"] = "< > & ¢ £ ¥ € © ®";
            sut.Save(false);

            sut = new AndroidResourceFileHandler(AndroidFileName, false);
            Assert.That(sut.Keys.Count, Is.EqualTo(4));
        }
Exemplo n.º 5
0
        public void AddValue_WithClearOption_Save_FileUpdated()
        {
            var sut = new AndroidResourceFileHandler(AndroidFileName, true);

            sut["anotherkey"] = "test";
            sut.Save(false);

            sut = new AndroidResourceFileHandler(AndroidFileName, false);
            Assert.That(sut.Keys.Count, Is.EqualTo(1));
        }
        public void AndroidResourceFileHandler()
        {
            var fullPath = GetFullPath(AndroidRelativePath);

            var androidResourceFileHandler = new AndroidResourceFileHandler(fullPath, "");

            Assert.That(androidResourceFileHandler.Count, Is.GreaterThan(0));

            string backupFilePath = androidResourceFileHandler.Save();
            var    backupAndroidResourceFileHandler = new AndroidResourceFileHandler(backupFilePath, "");

            Assert.That(backupAndroidResourceFileHandler.Count, Is.EqualTo(androidResourceFileHandler.Count));

            androidResourceFileHandler.Add("maxime", "allo");
            androidResourceFileHandler.Save(false);
            androidResourceFileHandler = new AndroidResourceFileHandler(fullPath, "");
            Assert.That(androidResourceFileHandler.Count, Is.EqualTo(backupAndroidResourceFileHandler.Count + 1));

            File.Copy(backupFilePath, fullPath, true);
            File.Delete(backupFilePath);
        }
        public void CompareMasterResxWithClientResourceFiles()
        {
            var resxResourceFileHandler    = new ResxResourceFileHandler(GetFullPath(MasterResxRelativePath));
            var iOSResourceFileHandler     = new iOSResourceFileHandler(GetFullPath(iOSRelativePath), "");
            var androidResourceFileHandler = new AndroidResourceFileHandler(GetFullPath(AndroidRelativePath), "");

            var androidResourceFileHandlerDiff = CompareResourceFileHandlers(resxResourceFileHandler, androidResourceFileHandler);
            var iOSResourceFileHandlerDiff     = CompareResourceFileHandlers(resxResourceFileHandler, iOSResourceFileHandler);

            Assert.That(iOSResourceFileHandlerDiff.GetProblematicKeys().Count(), Is.EqualTo(0));
            Assert.That(androidResourceFileHandlerDiff.GetProblematicKeys().Count(), Is.EqualTo(0));

            //if (iOSResourceFileHandlerDiff.GetProblematicKeys().Any())
            //{
            //    var report = BuildCompareReportCsv(iOSResourceFileHandlerDiff);
            //}

            //if (androidResourceFileHandlerDiff.GetProblematicKeys().Any())
            //{
            //    var report = BuildCompareReportCsv(androidResourceFileHandlerDiff);
            //}
        }
Exemplo n.º 8
0
        public void Ctor_WithFile_CorrectlyInitialized()
        {
            var sut = new AndroidResourceFileHandler(AndroidFileName, false);

            Assert.That(sut.Keys.Count, Is.EqualTo(3));
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            // string.Empty is english, since english resource file name doesn't have language suffix
            var supportedLanguages = new List <string> {
                string.Empty
            };

            supportedLanguages.AddRange(
                Enum.GetNames(typeof(SupportedLanguages)).Except(new[] { SupportedLanguages.en.ToString() }));

            string target      = string.Empty;
            string source      = string.Empty;
            string settings    = string.Empty;
            string destination = string.Empty;
            bool   backup      = false;

            var p = new OptionSet
            {
                { "t|target=", "Target application: ios or android", t => target = t.ToLowerInvariant() },
                { "m|master=", "Master .resx file path", m => source = m },
                { "d|destination=", "Destination file path", d => destination = d },
                { "s|settings:", "JSON settings file path", s => settings = s },
                { "b|backup", "Backup file", b => backup = b != null },
            };

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                ShowHelpAndExit(e.Message, p);
            }

            try
            {
                foreach (var lang in supportedLanguages)
                {
                    var resourceManager = new ResourceManager();
                    var handler         = default(ResourceFileHandlerBase);

                    resourceManager.AddSource(new ResxResourceFileHandler(AddLanguageToPathResx(source, lang)));

                    if (settings != null && File.Exists(settings))
                    {
                        dynamic appSettings = JsonConvert.DeserializeObject(File.ReadAllText(settings));
                        // Custom resource file should be in the same folder as Master.resx
                        // Name of the custom resource file is equal to settings ApplicationName
                        var customResourcesFilePath = AddLanguageToPathResx(Path.Combine(Path.GetDirectoryName(source), (string)appSettings["TaxiHail.ApplicationName"] + ".resx"), lang);

                        if (File.Exists(customResourcesFilePath))
                        {
                            Console.WriteLine("Adding Company Specific resource file {0}.", customResourcesFilePath);

                            resourceManager.AddSource(new ResxResourceFileHandler(customResourcesFilePath));
                        }
                    }

                    switch (target)
                    {
                    case "android":
                        AndroidLanguageFileManager.CreateAndroidClientResourceFileIfNecessary(lang);
                        resourceManager.AddDestination(handler = new AndroidResourceFileHandler(destination, lang));
                        break;

                    case "ios":
                        iOSLanguageFileManager.CreateResourceFileIfNecessary(lang);
                        resourceManager.AddDestination(handler = new iOSResourceFileHandler(destination, lang));
                        break;

                    case "callbox":
                        AndroidLanguageFileManager.CreateCallboxClientResourceFileIfNecessary(lang);
                        resourceManager.AddDestination(handler = new AndroidResourceFileHandler(destination, lang));
                        break;

                    default:
                        throw new InvalidOperationException("Invalid program arguments");
                    }

                    resourceManager.Update();
                    handler.Save(backup);

                    var l = string.IsNullOrWhiteSpace(lang) ? "en" : lang;
                    Console.WriteLine("Localization for :  " + l + " was successful");
                }

                Console.WriteLine("Localization tool ran successfully.");
            }
            catch (Exception exception)
            {
                Console.Write("error: ");
                Console.WriteLine(exception.ToString());
                throw;
            }
        }