Last active
May 5, 2017 11:07
-
-
Save mdiener21/5da03f2d2473eb24bf95bb86c6f5e291 to your computer and use it in GitHub Desktop.
Generate a Django html file template for translations not in html or javascript but from model field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import psycopg2 | |
| conn = psycopg2.connect(host='localhost', user='someuser', port='5432', password='verysecretpwd', database='myDbName') | |
| cur = conn.cursor() | |
| def generate_poi_translation_template(filename): | |
| # query the database table for the list of names you want to translate | |
| sel_building_floor_id = """SELECT f.cat_name FROM ( | |
| SELECT DISTINCT ON (cat_name) cat_name, parent_id | |
| FROM django.poi_manager_poicategory) AS f ORDER BY parent_id DESC ;""" | |
| cur.execute(sel_building_floor_id) | |
| res_floor_id = cur.fetchall() | |
| with open(filename, 'w') as f: | |
| f.write('{% load i18n %}' + '\n\n') | |
| for r in res_floor_id: | |
| f.write('{% trans "' + r[0] + '" %}\n') | |
| generate_poi_translation_template('poi-trans.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment