Hi ,
I am learning about the best way of language handling in perspective.
Question is , if I have a phrase like “Fresh Water” , is there a way to just create a key for “Fresh” and a key for “Water” and expect the phrase above to be translated , or do I need to create a sparate key for the exact phrase “Fresh Water” ?
thanks
You will need a separate key. As it would not make sense to translate sentences like that as some langagues use different grammar/structures.
If you are interested i actually am busy with translation today aswell, and i made this script to read all the project file ‘text’ attributes and adding them to the translation manager. Im currently busy trying to implement a googletranslate aswell.
Just adjust the pathToProject to you project folder and run the script in a button on your project or something
import os
import json
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.gateway.script import GatewaySystemUtilities
pathToProject = '/Program Files/Inductive Automation/Ignition/data/projects/ProjectName'
path = pathToProject + '/com.inductiveautomation.perspective/views/'
package = IgnitionGateway.get().getLocalizationManager().loadFullPackage()
oldKeys = package.getAvailableKeys()
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(path):
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')