diff --git a/__init__.py b/__init__.py index b0bf46e..ce1b86c 100755 --- a/__init__.py +++ b/__init__.py @@ -5,8 +5,8 @@ "name": "Subsimport", "description": "Import subtitles into blender", "author": "doakey3", - "version": (1, 3, 1), - "blender": (2, 80, 0), + "version": (1, 3, 2), + "blender": (3, 2, 0), "wiki_url": "https://github.com/doakey3/subsimport", "tracker_url": "https://github.com/doakey3/subsimport/issues", "category": "Sequencer" @@ -135,6 +135,8 @@ def init_prop(): # Better off using en-us until I have a better dictionary #('en-gb', 'English-Great Britain', ''), ('en-us', 'English-U.S.', ''), + ('zh-tw', '繁體中文', ''), + ('zh-cn', '簡體中文', ''), ('eo', 'Esperanto', ''), ('et', 'Estonian', ''), ('fi', 'Finnish', ''), diff --git a/operators/hyphenator/dictionaries/zh-cn.txt b/operators/hyphenator/dictionaries/zh-cn.txt new file mode 100644 index 0000000..e69de29 diff --git a/operators/hyphenator/dictionaries/zh-tw.txt b/operators/hyphenator/dictionaries/zh-tw.txt new file mode 100644 index 0000000..e69de29 diff --git a/operators/hyphenator/get_dictionary.py b/operators/hyphenator/get_dictionary.py index 91efd56..cf705b9 100755 --- a/operators/hyphenator/get_dictionary.py +++ b/operators/hyphenator/get_dictionary.py @@ -10,7 +10,7 @@ def get_dictionary(dic_path=None, lang='en-us'): dictionary = {} try: - f = open(dic_path, 'r') + f = open(dic_path, 'r', encoding="utf-8") lines = f.readlines() f.close() diff --git a/operators/hyphenator/patterns/zh-cn.txt b/operators/hyphenator/patterns/zh-cn.txt new file mode 100644 index 0000000..e69de29 diff --git a/operators/hyphenator/patterns/zh-tw.txt b/operators/hyphenator/patterns/zh-tw.txt new file mode 100644 index 0000000..e69de29 diff --git a/operators/pylrc/tools/find_even_split.py b/operators/pylrc/tools/find_even_split.py index 91911c0..0823e2d 100755 --- a/operators/pylrc/tools/find_even_split.py +++ b/operators/pylrc/tools/find_even_split.py @@ -2,6 +2,7 @@ def find_even_split(line): """ Given a string, splits it into two (almost) evenly spaced lines """ + """word_list = line.split(' ')""" word_list = line.split(' ') differences = [] for i in range(len(word_list)): diff --git a/operators/pysrt/srtfile.py b/operators/pysrt/srtfile.py index d21d5c1..89a4dfc 100755 --- a/operators/pysrt/srtfile.py +++ b/operators/pysrt/srtfile.py @@ -321,7 +321,7 @@ def _get_first_line(cls, string_iterable): @classmethod def _detect_encoding(cls, path): - file_descriptor = open(path, 'rb') + file_descriptor = open(path, 'rb', 'utf-8') first_chars = file_descriptor.read(BIGGER_BOM) file_descriptor.close() diff --git a/operators/save_syllables.py b/operators/save_syllables.py index b4b689e..109d539 100755 --- a/operators/save_syllables.py +++ b/operators/save_syllables.py @@ -23,7 +23,7 @@ def execute(self, context): lang=scene.syllabification_language) path = bpy.path.abspath(scene.syllable_dictionary_path) - f = open(path, 'r') + f = open(path, 'r',encoding='utf-8') words = f.readlines() f.close() @@ -39,7 +39,7 @@ def execute(self, context): module_path, 'hyphenator', 'dictionaries', scene.syllabification_language + '.txt') - f = open(dic_path, 'w') + f = open(dic_path, 'w', encoding='utf-8') f.write('\n'.join(values)) f.close() diff --git a/operators/split_words.py b/operators/split_words.py index 7d289ef..3747feb 100755 --- a/operators/split_words.py +++ b/operators/split_words.py @@ -23,7 +23,10 @@ def break_strip(scene, strip): else: dictionary = {} - words = strip.text.replace('\n', ' ').split(' ') + if scene.syllabification_language == 'zh-tw' or scene.syllabification_language == 'zh-cn': + words = list(strip.text.replace('\n', ' ')) + else: + words = strip.text.replace('\n', ' ').split(' ') i = 0 while i < len(words): if words[i].rstrip() == '': @@ -72,9 +75,13 @@ def form_items(scene, strip, pieces): text = strip.text lines = text.split('\n') empty_text = '' + empty_chr = ' ' + if scene.syllabification_language == 'zh-tw' or scene.syllabification_language == 'zh-cn': + empty_chr = ' ' + for i in range(len(lines)): for char in range(len(lines[i])): - empty_text += ' ' + empty_text += empty_chr empty_text += '\n' new_pieces = [] diff --git a/operators/syllabify.py b/operators/syllabify.py index 80adec7..3301c17 100755 --- a/operators/syllabify.py +++ b/operators/syllabify.py @@ -15,9 +15,14 @@ def collect_words(scene): words = [] text_strips = get_text_strips(scene) - for strip in text_strips: - strip_words = strip.text.lower().replace('--', ' ').replace('\n', ' ').split(' ') - words.extend(strip_words) + if scene.syllabification_language == 'zh-tw' or scene.syllabification_language == 'zh-cn': + for strip in text_strips: + strip_words = list(strip.text.lower().replace('--', ' ').replace('\n', ' ')) + words.extend(strip_words) + else: + for strip in text_strips: + strip_words = strip.text.lower().replace('--', ' ').replace('\n', ' ').split(' ') + words.extend(strip_words) i = 0 while i < len(words): @@ -105,7 +110,7 @@ def execute(self, context): words[i] = ' '.join(words[i]) words = set(words) words = sorted(list(words)) - f = open(self.filepath, 'w') + f = open(self.filepath, 'w',encoding='utf-8') f.write('\n'.join(words)) f.close() diff --git a/operators/tools/subtitles_to_sequencer.py b/operators/tools/subtitles_to_sequencer.py index e822106..92ac28d 100755 --- a/operators/tools/subtitles_to_sequencer.py +++ b/operators/tools/subtitles_to_sequencer.py @@ -37,8 +37,8 @@ def subtitles_to_sequencer(context, subs): name=sub_name, type='TEXT', channel=open_channel, - frame_start=strip_start, - frame_end=strip_end + frame_start=int(strip_start), + frame_end=int(strip_end) ) text_strip.font = get_font(scene.subtitle_font) diff --git a/tools/automatic_text_alignment.py b/tools/automatic_text_alignment.py index 643d098..1ad77d6 100755 --- a/tools/automatic_text_alignment.py +++ b/tools/automatic_text_alignment.py @@ -22,6 +22,7 @@ def write_word_level(text, txt_path): text = text.split('\n') for line in text: split = line.split(' ') + """split = list(line)""" for word in split: words.append(word)