Note
This project is using a deprecated NuGet package with frequent errors, from now on, this repository will be labelled as deprecated
GoogleTranslateLogic is a NetLogic designed to translate missing keys in a localization dictionary of FactoryTalk Optix using the Google Translate API. This class leverages the GTranslate NuGet package to perform translations.
- FactoryTalk Optix
- .NET 8 SDK
- Visual Studio
- NuGet package:
GTranslate(link)
- Open the NetSolution in Visual Studio.
- Install the
GTranslateNuGet package using theNuGet Package Manageror by running the following command in the Package Manager Console:
Install-Package GTranslate- TranslateMissingKeys: This method initiates the translation process by starting a long-running task.
public void TranslateMissingKeys()- TranslateMissingKeysMethod: This method performs the actual translation process. It retrieves the localization dictionary, loads its content, translates the missing keys, and updates the dictionary.
private void TranslateMissingKeysMethod()- GetLocalizationDictionary: This method retrieves the localization dictionary from the Information Model.
private IUAVariable GetLocalizationDictionary()- LoadDictionaryContent: This method loads the content of the localization dictionary.
private string[,] LoadDictionaryContent(IUAVariable localizationDictionary)- TranslateDictionaryContent: This method translates the content of the dictionary using non-empty keys.
private string[,] TranslateDictionaryContent(string[,] dictionaryContent)- TranslateText: This method uses the
GoogleTranslatorclass from theGTranslate.Translatorspackage to translate text.
private static string TranslateText(string textToTranslate, string targetLanguage, string sourceLanguage)- UpdateDictionaryContent: This method updates the localization dictionary with the translated content.
private bool UpdateDictionaryContent(IUAVariable dictionaryToUpdate, string[,] newDictionaryContent)- Ensure that the
LocalizationDictionaryvariable is properly set up in the NetLogic object. - Call the
TranslateMissingKeysmethod to start the translation process.
The class uses the Log object to log information, warnings, and errors throughout the translation process. This helps in monitoring the progress and identifying any issues that may arise.
- The translation process is synchronous to ensure that all translations are completed before updating the dictionary.
- The first row of the dictionary is assumed to contain the language headers.
- The first column of the dictionary is assumed to contain the localization keys.
This project is licensed under the MIT License. See the LICENSE file for details.
Rockwell Automation maintains these repositories as a convenience to you and other users. Although Rockwell Automation reserves the right at any time and for any reason to refuse access to edit or remove content from this Repository, you acknowledge and agree to accept sole responsibility and liability for any Repository content posted, transmitted, downloaded, or used by you. Rockwell Automation has no obligation to monitor or update Repository content
The examples provided are to be used as a reference for building your own application and should not be used in production as-is. It is recommended to adapt the example for the purpose, observing the highest safety standards.