2 language applications

gods1child alankarmisra at hotmail.com
Wed Jun 6 08:38:44 EDT 2001


Why not just have two different dictionaries like:
en_messages = {'greetings':'Hello','farewell':'Goodbye','inquiry':'How
are you?'}
fr_messages = {'greetings':'Bonjour','farewell':'Au
revoir','inquiry':'Comment allez-vous?'}

then based on locale use the appropriate dictionary. To avoid
namespace pollution, and to avoid creating all the dictionaries when
all you need is one, you could create a class which could have
something like Java does:
MessageBundle.setLocale('en') 
MessageBundle.get('greetings') # returns Hello
MessageBundle.setLocale('fr')
MessageBundle.get('greetings') # returns Bonjour

internally the class could use a dictionary created based on the
locale (instead of creating all of them and then assigning) if the
messages are few, or rely on a text file (with some caching mechanism)
for its data.



More information about the Python-list mailing list