From 2abd6473758ca609deb0adb5caa685f4d8e34d1b Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 24 Jan 2014 16:17:46 -0500 Subject: [PATCH 1/2] Always add Plural metadata to dummy translations. When this was conditional, we'd have plural info in some files, not in others. Then we'd merge them, and msgcat would add wacky markers to indicate the difference, and the metadata wouldn't parse. --- i18n/make_dummy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/i18n/make_dummy.py b/i18n/make_dummy.py index 58a874f5fb..13ccef5ef3 100755 --- a/i18n/make_dummy.py +++ b/i18n/make_dummy.py @@ -42,11 +42,9 @@ def main(file, locale): for msg in pofile: converter.convert_msg(msg) - # If any message has a plural, then the file needs plural information. # Apply declaration for English pluralization rules so that ngettext will # do something reasonable. - if any(m.msgid_plural for m in pofile): - pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' + pofile.metadata['Plural-Forms'] = 'nplurals=2; plural=(n != 1);' new_file = new_filename(file, locale) create_dir_if_necessary(new_file) From 1e8a0cb7e0d842c6613f587cc6b70130de9f6a34 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 24 Jan 2014 16:18:43 -0500 Subject: [PATCH 2/2] Tighten up the extraction I/O We were writing the main file twice. No need. --- i18n/extract.py | 6 +----- i18n/segment.py | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/i18n/extract.py b/i18n/extract.py index 209ee3413d..1e9acdc110 100755 --- a/i18n/extract.py +++ b/i18n/extract.py @@ -41,9 +41,6 @@ def main(): create_dir_if_necessary(LOCALE_DIR) source_msgs_dir = CONFIGURATION.source_messages_dir - generated_files = ['django-partial.po', 'djangojs.po', 'mako.po'] - - # Prepare makemessages command. makemessages = "django-admin.py makemessages -l en" ignores = " ".join('--ignore="{}/*"'.format(d) for d in CONFIGURATION.ignore_dirs) if ignores: @@ -70,10 +67,9 @@ def main(): # Segment the generated files. segmented_files = segment_pofiles("en") - generated_files.extend(segmented_files) # Finish each file. - for filename in generated_files: + for filename in segmented_files: LOG.info('Cleaning %s' % filename) po = pofile(source_msgs_dir.joinpath(filename)) # replace default headers with edX headers diff --git a/i18n/segment.py b/i18n/segment.py index 8420694eae..7920f896c4 100755 --- a/i18n/segment.py +++ b/i18n/segment.py @@ -93,13 +93,13 @@ def segment_pofile(filename, segments): else: msg_segments.add(filename) + assert msg_segments if len(msg_segments) == 1: # This message belongs in this segment. segment_file = msg_segments.pop() segment_po_files[segment_file].append(msg) else: - # Either it's in more than one segment, or none, so put it back in - # the main file. + # It's in more than one segment, so put it back in the main file. remaining_po.append(msg) # Write out the results. @@ -113,9 +113,6 @@ def segment_pofile(filename, segments): pofile.save(out_file) files_written.add(out_file) - LOG.info(writing_msg.format(file=filename, num=len(remaining_po))) - remaining_po.save(filename) - return files_written