i18n first draft

- gettext support added in SàT
- first draft of french translation
- added README with a HOWTO for translators
This commit is contained in:
Goffi 2010-03-03 17:12:23 +11:00
commit 4a293cdaa1

View file

@ -74,17 +74,17 @@ class Param():
try:
with open(file_gen, 'r') as file_gen_pickle:
self.params_gen=pickle.load(file_gen_pickle)
debug("general params data loaded")
debug(_("general params data loaded"))
except:
error ("Can't load general params data !")
error (_("Can't load general params data !"))
if os.path.exists(file_ind):
try:
with open(file_ind, 'r') as file_ind_pickle:
self.params=pickle.load(file_ind_pickle)
debug("individual params data loaded")
debug(_("individual params data loaded"))
except:
error ("Can't load individual params data !")
error (_("Can't load individual params data !"))
def save_xml(self, file):
"""Save parameters template to xml file"""
@ -121,7 +121,7 @@ class Param():
"""Create a new profile
@param name: Name of the profile"""
if self.params.has_key(name):
info ('The profile name already exists')
info (_('The profile name already exists'))
return 1
self.params[name]={}
return 0
@ -130,7 +130,7 @@ class Param():
"""Delete an existing profile
@param name: Name of the profile"""
if not self.params.has_key(name):
error ('Trying to delete an unknown profile')
error (_('Trying to delete an unknown profile'))
return 1
del self.params[name]
return 0
@ -146,12 +146,12 @@ class Param():
return ""
default = self.host.memory.getPrivate('Profile_default')
if not default or not default in self.params:
info('No default profile, returning first one') #TODO: manage real default profile
info(_('No default profile, returning first one')) #TODO: manage real default profile
default = self.params.keys()[0]
self.host.memory.setPrivate('Profile_default', default)
return default #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists
if not self.params.has_key(profile_key):
info ('Trying to access an unknown profile')
info (_('Trying to access an unknown profile'))
return ""
return profile_key
@ -191,7 +191,7 @@ class Param():
self.setParam(name, value, category) #FIXME: better to set param xml value ???
def __default_ko(self, failure, name, category):
error ("Can't determine default value for [%s/%s]: %s" % (category, name, str(failure.value)))
error (_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category':category, 'name':name, 'reason':str(failure.value)})
def setDefault(self, name, category, callback, errback=None):
"""Set default value of parameter
@ -204,7 +204,7 @@ class Param():
#TODO: send signal param update if value changed
node = self.__getParamNode(name, category, '@ALL@')
if not node:
error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category})
return
if node[1].getAttribute('default_cb') == 'yes':
del node[1].attributes['default_cb']
@ -222,7 +222,7 @@ class Param():
@return: attribute"""
node = self.__getParamNode(name, category)
if not node:
error("Requested param [%s] in category [%s] doesn't exist !" , name, category)
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name':name, 'category':category})
return None
if node[0] == 'general':
@ -233,7 +233,7 @@ class Param():
profile = self.getProfileName(profile_key)
if not profile:
error('Requesting a param for an non-existant profile')
error(_('Requesting a param for an non-existant profile'))
return None
if attr == "value":
@ -287,7 +287,7 @@ class Param():
Take params xml as skeleton"""
profile = self.getProfileName(profile_key)
if not profile:
error("Asking params for inexistant profile")
error(_("Asking params for inexistant profile"))
return ""
prof_xml = self.__constructProfileXml(profile)
return_xml = prof_xml.toxml()
@ -300,7 +300,7 @@ class Param():
#TODO: manage category of general type (without existant profile)
profile = self.getProfileName(profile_key)
if not profile:
error("Asking params for inexistant profile")
error(_("Asking params for inexistant profile"))
return ""
prof_xml = self.__constructProfileXml(profile)
@ -346,7 +346,7 @@ class Param():
node = self.__getParamNode(name, category, '@ALL@')
if not node:
error('Requesting an unknown parameter (%s/%s)' % (category, name))
error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category':category, 'name':name})
return
if node[0] == 'general':
@ -358,7 +358,7 @@ class Param():
profile = self.getProfileName(profile_key)
if not profile:
error('Trying to set parameter for an unknown profile')
error(_('Trying to set parameter for an unknown profile'))
return #TODO: throw an error
type = node[1].getAttribute("type")
@ -372,7 +372,7 @@ class Memory:
"""This class manage all persistent informations"""
def __init__(self, host):
info ("Memory manager init")
info (_("Memory manager init"))
self.host = host
self.contacts={}
self.presenceStatus={}
@ -399,37 +399,37 @@ class Memory:
if os.path.exists(param_file_xml):
try:
self.params.load_xml(param_file_xml)
debug("params template loaded")
debug(_("params template loaded"))
except:
error ("Can't load params template !")
error (_("Can't load params template !"))
self.params.load_default_params()
else:
info ("No params template, using default template")
info (_("No params template, using default template"))
self.params.load_default_params()
try:
self.params.load_data(param_file_data)
debug("params loaded")
debug(_("params loaded"))
except:
error ("Can't load params !")
error (_("Can't load params !"))
#history
if os.path.exists(history_file):
try:
with open(history_file, 'r') as history_pickle:
self.history=pickle.load(history_pickle)
debug("history loaded")
debug(_("history loaded"))
except:
error ("Can't load history !")
error (_("Can't load history !"))
#private
if os.path.exists(private_file):
try:
with open(private_file, 'r') as private_pickle:
self.private=pickle.load(private_pickle)
debug("private values loaded")
debug(_("private values loaded"))
except:
error ("Can't load private values !")
error (_("Can't load private values !"))
def save(self):
"""Save parameters and all memory things to file/db"""
@ -445,13 +445,13 @@ class Memory:
self.params.save_xml(param_file_xml)
self.params.save_data(param_file_data)
debug("params saved")
debug(_("params saved"))
with open(history_file, 'w') as history_pickle:
pickle.dump(self.history, history_pickle)
debug("history saved")
debug(_("history saved"))
with open(private_file, 'w') as private_pickle:
pickle.dump(self.private, private_pickle)
debug("private values saved")
debug(_("private values saved"))
def getProfilesList(self):
return self.params.getProfilesList()
@ -494,11 +494,11 @@ class Memory:
def getHistory(self, from_jid, to_jid, size):
ret={}
if not self.history.has_key(from_jid):
error("source JID not found !")
error(_("source JID not found !"))
#TODO: throw an error here
return {}
if not self.history[from_jid].has_key(to_jid):
error("dest JID not found !")
error(_("dest JID not found !"))
#TODO: throw an error here
return {}
stamps=self.history[from_jid][to_jid].keys()
@ -525,7 +525,7 @@ class Memory:
debug("Memory addContact: %s",contact_jid.userhost())
profile = self.getProfileName(profile_key)
if not profile:
error ('Trying to add a contact to a non-existant profile')
error (_('Trying to add a contact to a non-existant profile'))
return
assert(isinstance(attributes,dict))
assert(isinstance(groups,set))
@ -537,7 +537,7 @@ class Memory:
debug("Memory delContact: %s",contact_jid.userhost())
profile = self.getProfileName(profile_key)
if not profile:
error ('Trying to delete a contact for a non-existant profile')
error (_('Trying to delete a contact for a non-existant profile'))
return
if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()):
del self.contacts[profile][contact_jid.userhost()]
@ -545,7 +545,7 @@ class Memory:
def getContact(self, contact_jid, profile_key='@DEFAULT@'):
profile = self.getProfileName(profile_key)
if not profile:
error('Asking a contact for a non-existant profile')
error(_('Asking a contact for a non-existant profile'))
return None
if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()):
self.contacts[profile][contact_jid.userhost()]
@ -559,7 +559,7 @@ class Memory:
debug ("Memory getContact OK (%s)", self.contacts)
profile = self.getProfileName(profile_key)
if not profile:
error('Asking contacts for a non-existant profile')
error(_('Asking contacts for a non-existant profile'))
return []
ret=[]
for contact in self.contacts[profile]:
@ -570,7 +570,7 @@ class Memory:
def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
profile = self.getProfileName(profile_key)
if not profile:
error('Trying to add presence status to a non-existant profile')
error(_('Trying to add presence status to a non-existant profile'))
return
if not self.presenceStatus.has_key(profile):
self.presenceStatus[profile] = {}
@ -598,7 +598,7 @@ class Memory:
"""Called to get a list of currently waiting subscription requests"""
profile = self.getProfileName(profile_key)
if not profile:
error('Asking waiting subscriptions for a non-existant profile')
error(_('Asking waiting subscriptions for a non-existant profile'))
return {}
if not self.subscriptions.has_key(profile):
return {}
@ -608,7 +608,7 @@ class Memory:
def getPresenceStatus(self, profile_key='@DEFAULT@'):
profile = self.getProfileName(profile_key)
if not profile:
error('Asking contacts for a non-existant profile')
error(_('Asking contacts for a non-existant profile'))
return {}
if not self.presenceStatus.has_key(profile):
self.presenceStatus[profile] = {}