Skip to content

Instantly share code, notes, and snippets.

@tejastank
Created August 20, 2012 12:05
Show Gist options
  • Save tejastank/3403565 to your computer and use it in GitHub Desktop.
Save tejastank/3403565 to your computer and use it in GitHub Desktop.
python i18n address format code: I used in OpenERP.
import re
str = '%(company_name)s%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s\n%(country_name)s'
el = { x:len(re.findall('\%\([^\%\(]+?\)s',x)) for x in str.split("\n")}
args_xml = {
'street': '<field name="street" placeholder="Street" style="width:{0}%;"/>',
'street2': '<field name="street2" placeholder="Street2" style="width:{0}%;"/>',
'city': '<field name="city" placeholder="City" style="width:{0}%;"/>',
'state_name': '<field name="state_id" placeholder="State" style="width:{0}%;"/>',
'state_code': '<field name="state_id" placeholder="State" style="width:{0}%;"/>',
'zip': '<field name="zip" placeholder="Zip" style="width:{0}%;"/>',
'country_name': '<field name="country_id" placeholder="Country" style="width:{0}%;"/>',
'country_code': '<field name="country_id" placeholder="Country" style="width:{0}%;"/>',
'company_name': '',
}
args = { y.replace("%(","").replace(")s",""): el[x] for x in el for y in re.findall('\%\([^\%\(]+?\)s', x)}
for itm in args:
args_xml[itm] = args_xml[itm].format(100/args[itm])
print args_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment