예제 #1
0
        private string GetText(string key, out bool notSucceed)
        {
#if NET451
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#elif NET46
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#else
            var culture = CultureInfo.CurrentCulture.ToString();
#endif
            string computedKey = $"{key}.{culture}";

            string result;
            if (_localizations.TryGetValue(computedKey, out result))
            {
                notSucceed = false;
                return(result);
            }
            else
            {
                notSucceed = true;
                if (_createNewRecordWhenLocalisedStringDoesNotExist)
                {
                    _developmentSetup.AddNewLocalizedItem(key, culture, _resourceKey);
                    _localizations.Add(computedKey, computedKey);
                    return(computedKey);
                }
                if (_returnKeyOnlyIfNotFound)
                {
                    return(key);
                }

                return(_resourceKey + "." + computedKey);
            }
        }
        private string GetText(string key, out bool notSucceed)
        {
#if NET451
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#elif NET46
            var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#else
            var culture = CultureInfo.CurrentCulture.ToString();
#endif
            KeyValuePair <string, bool>[] _values = PurifyTranslate(key, culture);
            string _result = "";
            string result;
            int    countNotFound = 0;
            if (_values != null && _values.Length > 0)
            {
                for (int i = 0; i < _values.Length; i++)
                {
                    if (_values[i].Value == true && !string.IsNullOrWhiteSpace(_values[i].Key))
                    {
                        string computedKey = $"{_values[i].Key}.{culture}";
                        if (_localizations.TryGetValue(computedKey, out result))
                        {
                            // notSucceed = false;
                            _result = _result + result;
                        }
                        else
                        {
                            // notSucceed = true;
                            countNotFound++;
                            /// <summary>
                            /// Add non-existed key-value if only in development environment and not to add if default Culture ('En-US')
                            /// </summary>
                            if (_createNewRecordWhenLocalisedStringDoesNotExist && (culture != "en-US"))
                            {
                                _developmentSetup.AddNewLocalizedItem(_values[i].Key, culture, _resourceKey);

#if NET_STANDARD
                                _localizations.Add(computedKey, computedKey);
#elif NET_CORE_11
                                _localizations.Add(computedKey, computedKey);
#else
                                _localizations.TryAdd(computedKey, computedKey);
#endif
                                _result = _result + computedKey;
                            }
                            else if (_returnKeyOnlyIfNotFound)
                            {
                                _result = _result + _values[i].Key;
                            }
                            else
                            {
                                _result = _result + _resourceKey + "." + computedKey;
                            }
                        }
                    }
                    else
                    {
                        _result = _result + _values[i].Key;
                    }
                }
            }
            notSucceed = countNotFound > 0;
            return(_result);
        }