Skip to content

Commit

Permalink
RF: rename _() to _translate() - initial commit
Browse files Browse the repository at this point in the history
- was getting a name conflict: dependency messing with global _, leading to crash back in the app

#$ find . -name '*.py' | xargs python ~/code/sub_translate.py

#import fileinput, sys, re
#for fpy in sys.argv[1:]:
#  i = 0
#  for line in fileinput.input(fpy, inplace=True):
#    sys.stdout.write(re.sub(r'\b_\(', '_translate(', line))
#    # sys.stdout is redirected to the file
  • Loading branch information
jeremygray committed Sep 12, 2014
1 parent 42a37aa commit dd7619c
Show file tree
Hide file tree
Showing 39 changed files with 961 additions and 959 deletions.
20 changes: 10 additions & 10 deletions psychopy/app/_psychopyApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def __init__(self, parent=None, ID=-1, app=None, title="PsychoPy2"):
self.menuBar = wx.MenuBar()

self.viewMenu = wx.Menu()
self.menuBar.Append(self.viewMenu, _('&View'))
self.viewMenu.Append(self.app.IDs.openBuilderView, _("&Open Builder view\t%s") %self.app.keys['switchToBuilder'], _("Open a new Builder view"))
self.menuBar.Append(self.viewMenu, _translate('&View'))
self.viewMenu.Append(self.app.IDs.openBuilderView, _translate("&Open Builder view\t%s") %self.app.keys['switchToBuilder'], _translate("Open a new Builder view"))
wx.EVT_MENU(self, self.app.IDs.openBuilderView, self.app.showBuilder)
self.viewMenu.Append(self.app.IDs.openCoderView, _("&Open Coder view\t%s") %self.app.keys['switchToCoder'], _("Open a new Coder view"))
self.viewMenu.Append(self.app.IDs.openCoderView, _translate("&Open Coder view\t%s") %self.app.keys['switchToCoder'], _translate("Open a new Coder view"))
wx.EVT_MENU(self, self.app.IDs.openCoderView, self.app.showCoder)
item=self.viewMenu.Append(wx.ID_EXIT, _("&Quit\t%s") %self.app.keys['quit'], _("Terminate the program"))
item=self.viewMenu.Append(wx.ID_EXIT, _translate("&Quit\t%s") %self.app.keys['quit'], _translate("Terminate the program"))
self.Bind(wx.EVT_MENU, self.app.quit, item)

self.SetMenuBar(self.menuBar)
Expand Down Expand Up @@ -105,13 +105,13 @@ def onInit(self, showSplash=True, testMode=False):
splash = AS.AdvancedSplash(None, bitmap=splashBitmap, timeout=3000, style=AS.AS_TIMEOUT|wx.FRAME_SHAPED,
shadowcolour=wx.RED)#could use this in future for transparency
splash.SetTextPosition((10,240))
splash.SetText(_(" Loading libraries..."))
splash.SetText(_translate(" Loading libraries..."))
else:
splash=None

#LONG IMPORTS - these need to be imported after splash screen starts (they're slow)
#but then that they end up being local so keep track in self
if splash: splash.SetText(_(" Loading PsychoPy2..."))
if splash: splash.SetText(_translate(" Loading PsychoPy2..."))
from psychopy import compatibility
from psychopy.app import coder, builder, dialogs, wxIDs, urls #import coder and builder here but only use them later
self.keys = self.prefs.keys
Expand Down Expand Up @@ -196,7 +196,7 @@ def onInit(self, showSplash=True, testMode=False):

#create both frame for coder/builder as necess
if splash:
splash.SetText(_(" Creating frames..."))
splash.SetText(_translate(" Creating frames..."))
self.coder = None
self.builderFrames = []
self.copiedRoutine=None
Expand All @@ -216,11 +216,11 @@ def onInit(self, showSplash=True, testMode=False):

ok, msg = compatibility.checkCompatibility(last, self.version, self.prefs, fix=True)
if not ok and not self.firstRun and not self.testMode: #tell the user what has changed
dlg = dialogs.MessageDialog(parent=None,message=msg,type='Info', title=_("Compatibility information"))
dlg = dialogs.MessageDialog(parent=None,message=msg,type='Info', title=_translate("Compatibility information"))
dlg.ShowModal()

if self.prefs.app['showStartupTips'] and not self.testMode:
tipFile = os.path.join(self.prefs.paths['resources'], _("tips.txt"))
tipFile = os.path.join(self.prefs.paths['resources'], _translate("tips.txt"))
tipIndex = self.prefs.appData['tipIndex']
tp = wx.CreateFileTipProvider(tipFile, tipIndex)
showTip = wx.ShowTip(None, tp)
Expand Down Expand Up @@ -492,7 +492,7 @@ def showAbout(self, event):
logging.debug('PsychoPyApp: Showing about dlg')

license = open(os.path.join(self.prefs.paths['psychopy'],'LICENSE.txt'), 'rU').read()
msg = _("""For stimulus generation and experimental control in python.
msg = _translate("""For stimulus generation and experimental control in python.
PsychoPy depends on your feedback. If something doesn't work
then let us know at psychopy-users@googlegroups.com""").replace(' ', '')
Expand Down
364 changes: 182 additions & 182 deletions psychopy/app/builder/builder.py

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions psychopy/app/builder/components/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from psychopy.constants import *

# only use _localized values for label values, nothing functional
_localized = {'name': _('Name'), # fieldName: display label
'startType': _('start type'), 'stopType': _('stop type'),
'startVal': _('Start'), 'stopVal': _('Stop'),
'startEstim': _('Expected start (s)'), 'durationEstim': _('Expected duration (s)')
_localized = {'name': _translate('Name'), # fieldName: display label
'startType': _translate('start type'), 'stopType': _translate('stop type'),
'startVal': _translate('Start'), 'stopVal': _translate('Stop'),
'startEstim': _translate('Expected start (s)'), 'durationEstim': _translate('Expected duration (s)')
}

class BaseComponent(object):
Expand All @@ -28,28 +28,28 @@ def __init__(self, exp, parentName, name='',

self.params={}
self.params['name']=Param(name, valType='code',
hint=_("Name of this component (alpha-numeric or _, no spaces)"),
hint=_translate("Name of this component (alpha-numeric or _, no spaces)"),
label=_localized['name'])
self.params['startType']=Param(startType, valType='str',
allowedVals=['time (s)', 'frame N', 'condition'],
hint=_("How do you want to define your start point?"),
hint=_translate("How do you want to define your start point?"),
label=_localized['startType'])
self.params['stopType']=Param(stopType, valType='str',
allowedVals=['duration (s)', 'duration (frames)', 'time (s)', 'frame N', 'condition'],
hint=_("How do you want to define your end point?"),
hint=_translate("How do you want to define your end point?"),
label=_localized['stopType'])
self.params['startVal']=Param(startVal, valType='code', allowedTypes=[],
hint=_("When does the component start?"),
hint=_translate("When does the component start?"),
label=_localized['startVal'])
self.params['stopVal']=Param(stopVal, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("When does the component end? (blank is endless)"),
hint=_translate("When does the component end? (blank is endless)"),
label=_localized['stopVal'])
self.params['startEstim']=Param(startEstim, valType='code', allowedTypes=[],
hint=_("(Optional) expected start (s), purely for representing in the timeline"),
hint=_translate("(Optional) expected start (s), purely for representing in the timeline"),
label=_localized['startEstim'])
self.params['durationEstim']=Param(durationEstim, valType='code', allowedTypes=[],
hint=_("(Optional) expected duration (s), purely for representing in the timeline"),
hint=_translate("(Optional) expected duration (s), purely for representing in the timeline"),
label=_localized['durationEstim'])

self.order=['name'] # name first, then timing, then others
Expand Down
22 changes: 11 additions & 11 deletions psychopy/app/builder/components/_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from os import path

# only use _localized values for label values, nothing functional:
_localized = {'units': _('Units'),
'color': _('Color'), 'colorSpace': _('Color space'),
'opacity': _('Opacity'), 'pos': _('Position [x,y]'),
'ori': _('Orientation'), 'size': _('Size [w,h]')
_localized = {'units': _translate('Units'),
'color': _translate('Color'), 'colorSpace': _translate('Color space'),
'opacity': _translate('Opacity'), 'pos': _translate('Position [x,y]'),
'ori': _translate('Orientation'), 'size': _translate('Size [w,h]')
}

class VisualComponent(BaseComponent):
Expand All @@ -28,31 +28,31 @@ def __init__(self, exp, parentName, name='', units='from exp settings', color='$
self.psychopyLibs=['visual']#needs this psychopy lib to operate

self.params['units']=Param(units, valType='str', allowedVals=['from exp settings', 'deg', 'cm', 'pix', 'norm'],
hint=_("Units of dimensions for this stimulus"),
hint=_translate("Units of dimensions for this stimulus"),
label=_localized['units'])
self.params['color']=Param(color, valType='str', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Color of this stimulus (e.g. $[1,1,0], red ); Right-click to bring up a color-picker (rgb only)"),
hint=_translate("Color of this stimulus (e.g. $[1,1,0], red ); Right-click to bring up a color-picker (rgb only)"),
label=_localized['color'])
self.params['opacity']=Param(opacity, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Opacity of the stimulus (1=opaque, 0=fully transparent, 0.5=translucent)"),
hint=_translate("Opacity of the stimulus (1=opaque, 0=fully transparent, 0.5=translucent)"),
label=_localized['opacity'])
self.params['colorSpace']=Param(colorSpace, valType='str', allowedVals=['rgb','dkl','lms'],
updates='constant',
hint=_("Choice of color space for the color (rgb, dkl, lms)"),
hint=_translate("Choice of color space for the color (rgb, dkl, lms)"),
label=_localized['colorSpace'])
self.params['pos']=Param(pos, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Position of this stimulus (e.g. [1,2] )"),
hint=_translate("Position of this stimulus (e.g. [1,2] )"),
label=_localized['pos'])
self.params['size']=Param(size, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Size of this stimulus (either a single value or x,y pair, e.g. 2.5, [1,2] "),
hint=_translate("Size of this stimulus (either a single value or x,y pair, e.g. 2.5, [1,2] "),
label=_localized['size'])
self.params['ori']=Param(ori, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Orientation of this stimulus (in deg)"),
hint=_translate("Orientation of this stimulus (in deg)"),
label=_localized['ori'])
def writeFrameCode(self,buff):
"""Write the code that will be called every frame
Expand Down
8 changes: 4 additions & 4 deletions psychopy/app/builder/components/aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

thisFolder = path.abspath(path.dirname(__file__)) # the absolute path to the folder containing this path
iconFile = path.join(thisFolder,'aperture.png')
tooltip = _('Aperture: restrict the drawing of stimuli to a given region')
tooltip = _translate('Aperture: restrict the drawing of stimuli to a given region')

class ApertureComponent(VisualComponent):
"""An event class for using GL stencil to restrict the viewing area to a
Expand All @@ -33,9 +33,9 @@ def __init__(self, exp, parentName, name='aperture', units='norm',
#params:
#NB make some adjustments on the params defined by _visual component
self.order = ['name', 'size', 'pos'] # make sure this is at top
self.params['size'].hint = _("How big is the aperture? (a single number for diameter)")
self.params['size'].label=_("Size") # only localize hints and labels
self.params['pos'].hint = _("Where is the aperture centred?")
self.params['size'].hint = _translate("How big is the aperture? (a single number for diameter)")
self.params['size'].label=_translate("Size") # only localize hints and labels
self.params['pos'].hint = _translate("Where is the aperture centred?")
#inherited from _visual component but not needed
del self.params['ori']
del self.params['color']
Expand Down
14 changes: 7 additions & 7 deletions psychopy/app/builder/components/cedrusBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

thisFolder = path.abspath(path.dirname(__file__)) # abs path to the folder containing this path
iconFile = path.join(thisFolder, 'cedrusBox.png')
tooltip = _('Cedrus Button Box: Cedrus response boxes, using the pyxid library provided by Cedrus')
tooltip = _translate('Cedrus Button Box: Cedrus response boxes, using the pyxid library provided by Cedrus')

# only use _localized values for label values, nothing functional:
_localized = {'deviceNumber': _('Device number'),
'useBoxTimer': _("Use box timer")}
_localized = {'deviceNumber': _translate('Device number'),
'useBoxTimer': _translate("Use box timer")}

class cedrusButtonBoxComponent(KeyboardComponent):
"""An event class for checking an Cedrus RBxxx button boxes using XID library
Expand Down Expand Up @@ -46,20 +46,20 @@ def __init__(self, exp, parentName, name='buttonBox',
self.url = "http://www.psychopy.org/builder/components/cedrusButtonBox.html"
self.exp.requirePsychopyLibs(['hardware'])

self.params['correctAns'].hint = _("What is the 'correct' response? NB, buttons are labelled 0 to 6 on a 7-button box. Enter 'None' (no quotes) if withholding a response is correct. Might be helpful to add a correctAns column and use $thisTrial.correctAns")
self.params['correctAns'].hint = _translate("What is the 'correct' response? NB, buttons are labelled 0 to 6 on a 7-button box. Enter 'None' (no quotes) if withholding a response is correct. Might be helpful to add a correctAns column and use $thisTrial.correctAns")
self.params['correctAns'].valType = 'code'
self.params['allowedKeys'].hint = _('Keys to be read (blank for any) or key numbers separated by commas')
self.params['allowedKeys'].hint = _translate('Keys to be read (blank for any) or key numbers separated by commas')
self.params['deviceNumber'] = Param(deviceNumber, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Device number, if you have multiple devices which one do you want (0, 1, 2...)"),
hint=_translate("Device number, if you have multiple devices which one do you want (0, 1, 2...)"),
label=_localized['deviceNumber'], categ='Advanced')
#self.params['getReleaseTime'] = Param(getReleaseTime, valType='bool', allowedVals=[True, False],
# updates='constant', allowedUpdates=[],
# hint="Wait for the key to be released and store the time that it was held down",
# label="Get release time")
self.params['useBoxTimer'] = Param(getReleaseTime, valType='bool', allowedVals=[True, False],
updates='constant', allowedUpdates=[],
hint=_("According to Cedrus the response box timer has a drift - use with caution!"),
hint=_translate("According to Cedrus the response box timer has a drift - use with caution!"),
label=_localized['useBoxTimer'], categ='Advanced')

def writeStartCode(self, buff):
Expand Down
22 changes: 11 additions & 11 deletions psychopy/app/builder/components/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

thisFolder = path.abspath(path.dirname(__file__))#the absolute path to the folder containing this path
iconFile = path.join(thisFolder,'code.png')
tooltip = _('Code: insert python commands into an experiment')
_localized = {'Begin Experiment': _('Begin Experiment'),
'Begin Routine': _('Begin Routine'),
'Each Frame': _('Each Frame'),
'End Routine': _('End Routine'),
'End Experiment': _('End Experiment')}
tooltip = _translate('Code: insert python commands into an experiment')
_localized = {'Begin Experiment': _translate('Begin Experiment'),
'Begin Routine': _translate('Begin Routine'),
'Each Frame': _translate('Each Frame'),
'End Routine': _translate('End Routine'),
'End Experiment': _translate('End Experiment')}

class CodeComponent(BaseComponent):
categories = ['Custom']#an attribute of the class, determines the section in the components panel
Expand All @@ -28,23 +28,23 @@ def __init__(self, exp, parentName, name='code',
self.order = ['name', 'Begin Experiment', 'Begin Routine', 'Each Frame', 'End Routine', 'End Experiment'] # want a copy, else codeParamNames list gets mutated
self.params['Begin Experiment']=Param(beginExp, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code at the start of the experiment (initialization); right-click checks syntax"),
hint=_translate("Code at the start of the experiment (initialization); right-click checks syntax"),
label=_localized['Begin Experiment'])
self.params['Begin Routine']=Param(beginRoutine, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code to be run at the start of each repeat of the Routine (e.g. each trial); right-click checks syntax"),
hint=_translate("Code to be run at the start of each repeat of the Routine (e.g. each trial); right-click checks syntax"),
label=_localized['Begin Routine'])
self.params['Each Frame']=Param(eachFrame, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code to be run on every video frame during for the duration of this Routine; right-click checks syntax"),
hint=_translate("Code to be run on every video frame during for the duration of this Routine; right-click checks syntax"),
label=_localized['Each Frame'])
self.params['End Routine']=Param(endRoutine, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code at the end of this repeat of the Routine (e.g. getting/storing responses); right-click checks syntax"),
hint=_translate("Code at the end of this repeat of the Routine (e.g. getting/storing responses); right-click checks syntax"),
label=_localized['End Routine'])
self.params['End Experiment']=Param(endRoutine, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code at the end of the entire experiment (e.g. saving files, resetting computer); right-click checks syntax"),
hint=_translate("Code at the end of the entire experiment (e.g. saving files, resetting computer); right-click checks syntax"),
label=_localized['End Experiment'])
# these inherited params are harmless but might as well trim:
for p in ['startType', 'startVal', 'startEstim', 'stopVal', 'stopType', 'durationEstim']:
Expand Down
Loading

0 comments on commit dd7619c

Please sign in to comment.