I’m working on an Ignition Edge Perspective project and want to create a dropdown component that lists available translation languages based on what languages are in the Translation Manager.
Ideally, I want this dropdown to be reusable across different Edge projects, each having a different set of languages.
This is the script the Perspective User Management Resource uses:
def transform(self, value, quality, timestamp):
from java.util import Locale
import operator
# Gets list of available locales from the Gateway and creates a dictionary of locales.
list = []
for locale in Locale.getAvailableLocales():
# If the locale has a country associated with the local, append the country name.
if "-" in locale.toLanguageTag():
dict = { "value": locale.toLanguageTag().replace("-", "_"), "label": locale.displayLanguage + " (" + locale.displayCountry + ")" }
else:
dict = { "value": locale.toLanguageTag().replace("-", "_"), "label": locale.displayLanguage }
list.append(dict)
list = sorted(list)
return list[1:]
Is there a way to filter by languages in the Translation Manager?
Preliminary disclaimer: This is subject to change in 8.3, and once you're importing internal Java classes you're on your own if an update ends up breaking functionality, but as a starting point:
You need to obtain a TranslationPackage - this has a defined list of locales associated with it (and a bunch of other introspective methods you may find useful).
To get a TranslationPackage, you need to ask the gateway, which requires you to obtain a GatewayContext instance. Search the forum for how to do so; it's your entrypoint to unsupported behavior so I required folks to do a bare minimum of due diligence before I tell them how to do it now
From the gateway context you'll call the undocumented getLocalizationManager method to get a LocalizationManagerImpl.
That LocalizationManagerImpl has a no-argument loadFullPackage() method that returns your base TranslationPackage.
As an aside, shadowing names like dict and list in your own Python code is a bad idea - can make it hard to read down the line for someone else, and runs the risk of 'leaking' outside a context you expect.