Create a gist now

Instantly share code, notes, and snippets.

Python localization
import locale
import logging
def init_localization():
'''prepare l10n'''
locale.setlocale(locale.LC_ALL, '') # use user's preferred locale
# take first two characters of country code
loc = locale.getlocale()
filename = "res/" % locale.getlocale()[0][0:2]
logging.debug( "Opening message file %s for locale %s", filename, loc[0] )
trans = gettext.GNUTranslations(open( filename, "rb" ) )
except IOError:
logging.debug( "Locale not found. Using default messages" )
trans = gettext.NullTranslations()
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment