public void UpdateLocalization()
        {
            var dropdown = GetComponent <Dropdown>();
            var dOptions = dropdown.options;

            if (options != null)
            {
                for (var i = 0; i < options.Count; i++)
                {
                    var option  = options[i];
                    var dOption = default(Dropdown.OptionData);

                    if (dOptions.Count == i)
                    {
                        dOption = new Dropdown.OptionData();

                        dOptions.Add(dOption);
                    }
                    else
                    {
                        dOption = dOptions[i];
                    }

                    var stringTranslation = LeanLocalization.GetTranslation(option.StringTranslationName);

                    // Use translation?
                    if (stringTranslation != null && stringTranslation.Data is string)
                    {
                        dOption.text = LeanTranslation.FormatText((string)stringTranslation.Data, dOption.text, this);
                    }
                    // Use fallback?
                    else
                    {
                        dOption.text = LeanTranslation.FormatText(option.FallbackText, dOption.text, this);
                    }

                    var spriteTranslation = LeanLocalization.GetTranslation(option.StringTranslationName);

                    // Use translation?
                    if (spriteTranslation != null && spriteTranslation.Data is Sprite)
                    {
                        dOption.image = (Sprite)spriteTranslation.Data;
                    }
                    // Use fallback?
                    else
                    {
                        dOption.image = option.FallbackSprite;
                    }
                }
            }
            else
            {
                dOptions.Clear();
            }

            dropdown.options = dOptions;
        }
Exemple #2
0
        // This gets called every time the translation needs updating
        public override void UpdateTranslation(LeanTranslation translation)
        {
            // Get the TextMeshProUGUI component attached to this GameObject
            var text = GetComponent <TextMeshProUGUI>();

            // Use translation?
            if (translation != null && translation.Data is string)
            {
                text.text = LeanTranslation.FormatText((string)translation.Data, text.text, this, gameObject);
            }
            // Use fallback?
            else
            {
                text.text = LeanTranslation.FormatText(FallbackText, text.text, this, gameObject);
            }
        }
        /// <summary>This will return the translated string with the specified name, or the fallback if none is found.</summary>
        public static string GetTranslationText(string name, string fallback = null, bool replaceTokens = true)
        {
            var translation = default(LeanTranslation);

            if (string.IsNullOrEmpty(name) == false && CurrentTranslations.TryGetValue(name, out translation) == true && translation.Data is string)
            {
                fallback = (string)translation.Data;
            }

            if (replaceTokens == true)
            {
                fallback = LeanTranslation.FormatText(fallback);
            }

            return(fallback);
        }
        // This gets called every time the translation needs updating
        public override void UpdateTranslation(LeanTranslation translation)
        {
            // Get the Text component attached to this GameObject
            var text = GetComponent <Text>();

            languageAnchors = GetComponents <LanguageAnchor>();
            // Use translation?
            if (translation != null && translation.Data is string)
            {
                if (LeanLocalization.CurrentLanguage.ToLower().Equals("arabic"))
                {
                    if (languageAnchors.Length > 0)
                    {
                        text.gameObject.transform.position =
                            languageAnchors[0].anchorName == AnchorName.ArabicAnchor ?
                            languageAnchors[0].AnchorObject.transform.position :
                            languageAnchors[1].AnchorObject.transform.position;
                        text.alignment = TextAnchor.UpperRight;
                    }
                    else
                    {
                        text.alignment = TextAnchor.MiddleCenter;
                    }
                }
                else if (LeanLocalization.CurrentLanguage.ToLower().Equals("english"))
                {
                    if (languageAnchors.Length > 0)
                    {
                        text.gameObject.transform.position =
                            languageAnchors[0].anchorName == AnchorName.EnglishAnchor ?
                            languageAnchors[0].AnchorObject.transform.position :
                            languageAnchors[1].AnchorObject.transform.position;
                        text.alignment = TextAnchor.UpperLeft;
                    }
                    else
                    {
                        text.alignment = TextAnchor.MiddleCenter;
                    }
                }
                text.text = LeanTranslation.FormatText((string)translation.Data, text.text, this);
            }
            // Use fallback?
            else
            {
                text.text = LeanTranslation.FormatText(FallbackText, text.text, this);
            }
        }