How translation are managed between a parent and a child project ?
Are translation terms exported with the projet and imported with the project ?
Or translation terms are in gateway internal DB and not relative to projects ?
How translation are managed between a parent and a child project ?
Are translation terms exported with the projet and imported with the project ?
Or translation terms are in gateway internal DB and not relative to projects ?
Translation terms are a gateway-scoped resource. Component level translations are available inside Vision and subject to the same inheritance behavior as individual Vision windows.
Translation terms are only in the gateway internal DB (table TRANSLATIONTERMS and TRANSLATIONSETTINGS) and not relative to project.
So you can't export translation just with project export.
I've write my own script to export/import it in a json file.
"""
https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.1/com/inductiveautomation/ignition/common/i18n/translation/TranslationPackage.html
"""
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.gateway.script import GatewaySystemUtilities
import json
import os
package = IgnitionGateway.get().getLocalizationManager().loadFullPackage()
hashRule = package.getKeyHashRule()
def getAvailableKeys():
keys = package.getAvailableKeys()
for key in keys:
system.perspective.print(key)
def getAvailableLocales():
locals = package.getAvailableLocales()
for local in locals:
system.perspective.print(local)
def getAllTranslations():
dictResults = {}
translations = package.getAllTranslations()
for translation in translations:
locale = unicode(translation.getLocale())
sourceTerm = unicode(translation.getSourceTerm())
translationTerm = unicode(translation.getTranslation())
if locale not in dictResults.keys():
dictResults[locale]={}
dictResults[locale][sourceTerm]=translationTerm
return dictResults
def isCaseInsensitive():
return hashRule.isCaseInsensitive()
def isIgnorePunct():
return hashRule.isIgnorePunct()
def isIgnoreTags():
return hashRule.isIgnoreTags()
def isIgnoreWS():
return hashRule.isIgnoreWS()
def getKeyHashRule():
keyHashRule = {
"caseInsensitive":isCaseInsensitive(),
"ignorePunct":isIgnorePunct(),
"ignoreTags":isIgnoreTags(),
"ignoreWS":isIgnoreWS()
}
return keyHashRule
def exportTranslations(targetPath,fileName="translates.json"):
try:
translates = {}
translates["translations"] = getAllTranslations()
translates["keyHashRule"] = getKeyHashRule()
filePath = os.path.join(targetPath, fileName)
commons.ignition.files.writeJsonFile(filePath, translates, False)
system.perspective.print("Translates exported successfully")
except Exception as e:
system.perspective.print("Translates export failed!\nReason: %s" % str(e))
raise Exception(e)
def importTranslations(sourcePath,fileName="translates.json"):
from com.inductiveautomation.ignition.common.i18n.translation import KeyHashRule
try:
filePath = os.path.join(sourcePath, fileName)
translates = commons.ignition.files.readJsonFile(filePath)
if translates and "translations" in translates.keys() and "keyHashRule" in translates.keys():
for locale,translations in translates["translations"].items():
for term,translation in translations.items():
system.util.modifyTranslation(unicode(term), unicode(translation), unicode(locale))
sourceKeyHashRule = KeyHashRule(translates["keyHashRule"]["caseInsensitive"],
translates["keyHashRule"]["ignoreWS"],
translates["keyHashRule"]["ignorePunct"],
translates["keyHashRule"]["ignoreTags"]
)
targetKeyHashRule = hashRule
if not targetKeyHashRule.equals(sourceKeyHashRule):
system.perspective.print("Target KeyHashRule not coerced please change to &s" % translates["keyHashRule"])
system.perspective.print("Translates imported successfully")
except Exception as e:
system.perspective.print("Translates import failed!\nReason: %s" % str(e))
raise Exception(e)
so for perspective translation terms have no link with project
That is correct. Component level translations for Perspective are something we've considered implementing, but it hasn't yet gone anywhere.