def test_new_localization_workflow(self): # Write a new localization. article_dir = os.path.join(Article.LOCALIZED_ROOT, 'de') os.makedirs(article_dir) with open(os.path.join(article_dir, 'article1.html'), 'w') as f: text = r'%s{%% tag %%}%sBeispiel' % (UNTRANSLATABLE_BEGIN, UNTRANSLATABLE_END) f.write(text) l7r = Localizer(original_root=Article.ROOT, localized_root=Article.LOCALIZED_ROOT) self.assertEqual(1, len(l7r.articles)) # Test writing localizable HTML l7r.GenerateLocalizableFiles() self.assertTrue(os.path.exists(l7r.articles[0].localizable_file_path)) self.assertTrue(os.path.isfile(l7r.articles[0].localizable_file_path)) # Test importataion. l7r.ImportLocalizedFiles() self.assertEqual([], l7r.articles[0].new_localizations) self.assertTrue(os.path.exists(l7r.articles[0].GetOriginalFilePath('en'))) self.assertTrue(os.path.isfile(l7r.articles[0].GetOriginalFilePath('en'))) self.assertTrue(os.path.exists(l7r.articles[0].GetOriginalFilePath('de'))) self.assertTrue(os.path.isfile(l7r.articles[0].GetOriginalFilePath('de'))) # Verify contents with open(l7r.articles[0].GetOriginalFilePath('de'), 'r') as infile: contents = infile.read() self.assertEqual("{% tag %}Beispiel", contents)
help=('Generate Django templates from localized ' 'HTML articles in `./_localized`.')) parser.add_option('--yaml', dest='yaml_infile', default='', help=('Generate localizable template from a specified YAML ' 'file. Output is written to `./[filename].html`')) options = parser.parse_args()[0] if not (options.generate_html or options.import_html): parser.error('You must specify either `--generate` or `--import`.') l7r = Localizer(original_root=Article.ROOT, localized_root=Article.LOCALIZED_ROOT) if options.generate_html and options.yaml_infile: try: l7r.GenerateLocalizableYaml(options.yaml_infile) except YamlProcessorException: parser.error('`%s` couldn\'t be read.' % options.yaml_infile) elif options.generate_html: try: os.mkdir(Article.UNLOCALIZED_ROOT) except OSError: pass l7r.GenerateLocalizableFiles() elif options.import_html: try: os.mkdir(Article.LOCALIZED_ROOT) except OSError: pass l7r.ImportLocalizedFiles()