Example #1
0
        /// <summary>
        /// Updates the displayed text using the passed <paramref name="language"/> and locale key.
        /// </summary>
        public void UpdateLocale(SystemLanguage language)
        {
            Assert.IsNotNull(_tmpText);

            // Attempt to set the font first before any locale value in case a specific font is needed.
            TMP_FontAsset fontAsset;

            if (LocaleCache.TryGetFont(language, _fontStyleId, out fontAsset))
            {
                _tmpText.font = fontAsset;
            }

            // Attempt to set the locale key value
            string localeValue;

            if (LocaleCache.TryGetLocaleValue(language, _localeKey, out localeValue))
            {
                // If there are no substitution arguments to pass to the format string, set it directly.
                if (_localeKeyArguments == null || _localeKeyArguments.Length == 0)
                {
                    _tmpText.text = localeValue;
                }
                // Otherwise grab all of the localization values for the string format arguments and then set
                // the value as a format string with the additional arguments.
                else
                {
                    for (var i = 0; i < _localeKeyArguments.Length; i++)
                    {
                        string argKeyValue;
                        if (!LocaleCache.TryGetLocaleValue(_localeKeyArguments[i], out argKeyValue))
                        {
                            Debug.LogFormat(WearableConstants.LOCALE_KEY_ARGUMENT_NOT_FOUND_FORMAT,
                                            _localeKey,
                                            _localeKeyArguments[i]);
                        }

                        _localeKeyValues[i] = argKeyValue;
                    }

                    _tmpText.text = string.Format(localeValue, _localeKeyValues);
                }
            }
            else if (!string.IsNullOrEmpty(_localeKey))
            {
                Debug.LogWarningFormat(this, WearableConstants.LOCALE_KEY_NOT_FOUND_FORMAT, _localeKey, language);
            }
        }
Example #2
0
 /// <summary>
 /// Updates the displayed text using the preferred system language and local locale key.
 /// </summary>
 public void UpdateLocale()
 {
     UpdateLocale(LocaleCache.GetPreferredSystemLanguage());
 }