Exemplo n.º 1
0
        public string Retrieve(LocalizationKey key, Func <string> missing)
        {
            var text = initialRead(key);

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

            return(text);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 public void Append(LocalizationKey key, string value)
 {
     _lock.Write(() =>
     {
         if (_data.ContainsKey(key))
         {
             _data[key] = value;
         }
         else
         {
             _data.Add(key, value);
         }
     });
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 private string initialRead(LocalizationKey key)
 {
     return(_lock.Read(() => !_data.ContainsKey(key) ? null : _data[key]));
 }