mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	build_emoji: Generate codepoint_to_name.json file.
				
					
				
			Store the `codepoint_to_name` map in a JSON file which can be used by the rest of codebase(zerver) to convert emoji codepoints to canonical names.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							8abbb6d781
						
					
				
				
					commit
					fee4065571
				
			@@ -16,8 +16,8 @@ from typing import Dict, Text, Union
 | 
			
		||||
from os.path import dirname
 | 
			
		||||
from PIL import Image, ImageDraw, ImageFont
 | 
			
		||||
 | 
			
		||||
from emoji_setup_utils import generate_emoji_catalog, emoji_names_for_picker, \
 | 
			
		||||
    EMOJISETS
 | 
			
		||||
from emoji_setup_utils import generate_emoji_catalog, generate_codepoint_to_name_map, \
 | 
			
		||||
    emoji_names_for_picker, EMOJISETS
 | 
			
		||||
 | 
			
		||||
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')
 | 
			
		||||
sys.path.append(ZULIP_PATH)
 | 
			
		||||
@@ -205,6 +205,10 @@ def dump_emojis(cache_path):
 | 
			
		||||
    emoji_data = ujson.load(open(os.path.join(EMOJI_DATA_PATH, 'emoji.json')))
 | 
			
		||||
    emoji_catalog = generate_emoji_catalog(emoji_data)
 | 
			
		||||
 | 
			
		||||
    UNIFIED_REACTIONS_PATH = os.path.join(ZULIP_PATH, 'zerver', 'management', 'data', 'unified_reactions.json')
 | 
			
		||||
    with open(UNIFIED_REACTIONS_PATH) as unified_reactions_file:
 | 
			
		||||
        unified_reactions_data = ujson.load(unified_reactions_file)
 | 
			
		||||
 | 
			
		||||
    os.chdir(EMOJI_DUMP_DIR_PATH)
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
@@ -319,5 +323,12 @@ def dump_emojis(cache_path):
 | 
			
		||||
    name_to_codepoint_file.write(ujson.dumps(emoji_map))
 | 
			
		||||
    name_to_codepoint_file.close()
 | 
			
		||||
 | 
			
		||||
    CODEPOINT_TO_NAME_PATH = os.path.join(cache_path, 'codepoint_to_name.json')
 | 
			
		||||
    codepoint_to_name_file = open(CODEPOINT_TO_NAME_PATH, 'w')
 | 
			
		||||
    codepoint_to_name = generate_codepoint_to_name_map(names, unified_reactions_data)
 | 
			
		||||
 | 
			
		||||
    codepoint_to_name_file.write(ujson.dumps(codepoint_to_name))
 | 
			
		||||
    codepoint_to_name_file.close()
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    main()
 | 
			
		||||
 
 | 
			
		||||
@@ -256,3 +256,14 @@ def emoji_is_universal(emoji_dict):
 | 
			
		||||
        if not emoji_dict['has_img_' + emoji_set]:
 | 
			
		||||
            return False
 | 
			
		||||
    return True
 | 
			
		||||
 | 
			
		||||
def generate_codepoint_to_name_map(names, unified_reactions_data):
 | 
			
		||||
    # type: (List[str], Dict[Text, Text]) -> Dict[str, str]
 | 
			
		||||
    # TODO: Decide canonical names. For now, using the names
 | 
			
		||||
    # generated for emoji picker. In case of multiple names
 | 
			
		||||
    # for the same emoji, lexicographically greater name is
 | 
			
		||||
    # used, for example, `thumbs_up` is used and not `+1`.
 | 
			
		||||
    codepoint_to_name = {}  # type: Dict[str, str]
 | 
			
		||||
    for name in names:
 | 
			
		||||
        codepoint_to_name[str(unified_reactions_data[name])] = str(name)
 | 
			
		||||
    return codepoint_to_name
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user