private void SetLanguageInfo(BasicTriList trilist, I18NUtilityJoinMap joinMap) { if (_languagesConfig == null) { Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "No Language configs loaded."); return; } Debug.Console(1, this, "Setting supported language information"); ushort i = 0; if (_languagesConfig.LanguageDefinitions.Count == 0) { return; } foreach (var lang in _languagesConfig.LanguageDefinitions.Select(language => language.Value)) { Debug.Console(1, this, "Setting supported language information for locale {0}", lang.LocaleName); trilist.SetBool(joinMap.SupportedLanguageEnable.JoinNumber + i, lang.Enable); trilist.SetString(joinMap.SupportedLanguagesStart.JoinNumber + i, lang.LocaleName); trilist.SetString(joinMap.SupportedLanguagesDescriptionStart.JoinNumber + i, lang.FriendlyName); i++; } }
private void SetLanguageStrings(BasicTriList trilist, I18NUtilityJoinMap joinMap) { LanguageDefinition languageDefinition; if (!_languagesConfig.LanguageDefinitions.TryGetValue(_currentLanguageString, out languageDefinition)) { Debug.Console(0, this, Debug.ErrorLogLevel.Warning, "Language definition for selected locale {0} not found", _currentLanguageString); return; } if (languageDefinition.UiLabels != null) { foreach (var label in languageDefinition.UiLabels) { Debug.Console(2, this, "Setting join {0} to {1}", (joinMap.UiLabelsStart.JoinNumber + label.JoinNumber) - 1, label.DisplayText); var stringInputSig = trilist.StringInput[joinMap.UiLabelsStart.JoinNumber + label.JoinNumber - 1]; stringInputSig.StringEncoding = eStringEncoding.eEncodingUTF16; trilist.SetString((joinMap.UiLabelsStart.JoinNumber + label.JoinNumber) - 1, label.DisplayText); } } if (languageDefinition.Sources != null) { foreach (var label in languageDefinition.Sources) { var langLabel = label as LanguageLabel; if (langLabel == null) { continue; } Debug.Console(2, this, "Setting join {0} to {1}", (joinMap.SourceLabelsStart.JoinNumber + langLabel.JoinNumber) - 1, label.DisplayText); var stringInputSig = trilist.StringInput[joinMap.SourceLabelsStart.JoinNumber + langLabel.JoinNumber - 1]; stringInputSig.StringEncoding = eStringEncoding.eEncodingUTF16; trilist.SetString((joinMap.SourceLabelsStart.JoinNumber + langLabel.JoinNumber) - 1, label.DisplayText); } } if (languageDefinition.Destinations == null) { return; } foreach (var label in languageDefinition.Destinations) { var langLabel = label as LanguageLabel; if (langLabel == null) { continue; } Debug.Console(2, this, "Setting join {0} to {1}", (joinMap.DestinationLabelsStart.JoinNumber + langLabel.JoinNumber) - 1, label.DisplayText); var stringInputSig = trilist.StringInput[joinMap.DestinationLabelsStart.JoinNumber + langLabel.JoinNumber - 1]; stringInputSig.StringEncoding = eStringEncoding.eEncodingUTF16; trilist.SetString((joinMap.DestinationLabelsStart.JoinNumber + langLabel.JoinNumber) - 1, label.DisplayText); } }
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge) { var joinMap = new I18NUtilityJoinMap(joinStart); // This adds the join map to the collection on the bridge if (bridge != null) { bridge.AddJoinMap(Key, joinMap); } Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); //Set actions & Feedback for languages trilist.SetUShortSigAction(joinMap.CurrentLanguage.JoinNumber, i => { if (i <= 0) { return; } CurrentLanguageIndex = i; CurrentLanguageString = _languagesConfig.LanguageDefinitions.Keys.ToList()[i - 1]; CurrentLanguage = GetLanguageDefinitionByName(CurrentLanguageString); SetLanguageStrings(trilist, joinMap); }); trilist.SetStringSigAction(joinMap.CurrentLanguage.JoinNumber, s => { if (String.IsNullOrEmpty(s)) { return; } CurrentLanguageString = s; try { CurrentLanguageIndex = _languagesConfig.LanguageDefinitions.Keys.ToList().IndexOf(CurrentLanguageString); } catch (Exception ex) { CurrentLanguageIndex = 0; Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to get index for language {0}\r\n{1}", CurrentLanguageString, ex.Message); } CurrentLanguage = GetLanguageDefinitionByName(CurrentLanguageString); SetLanguageStrings(trilist, joinMap); }); CurrentLanguageFeedback.LinkInputSig(trilist.StringInput[joinMap.CurrentLanguage.JoinNumber]); CurrentLanguageIntFeedback.LinkInputSig(trilist.UShortInput[joinMap.CurrentLanguage.JoinNumber]); SetLanguageInfo(trilist, joinMap); trilist.OnlineStatusChange += (o, a) => { if (!a.DeviceOnLine) { return; } SetLanguageInfo(trilist, joinMap); CurrentLanguageFeedback.FireUpdate(); SetLanguageStrings(trilist, joinMap); }; }