From e7cab3b975d2c7d4ca637a1abe27662ef8f744fa Mon Sep 17 00:00:00 2001 From: Martin Doucha Date: Tue, 20 Dec 2016 18:54:20 +0100 Subject: [PATCH] Add Auth and Crud messages when updating language files --- gluon/languages.py | 24 +++++++++++++++--------- gluon/tools.py | 24 +++++++++++++----------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/gluon/languages.py b/gluon/languages.py index 0faedf33e..b626457c9 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -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): @@ -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) diff --git a/gluon/tools.py b/gluon/tools.py index 053dc9adf..8a5b5aaa7 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -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 @@ -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):