Skip to content

Commit

Permalink
Split off minor sections of main package
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarize committed Apr 21, 2023
1 parent 1d9a6b4 commit db1fb81
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 189 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = poboy
version = 0.0.1
version = 0.1.0
description = POboy
long_description_content_type=text/markdown
long_description = file: README.md
Expand Down Expand Up @@ -36,4 +36,4 @@ universal=1
[options.entry_points]
console_scripts = poboy = src.poboy:run
console_scripts = babelmsg = src.babelmsg.frontend:main
meerk40t.plugins = Poboy = src.poboy:plugin
meerk40t.plugins = Poboy = src.plugin:plugin
23 changes: 23 additions & 0 deletions src/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from wx.lib.embeddedimage import PyEmbeddedImage

icons8_translation_50 = PyEmbeddedImage(
b"iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABmJLR0QA/wD/AP+gvaeTAAAD"
b"oklEQVRogd2ay0sVURzHP+bNWrgpuPdKLYKeG20jImQRBZdoERTSwmiT1CK0FkGt7WlRQi2K"
b"3Bb9ARIu06VEi8RKe1EE3gjKIGtRRt4W8xtnmjsz5zEzV/MLB+ae8zvf7/nOnDmvubDM0ABc"
b"Az4ClRqlMtAv2jpoAnpUQVdraCCYrmiamJL43rjAsgTt0CBNCx14TyYOfhNT8jsS7t2pNVS6"
b"ReC5xLwE1iUlzApxusYmVIRZIkq3AEyi2Z0AVqTbrsVHkieSVd0CXtd6RQ26VpZ1jc3EEaY1"
b"X9gYMTazlI2AwYSY5qi1EvgufEVFrImu1hJFl3A70IrT2Ci4M/a0Bl/qw74u4TOJa42JGZKY"
b"GynqakOX8LbE3Y8o3yflP4H1KepqQ5dwK/BLYk8EyjYCX6SsL2VdbZgQnpLYeeA8kAM2AG8k"
b"fxSo1+Ap+nRtUuh+xvTOnBUjFeAJ8EGunwJrNTnywERCMxUC+xmbR7wf+Oar+wc4DNQp6hWA"
b"ks+MaoiOQuh+xtRIHnjgq/fbdz0JnCF8QdoIvMB5z0oh5aaoareukRxwEvgs8T+A0zjd6Rxe"
b"F3sdw9GHY6Zg2uoQGBupB7rw9ggVYATYFIjLAQeAo4H8PDCA92I22rQ6BMZG2n0xb4FOQ8FH"
b"UnfAsJ4KVl3rHnCM+OVJFFpwzOQD+TlgjaScBa/1O2KCAk7jW2Jien3aygVhCGpi5DreuxSF"
b"cbz5aNxCI1Mj7oucwzETNU+0ieYQ8F6u2wy1MjPiztY6K99B0ewELsn1XUO9zIyUcCa7CeKH"
b"2EZgFvgKrAK2if6sol4QVe12j0w7DEj8KOKNSCWqR6cgukVv0Jf3WPK6DXSrjPT7Mm3ThIYB"
b"F2NSZ5cvzx3BxpIYaRAzZZKZ0VkANkvsO/5dYOaBOSlrtjWSFCaEtyT2QkjZQym7mYFuqoSr"
b"gRmJbceb1d10XMpmJDYtXW3oEh5Bv5t2meiqNkG6cE2o+EaAPTjb4tmImCacg4tRYG9S3R40"
b"jvIDhKonshlnOTJH/Oi2W7jmpY61rjsMan2X0CEUuEP8kCKuDm/J0p9E1+Y4X2Ukh/fFWGcv"
b"c1FiPxG/bVDeQFMzKsJDUu4uSVTYgrcqPphAFzAzoyIclvI7KlEf3Nl/OIHuAvzH+ZNEHxik"
b"Pp5rYkF32X1DDIPJ5+FFfyJRMP3GvSSNGP1lQpB0P2ODnaIZ+UHJZkJMYz9jmy7HNcx0iZLW"
b"fsYkTYsJ3b9J/R/4C673TQnRnTmBAAAAAElFTkSuQmCC"
)
168 changes: 168 additions & 0 deletions src/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import sys

import re

from src.poboy import PoboyWindow


def plugin(kernel, lifecycle):
if getattr(sys, "frozen", False):
# This plugin is source only.
return
if lifecycle == "register":
context = kernel.root
_ = kernel.translation

@context.console_command("locale", output_type="locale", hidden=True)
def locale(channel, _, **kwargs):
return "locale", "en"

@context.console_command(
"generate", input_type="locale", output_type="locale", hidden=True
)
def generate_locale(channel, _, data=None, **kwargs):
return "locale", data

@context.console_argument("locale", help="locale use for these opeations")
@context.console_command(
"change", input_type="locale", output_type="locale", hidden=True
)
def change_locale(channel, _, data=None, locale=None, **kwargs):
if locale is None:
raise SyntaxError
channel("locale changed from %s to %s" % (data, locale))
return "locale", locale

@context.console_command("update", input_type="locale", hidden=True)
def update_locale(channel, _, data=None, **kwargs):
"""
This script updates the message.po structure with the original translation information.
@param channel:
@param _:
@param data:
@param kwargs:
@return:
"""
if data == "en":
channel(
"Cannot update English since it is the default language and has no file"
)
keys = dict()
translations = open(
"./locale/%s/LC_MESSAGES/meerk40t.po" % data, "r", encoding="utf-8"
)

file_lines = translations.readlines()
key = None
index = 0
translation_header = []
while index < len(file_lines):
# Header is defined as the first batch of uninterrupted lines in the file.
try:
if file_lines[index]:
translation_header.append(file_lines[index])
else:
break
index += 1
except IndexError:
break

while index < len(file_lines):
try:
# Find msgid and all multi-lined message ids
if re.match('msgid "(.*)"', file_lines[index]):
m = re.match('msgid "(.*)"', file_lines[index])
key = m.group(1)
index += 1
if index >= len(file_lines):
break
while re.match('^"(.*)"$', file_lines[index]):
m = re.match('^"(.*)"$', file_lines[index])
key += m.group(1)
index += 1

# find all message strings and all multi-line message strings
if re.match('msgstr "(.*)"', file_lines[index]):
m = re.match('msgstr "(.*)"', file_lines[index])
value = [file_lines[index]]
if len(key) > 0:
keys[key] = value
index += 1
while re.match('^"(.*)"$', file_lines[index]):
value.append(file_lines[index])
if len(key) > 0:
keys[key] = value
index += 1
index += 1
except IndexError:
break

template = open("./locale/messages.po", "r", encoding="utf-8")
lines = []

file_lines = list(template.readlines())
index = 0
template_header = []
while index < len(file_lines):
# Header is defined as the first batch of uninterrupted lines in the file.
# We read the template header but do not use them.
try:
if file_lines[index]:
template_header.append(file_lines[index])
else:
break
index += 1
except IndexError:
break

# Lines begins with the translation's header information.
lines.extend(translation_header)
while index < len(file_lines):
try:
# Attempt to locate message id
if re.match('msgid "(.*)"', file_lines[index]):
lines.append(file_lines[index])
m = re.match('msgid "(.*)"', file_lines[index])
key = m.group(1)
index += 1
while re.match('^"(.*)"$', file_lines[index]):
lines.append(file_lines[index])
key += m.group(1)
index += 1
except IndexError:
pass
try:
# Attempt to locate message string
if re.match('msgstr "(.*)"', file_lines[index]):
if key in keys:
lines.extend(keys[key])
index += 1
while re.match('^"(.*)"$', file_lines[index]):
index += 1
else:
lines.append(file_lines[index])
index += 1
while re.match('^"(.*)"$', file_lines[index]):
lines.append(file_lines[index])
index += 1
except IndexError:
pass
try:
# We append any line if it wasn't fully read by msgid and msgstr readers.
lines.append(file_lines[index])
index += 1
except IndexError:
break

filename = "meerk40t.update"
channel("writing %s" % filename)
import codecs

template = codecs.open(filename, "w", "utf8")
template.writelines(lines)

try:
kernel.register("window/Translate", PoboyWindow)
except NameError:
pass
Loading

0 comments on commit db1fb81

Please sign in to comment.