private async Task SetTranslation(int aPlayerId, string aLanguage)
        {
            var P = await Request_Player_Info(aPlayerId.ToId());

            var data = Configuration.Current.PlayerTranslationSettings.FirstOrDefault(T => T.PlayerId == P.entityId);

            if (data == null)
            {
                Configuration.Current.PlayerTranslationSettings.Add(data = new TranslationSettings()
                {
                    PlayerId   = P.entityId,
                    PlayerName = P.playerName,
                });
            }

            data.SelectedLanguage = aLanguage;
            Configuration.Save();;
            await ShowDialog(aPlayerId, P, "Empyrion Chat Auto Translate", TranslateAPI.Translate("de", aLanguage, "Automatische Übersetzung ist eingestellt auf:") + " " + aLanguage);
        }
        private bool TranslationNeeded(PlayerInfo aSender, TranslationSettings aSenderTranslateInfo, PlayerInfo aReceiver, TranslationSettings aReceiverTranslateInfo, ChatInfo aInfo)
        {
            if (aReceiverTranslateInfo == null && aSenderTranslateInfo == null)
            {
                return(false);                                                                // beide in Serversprache unterwegs
            }
            var SameFactionOrGlobal = aInfo.type == (byte)ChatType.Global || aReceiver.factionId == aSender.factionId;

            if (!SameFactionOrGlobal)
            {
                return(false);                      // Chat nicht für Spieler bestimmt
            }
            if (aReceiverTranslateInfo != null && aSenderTranslateInfo == null)
            {
                return(true);                                                                 // Unterschiedliche Spracheinstellungen
            }
            if (aReceiverTranslateInfo == null && aSenderTranslateInfo != null)
            {
                return(true);                                                                 // Unterschiedliche Spracheinstellungen
            }
            return(aReceiverTranslateInfo.SelectedLanguage != aSenderTranslateInfo.SelectedLanguage);
        }
        private async Task SendTranslateToEveryPlayer(int requestPlayerId, PlayerInfo aSender, ChatInfo aInfo, Dictionary <string, string> Cache, TranslationSettings aSenderTranslateInfo)
        {
            var P = await Request_Player_Info(requestPlayerId.ToId());

            var aReceiverTranslateInfo = Configuration.Current.PlayerTranslationSettings.FirstOrDefault(T => T.PlayerId == P.entityId);

            if (TranslationNeeded(aSender, aSenderTranslateInfo, P, aReceiverTranslateInfo, aInfo))
            {
                new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        var TranslateText = TranslateAPI.Translate(
                            aSenderTranslateInfo == null ? Configuration.Current.DefaultSourceLanguage : aSenderTranslateInfo.SelectedLanguage,
                            aReceiverTranslateInfo == null ? Configuration.Current.ServerMainLanguage : aReceiverTranslateInfo.SelectedLanguage,
                            aInfo.msg, Cache, Configuration.Current.TranslateDelayTime);

                        if (TranslateText != null)
                        {
                            Log($"**HandleEmpyrionChatAutoTranslate SendTranslate {aSenderTranslateInfo?.PlayerName}:{aSenderTranslateInfo?.PlayerId} to {aReceiverTranslateInfo?.PlayerName}:{aReceiverTranslateInfo?.PlayerId} clientId:{P.clientId} -> {aSenderTranslateInfo?.SelectedLanguage}", LogLevel.Debug);
                            Task.Run(() => Request_InGameMessage_SinglePlayer($"[c]{(aInfo.type == (byte)ChatType.Faction ? "[00ff00]" : "[ff00ff]")}{aSender.playerName}[/c]: [c][ffffff]{TranslateText}[/c]".ToIdMsgPrio(P.entityId, MessagePriorityType.Info, Configuration.Current.TranslateDisplayTime)));
                        }
                    }
                    catch (Exception error)
                    {
                        Log($"SendTranslateToEveryPlayer: {error}", LogLevel.Error);
                    }
                })).Start();
            }
        }