Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added i18n from Markus #21

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from urllib.parse import urlparse #check if Online URL

from cudax_lib import get_translation
_ = get_translation(__file__) # I18N

#PIC_TAG = 0x1000 #minimal tag for api (CRC adds to tag)
BIG_SIZE = 500 #if width bigger, ask to resize
#DIALOG_FILTER = 'Pictures|*.png;*.jpg;*.jpeg;*.jpe;*.gif;*.bmp;*.ico'
Expand Down Expand Up @@ -43,14 +46,15 @@ def on_open(self, ed_self):
for index in range(ed_self.get_line_count()):
line = ed_self.get_text_line(index)
self.insert_file(ed_self, line, index)



def on_lexer(self, ed_self):
for index in range(ed_self.get_line_count()):
line = ed_self.get_text_line(index)
self.insert_file(ed_self, line, index)


def insert_file(self, ed_self, txt, nline):
##### parse syntax #####
#url can't mix with ), otherwise it become unsure ) is url or part of image syntax.
import re
x = re.findall("!\[[^\]]+\]\([^\)]+\)", txt) #get image syntax ex: ![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")
Expand All @@ -64,10 +68,8 @@ def insert_file(self, ed_self, txt, nline):
pp = p.group()[1:]
url = pp.split("\"")[0].strip() #get url
log(f"url: {url}")
#########################


##### detect URL #####
#if online URL, return
if urlparse(url).scheme in ('http', 'https'):
return
Expand All @@ -88,19 +90,18 @@ def insert_file(self, ed_self, txt, nline):
else:
filepath = ed_self.get_filename()
fn = os.path.join(os.path.dirname(filepath), url)
#########################


if not os.path.isfile(fn):
ed_self.gap(GAP_DELETE, nline, nline)
msg_status(PRE+'Cannot find picture.')
msg_status(PRE + _('Cannot find picture'))
return

ntag = 2 #for delete

res = get_image_size(fn)
if not res:
msg_status(PRE+'Cannot detect picture sizes')
msg_status(PRE + _('Cannot detect picture sizes'))
return
size_x, size_y = res

Expand All @@ -118,15 +119,15 @@ def insert_file(self, ed_self, txt, nline):

self.add_pic(ed_self, nline, fn, size_x, size_y, ntag)
ed_self.set_prop(PROP_MODIFIED, '1')
msg_status(PRE+'Added "%s", %dx%d, line %d' % (os.path.basename(fn), size_x, size_y, nline))
msg_status(PRE + _('Added "%s", %dx%d, line %d') % (os.path.basename(fn), size_x, size_y, nline))

def add_pic(self, ed_self, nline, fn, size_x, size_y, ntag):

global id_img
log(id_img)
log(fn)
if not image_proc(id_img, IMAGE_LOAD, fn):
print(PRE+'Cannot load "%s"' % os.path.basename(fn))
print(PRE + _('Cannot load "%s"') % os.path.basename(fn))
return

new_y = None
Expand All @@ -145,5 +146,5 @@ def add_pic(self, ed_self, nline, fn, size_x, size_y, ntag):
ed_self.gap(GAP_DELETE, nline, nline)
ed_self.gap(GAP_ADD, nline, id_bitmap, tag=ntag)

print(PRE+'"%s", %dx%d, line %d' % (os.path.basename(fn), size_x, size_y, nline+1))
print(PRE + _('"%s", %dx%d, line %d') % (os.path.basename(fn), size_x, size_y, nline+1))

2 changes: 2 additions & 0 deletions readme/history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2023.04.05
+ add: added i18n (patch from Markus F.)