Export all component text used in Ignition

Here is a script i used to automatically add all text values to the translate manager in perspective
By checking the resource files… warning this may take a while xd

	import os
	import json
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.gateway.script import GatewaySystemUtilities
	
	package = IgnitionGateway.get().getLocalizationManager().loadFullPackage()
	oldKeys = package.getAvailableKeys()
	context = IgnitionGateway.get()
	pathToProjectFolder = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/projects'	
	pathToProject = pathToProjectFolder + "/" + system.perspective.getProjectInfo().name + "/com.inductiveautomation.perspective/views/"
	
	def json_extract(obj, key):
	    """Recursively fetch values from nested JSON."""
	    arr = []
	
	    def extract(obj, arr, key):
	        """Recursively search for values of key in JSON tree."""
	        if isinstance(obj, dict):
	            for k, v in obj.items():
	                if isinstance(v, (dict, list)):
	                    extract(v, arr, key)
	                elif k == key:
	                    arr.append(v)
	        elif isinstance(obj, list):
	            for item in obj:
	                extract(item, arr, key)
	        return arr
	
	    values = extract(obj, arr, key)
	    return values

	newKeys = []
	for root, dirs, files in os.walk(pathToProject):
		try:
			for x in json_extract(json.loads(open(root + '/view.json').read()), 'text'):
				if x not in newKeys and x not in oldKeys and x != "":
					newKeys.append(x)
		except:
			pass
	
	for key in newKeys:			
		system.util.modifyTranslation(str(key),str(key),'en')
	

i got one for vision too but the gateway isnt on rn you need it? xd

4 Likes