def test_simple(self): flip_text_direction( os.path.join(TEST_PATH, "test_files", "flip_text.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt")) with open(os.path.join(TEST_PATH, "temp_files", "flipped.txt")) as f: self.assertEqual(f.read().strip(), "haduj ,olleh\nuoy era woh ,ih\n\na\ncb\ndoog")
def translate_po_files(po_path, tconf, protected_file=None): ''' This function translates a directory of po files in three steps: First it extracts the untranslated entries from every po file into one big file. Then it translates that file. Lastly it fills in all of the po files in the same order the entries were extracted, removing the text from any translated entries. :param string po_path: the path to the top level directory of the po_files :param config tconf: translation config object :param string protected_file: path to file with regexes to protect ''' with TempDir() as temp_dir: po_file_list = get_file_list(po_path, ["po", "pot"]) temp_file = extract_all_untranslated_po_entries(po_file_list, temp_dir) trans_file = temp_file + '.translated' translate_file(temp_file, trans_file, tconf, protected_file, temp_dir) # flips the file if the language is right to left if tconf.settings.foreign in ['he', 'ar']: flipped_file = trans_file + '.flip' flip_text_direction(trans_file, flipped_file) trans_file = flipped_file write_po_files(po_file_list, trans_file)
def flip_text(args): if args.t_output_file is None: args.t_output_file = args.t_input_file + '.flip' flip_text_direction(args.t_input_file, args.t_output_file)
def test_empty(self): flip_text_direction( os.path.join(TEST_PATH, "test_files", "empty.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt")) with open(os.path.join(TEST_PATH, "temp_files", "flipped.txt")) as f: self.assertEqual(f.read().strip(), "")
def test_bad_file(self): with self.assertRaises(Exception): flip_text_direction( os.path.join(TEST_PATH, "test_files", "empdfadfadty.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt"))
def test_bad_file(self): with self.assertRaises(Exception): flip_text_direction(os.path.join(TEST_PATH, "test_files", "empdfadfadty.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt"))
def test_empty(self): flip_text_direction(os.path.join(TEST_PATH, "test_files", "empty.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt")) with open(os.path.join(TEST_PATH, "temp_files", "flipped.txt")) as f: self.assertEqual(f.read().strip(), "")
def test_simple(self): flip_text_direction(os.path.join(TEST_PATH, "test_files", "flip_text.txt"), os.path.join(TEST_PATH, "temp_files", "flipped.txt")) with open(os.path.join(TEST_PATH, "temp_files", "flipped.txt")) as f: self.assertEqual(f.read().strip(), "haduj ,olleh\nuoy era woh ,ih\n\na\ncb\ndoog")