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); }
public void UpdateIosClientResourceFiles() { var resxResourceFileHandler = new ResxResourceFileHandler(GetFullPath(MasterResxRelativePath)); var iOSResourceFileHandler = new iOSResourceFileHandler(GetFullPath(iOSRelativePath), resxResourceFileHandler, ""); iOSResourceFileHandler.Save(); }
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 AddValue_Save_FileUpdated_Escaped() { var sut = new iOSResourceFileHandler(iOSFileName, false); sut["anotherkey"] = "< > & ¢ £ ¥ € © ®"; sut.Save(false); sut = new iOSResourceFileHandler(iOSFileName, false); Assert.That(sut.Keys.Count, Is.EqualTo(3)); }
public void AddValue_WithClearOption_Save_FileUpdated() { var sut = new iOSResourceFileHandler(iOSFileName, true); sut["anotherkey"] = "test"; sut.Save(false); sut = new iOSResourceFileHandler(iOSFileName, false); Assert.That(sut.Keys.Count, Is.EqualTo(1)); }
public void IosResourceFileHandler() { var fullPath = GetFullPath(iOSRelativePath); var iOSResourceFileHandler = new iOSResourceFileHandler(fullPath, ""); Assert.That(iOSResourceFileHandler.Count, Is.GreaterThan(0)); string backupFilePath = iOSResourceFileHandler.Save(); var backupIosResourceFileHandler = new iOSResourceFileHandler(backupFilePath, ""); Assert.That(backupIosResourceFileHandler.Count, Is.EqualTo(iOSResourceFileHandler.Count)); iOSResourceFileHandler.Add("maxime", "allo"); iOSResourceFileHandler.Save(false); iOSResourceFileHandler = new iOSResourceFileHandler(fullPath, ""); Assert.That(iOSResourceFileHandler.Count, Is.EqualTo(backupIosResourceFileHandler.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); //} }
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; } }
public void Ctor_WithFile_CorrectlyInitialized() { var sut = new iOSResourceFileHandler(iOSFileName, false); Assert.That(sut.Keys.Count, Is.EqualTo(2)); }