From 2a52b0c1e8fdd7570c8fcb97a3a28cf537e8448f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 1 Jun 2018 16:32:56 -0700 Subject: [PATCH] compilemessages: Use json.dump with sort_keys option. This should help make these files stable over time. Mostly useful for diffing release tarballs. --- zerver/management/commands/compilemessages.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zerver/management/commands/compilemessages.py b/zerver/management/commands/compilemessages.py index c2da7dd4b6..f4e19df2d4 100644 --- a/zerver/management/commands/compilemessages.py +++ b/zerver/management/commands/compilemessages.py @@ -1,11 +1,12 @@ +import json import os +import polib import re +import ujson from subprocess import CalledProcessError, check_output from typing import Any, Dict, List -import polib -import ujson from django.conf import settings from django.conf.locale import LANG_INFO from django.core.management.base import CommandParser @@ -55,7 +56,7 @@ class Command(compilemessages.Command): lang_list.sort(key=lambda lang: lang['name']) with open(output_path, 'w') as output_file: - ujson.dump({'name_map': lang_list}, output_file, indent=4) + ujson.dump({'name_map': lang_list}, output_file, indent=4, sort_keys=True) output_file.write('\n') def get_po_filename(self, locale_path: str, locale: str) -> str: @@ -140,7 +141,7 @@ class Command(compilemessages.Command): data['languages'].append(info) with open(output_path, 'w') as writer: - ujson.dump(data, writer, indent=2) + json.dump(data, writer, indent=2, sort_keys=True) writer.write('\n') def get_translation_percentage(self, locale_path: str, locale: str) -> int: