[gen] Added boolean Tool.loadTranslationsAtStartup that, if False, prevents to overwrite, on a production site, translations edited through-the-web by users. If True, at every Zope startup, Translation objects are overwritten by the content of their corresponding po files on disk.

This commit is contained in:
Gaetan Delannay 2012-06-03 21:55:26 +02:00
parent 8f57163c2a
commit 5b255ce55d
3 changed files with 24 additions and 19 deletions

View file

@ -326,23 +326,26 @@ class ZopeInstaller:
appyTool.create('translations', noSecurity=True, appyTool.create('translations', noSecurity=True,
id=language, title=title) id=language, title=title)
appyTool.log('Translation object created for "%s".' % language) appyTool.log('Translation object created for "%s".' % language)
# Now, we synchronise every Translation object with the corresponding
# "po" file on disk.
appFolder = self.config.diskFolder
appName = self.config.PROJECTNAME
i18nFolder = os.path.join(appFolder, 'tr')
for translation in appyTool.translations:
# Get the "po" file
poName = '%s-%s.po' % (appName, translation.id)
poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
for message in poFile.messages:
setattr(translation, message.id, message.getMessage())
appyTool.log('Translation "%s" updated from "%s".' % \
(translation.id, poName))
# Execute custom installation code if any # Execute custom installation code if any
if hasattr(appyTool, 'onInstall'): appyTool.onInstall() if hasattr(appyTool, 'onInstall'): appyTool.onInstall()
# Now, if required, we synchronise every Translation object with the
# corresponding "po" file on disk.
if appyTool.loadTranslationsAtStartup:
appFolder = self.config.diskFolder
appName = self.config.PROJECTNAME
i18nFolder = os.path.join(appFolder, 'tr')
for translation in appyTool.translations:
# Get the "po" file
poName = '%s-%s.po' % (appName, translation.id)
poFile = PoParser(os.path.join(i18nFolder, poName)).parse()
for message in poFile.messages:
setattr(translation, message.id, message.getMessage())
appyTool.log('Translation "%s" updated from "%s".' % \
(translation.id, poName))
def configureSessions(self): def configureSessions(self):
'''Configure the session machinery.''' '''Configure the session machinery.'''
# Register a function warning us when a session object is deleted. When # Register a function warning us when a session object is deleted. When

View file

@ -213,9 +213,9 @@ toolFieldPrefixes = ('defaultValue', 'podTemplate', 'formats', 'resultColumns',
'searchFields', 'optionalFields', 'showWorkflow', 'searchFields', 'optionalFields', 'showWorkflow',
'showAllStatesInPhase') 'showAllStatesInPhase')
defaultToolFields = ('title', 'mailHost', 'mailEnabled', 'mailFrom', defaultToolFields = ('title', 'mailHost', 'mailEnabled', 'mailFrom',
'appyVersion', 'users', 'groups', 'translations', 'pages', 'appyVersion', 'users', 'groups', 'translations',
'unoEnabledPython','openOfficePort', 'loadTranslationsAtStartup', 'pages', 'unoEnabledPython',
'numberOfResultsPerPage') 'openOfficePort', 'numberOfResultsPerPage')
class Tool(ModelClass): class Tool(ModelClass):
# In a ModelClass we need to declare attributes in the following list. # In a ModelClass we need to declare attributes in the following list.
@ -242,10 +242,11 @@ class Tool(ModelClass):
page=gen.Page('groups', show=isManager), page=gen.Page('groups', show=isManager),
queryable=True, queryFields=('title', 'login'), queryable=True, queryFields=('title', 'login'),
showHeaders=True, shownInfo=('title', 'login', 'roles')) showHeaders=True, shownInfo=('title', 'login', 'roles'))
pt = gen.Page('translations', show=isManager)
translations = gen.Ref(Translation, multiplicity=(0,None), add=False, translations = gen.Ref(Translation, multiplicity=(0,None), add=False,
link=False, show='view', link=False, show='view', page=pt,
back=gen.Ref(attribute='trToTool', show=False), back=gen.Ref(attribute='trToTool', show=False))
page=gen.Page('translations', show=isManager)) loadTranslationsAtStartup = gen.Boolean(default=True, show=False, page=pt)
pages = gen.Ref(Page, multiplicity=(0,None), add=True, link=False, pages = gen.Ref(Page, multiplicity=(0,None), add=True, link=False,
show='view', back=gen.Ref(attribute='toTool3', show=False), show='view', back=gen.Ref(attribute='toTool3', show=False),
page=gen.Page('pages', show=isManager)) page=gen.Page('pages', show=isManager))

1
gen/ui/icons.pt Normal file
View file

@ -0,0 +1 @@
<span metal:define-macro="icons"></span>