Beispiel #1
0
        public string GetFormattedTranslation(TranslationData translationData)
        {
            string translation = GetTranslation(translationData);

            if (translationData.Args == null || translationData.Args.Length == 0)
            {
                return(translation);
            }

            object[] data = new object[translationData.Args.Length];

            for (int i = 0; i < translationData.Args.Length; i++)
            {
                if (translationData.Args[i] is TranslationData nestedTranslationData)
                {
                    data[i] = GetFormattedTranslation(nestedTranslationData);
                }
                else
                {
                    data[i] = translationData.Args[i];
                }
            }

            return(string.Format(translation, data));
        }
Beispiel #2
0
        private string GetRawTranslation(TranslationData translationData)
        {
            if (translationData.Key.Length == 0)
            {
                return(string.Empty);
            }

            return(_langDict.GetValueOrDefault(translationData.Key));
        }
Beispiel #3
0
        private string GetTranslation(TranslationData translationData)
        {
            string translation = GetRawTranslation(translationData);

            if (translation != null)
            {
                return(translation);
            }

            if (Settings.SettingsManager.Instance.General.ReturnMissingKeys)
            {
                return($"[MISSING: Translation of '{translationData.Key}' not found]");
            }

            if (TTTLanguage.Languages.TryGetValue(TTTLanguage.FALLBACK_LANGUAGE, out Language fallbackLanguage) && fallbackLanguage != this)
            {
                return(fallbackLanguage.GetTranslation(translationData));
            }

            return(translationData.Key);
        }