Skip to content

Commit

Permalink
Add Auth and Crud messages when updating language files
Browse files Browse the repository at this point in the history
  • Loading branch information
nextghost committed Dec 20, 2016
1 parent efff27f commit e7cab3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 15 additions & 9 deletions gluon/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,23 @@ def findT(path, language=DEFAULT_LANGUAGE):
Note:
Must be run by the admin app
"""
from gluon.tools import Auth, Crud
lang_file = pjoin(path, 'languages', language + '.py')
sentences = read_dict(lang_file)
mp = pjoin(path, 'models')
cp = pjoin(path, 'controllers')
vp = pjoin(path, 'views')
mop = pjoin(path, 'modules')
def add_message(message):
if not message.startswith('#') and not '\n' in message:
tokens = message.rsplit('##', 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
message = tokens[0].strip() + '##' + tokens[1].strip()
if message and not message in sentences:
sentences[message] = message.replace("@markmin\x01", "")
for filename in \
listdir(mp, '^.+\.py$', 0) + listdir(cp, '^.+\.py$', 0)\
+ listdir(vp, '^.+\.html$', 0) + listdir(mop, '^.+\.py$', 0):
Expand All @@ -970,15 +981,10 @@ def findT(path, language=DEFAULT_LANGUAGE):
message = safe_eval(item)
except:
continue # silently ignore inproperly formatted strings
if not message.startswith('#') and not '\n' in message:
tokens = message.rsplit('##', 1)
else:
# this allows markmin syntax in translations
tokens = [message]
if len(tokens) == 2:
message = tokens[0].strip() + '##' + tokens[1].strip()
if message and not message in sentences:
sentences[message] = message.replace("@markmin\x01", "")
add_message(message)
gluon_msg = [Auth.default_messages, Crud.default_messages]
for item in [x for m in gluon_msg for x in m.values() if x is not None]:
add_message(item)
if not '!langcode!' in sentences:
sentences['!langcode!'] = (
DEFAULT_LANGUAGE if language in ('default', DEFAULT_LANGUAGE) else language)
Expand Down
24 changes: 13 additions & 11 deletions gluon/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4798,6 +4798,18 @@ def wikimenu(self):

class Crud(object): # pragma: no cover

default_messages = dict(
submit_button = 'Submit',
delete_label = 'Check to delete',
record_created = 'Record Created',
record_updated = 'Record Updated',
record_deleted = 'Record Deleted',
update_log = 'Record %(id)s updated',
create_log = 'Record %(id)s created',
read_log = 'Record %(id)s read',
delete_log = 'Record %(id)s deleted',
)

def url(self, f=None, args=None, vars=None):
"""
This should point to the controller that exposes
Expand Down Expand Up @@ -4846,17 +4858,7 @@ def __init__(self, environment, db=None, controller='default'):
settings.lock_keys = True

messages = self.messages = Messages(current.T)
messages.submit_button = 'Submit'
messages.delete_label = 'Check to delete'
messages.record_created = 'Record Created'
messages.record_updated = 'Record Updated'
messages.record_deleted = 'Record Deleted'

messages.update_log = 'Record %(id)s updated'
messages.create_log = 'Record %(id)s created'
messages.read_log = 'Record %(id)s read'
messages.delete_log = 'Record %(id)s deleted'

messages.update(Crud.default_messages)
messages.lock_keys = True

def __call__(self):
Expand Down

0 comments on commit e7cab3b

Please sign in to comment.