Do you already have the mapping, perhaps in a dictionary (or can you get it into one)? If so, maybe something like:
ISO_COUNTRY_CODE_MAPPINGS = {k: T(v) for (k, v) in original_mapping. iteritems()} # requires Python 2.7 Anthony On Monday, June 25, 2012 11:53:24 AM UTC-4, Daniel Gonzalez wrote: > > Yes, that is one of the options I mentioned. If I include all possible > countries, my list would have200 entries. > > I still do not fully understand the process in which > modules/views/controllers are loaded when requests are received. > But, if I am not completely mistaken, these files are parsed each time > that a request is received. > That means that, for each request, the list of *200 countries* will be > translated to the user language. > That means, lots of times the same translation will be performed (most of > my users will have the same language settings). Even if this is highly > efficient (caching of the translated objects?), this is still a lot of > processing, which could be avoided if I had a list of pre-translated > dictionaries (one for each language that I want to support). > > Of course it could be that I am not understanding at all how localization > in web2py is done ... > > On Monday, June 25, 2012 5:22:10 PM UTC+2, Anthony wrote: >> >> Now, to support internationalization here, I see two options: >>> >>> - I implement a function which returns the desired predefined mapping, >>> according to the language of the user. How can I know this? How does the T >>> operator know this? >>> - I walk the list of ISO country codes applying the T operator to return >>> the mapping. >>> >> >> Can't you just do: >> >> ISO_COUNTRY_CODES_MAPPING = { >> 'DE': T('Germany'), >> 'ES': T('Spain'), >> 'IT': T('Italy'), >> 'US': T('United States') >> } >> >> --