コード例 #1
0
 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")
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: translate.py プロジェクト: judahschvimer/docs-tools
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)
コード例 #5
0
 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(), "")
コード例 #6
0
 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"))
コード例 #7
0
ファイル: test_utils.py プロジェクト: MarkTseng/docs-tools
 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"))
コード例 #8
0
ファイル: test_utils.py プロジェクト: MarkTseng/docs-tools
 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(), "")
コード例 #9
0
ファイル: test_utils.py プロジェクト: MarkTseng/docs-tools
 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")