diff --git a/i18n-importer.py b/i18n-importer.py new file mode 100644 index 0000000..955d297 --- /dev/null +++ b/i18n-importer.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 + +def readDiff(): + with open('patch.diff', encoding='utf-8', errors="ignore") as diff_file: + lines = diff_file.readlines() + # sample lines + # -
Initial Startup
+ # +
初始化启动
+ json_output = open("cn.json", "a") + for index, line in enumerate(lines): + if line.startswith("-") and lines[index + 1].startswith("+") and 'data-i18n' in line: + # remove prefix '-' + sanitized_line = line[1:] + print(f"sanitized_line: {sanitized_line}") + # remove prefix '+' + sanitized_next_line = lines[index + 1][1:] + print(f"sanitized_next_line: {sanitized_next_line}") + key_start = sanitized_line.index('data-i18n') + 11 + key_to_end = sanitized_line[key_start:] + key_end = key_to_end.index('"') + i18n_key = sanitized_line[key_start: key_start + key_end] + print(f"i18n_key: {i18n_key}") + + # remove data-i18n-tag + i18n_removed_line = f"{sanitized_line[0: sanitized_line.index('data-i18n') -1]}{sanitized_line[key_start + key_end + 1:]}" + print(i18n_removed_line) + + translated_phrase = '' + # this will output string with ending tag like this: 初始化启动 + for line_index, char in enumerate(sanitized_next_line): + if len(i18n_removed_line) > line_index and char == i18n_removed_line[line_index]: + continue + else: + translated_phrase = f"{translated_phrase}{char}" + print(f"translated_phrase: {translated_phrase}") + # now remove closing tag + if translated_phrase: + for line_index, char in enumerate(i18n_removed_line[::-1]): + if len(sanitized_next_line) > line_index and char == sanitized_next_line[::-1][line_index]: + translated_phrase = translated_phrase[:-1] + else: + break + + print(f"translated_phrase: {translated_phrase}") + # partial json: "legend.title": "Legend", + json_output.write(f'"{i18n_key}": "{translated_phrase}",\n') + + +def main(): + readDiff() + + +if __name__ == "__main__": + main() diff --git a/patch.diff b/patch.diff new file mode 100644 index 0000000..2e9bc1f --- /dev/null +++ b/patch.diff @@ -0,0 +1,12020 @@ +diff --git a/package.nw/GridTracker.html b/package.nw/GridTracker.html +index ee9df69..6b95e40 100644 +--- a/package.nw/GridTracker.html ++++ b/package.nw/GridTracker.html +@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +- GridTracker ++ GridTracker + + + +@@ -46,19 +46,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +- +- +- +- +- +- +- +- + + +- + +- ++ + + +
+@@ -66,24 +57,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +
+
+-

GridTracker

++

GridTracker

+
+
+-

An Amateur Radio Companion

++

Grid网格跟踪助手

+
+-
Initial Startup
++
初始化启动
+ +