Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
[bug 1226601] Fix issues with extract_db command
Browse files Browse the repository at this point in the history
* switch from _lazy to pgettext
* redo the code that saves the files so that it's saving files in the
  relevant app
  • Loading branch information
willkg committed Nov 20, 2015
1 parent 8d34e37 commit 3cf9374
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
49 changes: 17 additions & 32 deletions fjord/base/management/commands/extract_db.py
Expand Up @@ -51,29 +51,14 @@ class Command(BaseCommand):
"""
help = 'Pulls strings from the database and writes them to python file.'

def add_arguments(self, parser):
parser.add_argument(
'-o', '--outputfile',
type=str,
action='store',
default=os.path.join(settings.BASE_DIR, 'fjord', 'base',
'db_strings.py'),
help=(
'The file where extracted strings are written to. (Default: '
'%default)'
),
)

def handle(self, *args, **options):
try:
apps = settings.DB_LOCALIZE
except AttributeError:
raise CommandError('DB_LOCALIZE setting is not defined!')

outputfile = options['outputfile']

strings = []
for app, models in apps.items():
strings = []
for model, params in models.items():
model_class = get_model(app, model)
attrs = params['attrs']
Expand All @@ -83,27 +68,27 @@ def handle(self, *args, **options):
for i in range(len(attrs)):
msg = {
'id': item[i],
'loc': 'DB: %s.%s.%s' % (app, model, attrs[i]),
'ctxt': 'DB: %s.%s.%s' % (app, model, attrs[i]),
'comments': params.get('comments')
}
strings.append(msg)

py_file = os.path.expanduser(outputfile)
py_file = os.path.abspath(py_file)

print 'Outputting db strings to: %s' % py_file
with open(py_file, 'w+') as f:
f.write(HEADER)
f.write(
'from django.utils.translation import ugettext_lazy as _lazy'
'\n\n'
outputfile = os.path.join(
settings.BASE_DIR, 'fjord', app, 'db_strings.py'
)
for s in strings:
comments = s['comments']
if comments:
for c in comments:
f.write((u'# l10n: %s\n' % c).encode('utf8'))
outputfile = os.path.abspath(outputfile)

tmpl = u'pgettext("""%(ctxt)s""", """%(id)s""")\n'

print 'Outputting db strings to: %s' % outputfile
with open(outputfile, 'w+') as f:
f.write(HEADER)
f.write(
(u'_lazy("""%(id)s""", \'%(loc)s\')\n' % s).encode('utf8')
'from django.utils.translation import pgettext'
'\n\n'
)
for s in strings:
for c in s['comments']:
f.write((u'# l10n: %s\n' % c).encode('utf8'))

f.write((tmpl % s).encode('utf8'))
12 changes: 6 additions & 6 deletions fjord/base/db_strings.py → fjord/feedback/db_strings.py
Expand Up @@ -13,15 +13,15 @@
# ./manage.py extract_db
#
#######################################################################
from django.utils.translation import ugettext_lazy as _lazy
from django.utils.translation import pgettext

# l10n: This is a product name
_lazy("""Firefox""", 'DB: feedback.Product.display_name')
pgettext("""DB: feedback.Product.display_name""", """Firefox""")
# l10n: This is a product name
_lazy("""Firefox for Android""", 'DB: feedback.Product.display_name')
pgettext("""DB: feedback.Product.display_name""", """Firefox for Android""")
# l10n: This is a product name
_lazy("""Firefox OS""", 'DB: feedback.Product.display_name')
pgettext("""DB: feedback.Product.display_name""", """Firefox OS""")
# l10n: This is a product name
_lazy("""Firefox Developer""", 'DB: feedback.Product.display_name')
pgettext("""DB: feedback.Product.display_name""", """Firefox Developer""")
# l10n: This is a product name
_lazy("""Firefox for iOS""", 'DB: feedback.Product.display_name')
pgettext("""DB: feedback.Product.display_name""", """Firefox for iOS""")

0 comments on commit 3cf9374

Please sign in to comment.