Example #1
0
        /// <summary>
        /// Loads localization data from the specified JSON stream. Loaded strings
        /// will overwrite any previously loaded strings that share the same key.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> from which to load localization data.</param>
        public void LoadFromJsonStream(Stream stream)
        {
            Contract.Require(stream, nameof(stream));

            using (var sreader = new StreamReader(stream))
                using (var jreader = new JsonTextReader(sreader))
                {
                    var serializer  = new JsonSerializer();
                    var description = serializer.Deserialize <LocalizationDatabaseDescription>(jreader);

                    var results = new Dictionary <String, LocalizedString>();

                    foreach (var lstring in description.Strings ?? Enumerable.Empty <LocalizedStringDescription>())
                    {
                        var key = LocalizedString.CreateFromDescription(lstring, results);
                        foreach (var result in results)
                        {
                            if (!strings.ContainsKey(result.Key))
                            {
                                strings[result.Key] = new Dictionary <String, LocalizedString>();
                            }
                            strings[result.Key][key] = result.Value;
                        }
                    }
                }

            InvalidateFallbackCultures();
        }