Beispiel #1
0
        public string GetHeader(PropertyToken property)
        {
            LocalizationKey localizationKey = property.ToLocalizationKey();

            return(_localeCache
                   .Retrieve(localizationKey, () => _missingHandler.FindMissingProperty(property, _localeCache.Culture)));
        }
Beispiel #2
0
        public string GetTextForKey(StringToken key)
        {
            LocalizationKey localizationKey = key.ToLocalizationKey();

            return(_localeCache
                   .Retrieve(localizationKey, () => _missingHandler.FindMissingText(key, _localeCache.Culture)));
        }
        public bool Equals(LocalizationKey other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            return string.Equals(_key1, other._key1, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(_key2, other._key2, StringComparison.OrdinalIgnoreCase);
        }
Beispiel #4
0
        public string Retrieve(LocalizationKey key, Func <string> missing)
        {
            var text = initialRead(key);

            if (text == null)
            {
                text = missing();
                Append(key, text);
            }

            return(text);
        }
        public string Retrieve(LocalizationKey key, Func<string> missing)
        {
            var text = initialRead(key);

            if (text == null)
            {
                text = missing();
                Append(key, text);
            }

            return text;
        }
Beispiel #6
0
 private string initialRead(LocalizationKey key)
 {
     _lock.EnterReadLock();
     try
     {
         return(!_data.ContainsKey(key) ? null : _data[key]);
     }
     finally
     {
         _lock.ExitReadLock();
     }
 }
Beispiel #7
0
 public void Append(LocalizationKey key, string value)
 {
     _lock.Write(() =>
     {
         if (_data.ContainsKey(key))
         {
             _data[key] = value;
         }
         else
         {
             _data.Add(key, value);
         }
     });
 }
 public void Append(LocalizationKey key, string value)
 {
     _lock.Write(() =>
     {
         if (_data.ContainsKey(key))
         {
             _data[key] = value;
         }
         else
         {
             _data.Add(key, value);
         }
     });
 }
Beispiel #9
0
        public bool Equals(LocalizationKey other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(string.Equals(_key1, other._key1, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(_key2, other._key2, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #10
0
        public ThreadSafeLocaleCache(CultureInfo culture, IEnumerable <LocalString> strings)
        {
            _data = new Dictionary <LocalizationKey, string>();
            strings.Each(s =>
            {
                var localizationKey = new LocalizationKey(s.value);
                if (_data.ContainsKey(localizationKey))
                {
                    throw new ArgumentException("Could not add localization key '{0}' to the cache as it already exists.".ToFormat(s.value));
                }

                _data.Add(localizationKey, s.display);
            });

            _culture = culture;
        }
        public ThreadSafeLocaleCache(CultureInfo culture, IEnumerable<LocalString> strings)
        {
            _data = new Dictionary<LocalizationKey, string>();
            strings.Each(s =>
            {
                var localizationKey = new LocalizationKey(s.value);
                if (_data.ContainsKey(localizationKey))
                {
                    throw new ArgumentException("Could not add localization key '{0}' to the cache as it already exists.".ToFormat(s.value));
                }

                _data.Add(localizationKey, s.display);
            });

            _culture = culture;
        }
Beispiel #12
0
 public void Append(LocalizationKey key, string value)
 {
     _lock.EnterWriteLock();
     try
     {
         if (_data.ContainsKey(key))
         {
             _data[key] = value;
         }
         else
         {
             _data.Add(key, value);
         }
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
Beispiel #13
0
 private string initialRead(LocalizationKey key)
 {
     return(_lock.Read(() => !_data.ContainsKey(key) ? null : _data[key]));
 }
 private string initialRead(LocalizationKey key)
 {
     return _lock.Read(() => !_data.ContainsKey(key) ? null : _data[key]);
 }