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 SetUp() { sourceFileHandler = new FakeResourceFileHandler { { SampleKey, SampleValue } }; destinationFileHandler = new FakeResourceFileHandler(); sut = new ResourceManager(); sut.AddSource(sourceFileHandler); sut.AddDestination(destinationFileHandler); }
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 when_adding_null_destination() { Assert.Throws <ArgumentNullException>(() => _sut.AddDestination(default(ResourceFileHandlerBase))); }