public IReadOnlyList <LocalizedString> GetAllStrings(long?tenantId) { //Get cache var cache = _cacheManager.GetMultiTenantLocalizationDictionaryCache(); //Create a temp dictionary to build (by underlying dictionary) var dictionary = new Dictionary <string, LocalizedString>(); foreach (var localizedString in _internalDictionary.GetAllStrings()) { dictionary[localizedString.Name] = localizedString; } //Override by host if (tenantId != null) { var defaultDictionary = cache.Get(CalculateCacheKey(null), () => GetAllValuesFromDatabase(null)); foreach (var keyValue in defaultDictionary) { dictionary[keyValue.Key] = new LocalizedString(keyValue.Key, keyValue.Value, CultureInfo); } } //Override by tenant var tenantDictionary = cache.Get(CalculateCacheKey(tenantId), () => GetAllValuesFromDatabase(tenantId)); foreach (var keyValue in tenantDictionary) { dictionary[keyValue.Key] = new LocalizedString(keyValue.Key, keyValue.Value, CultureInfo); } return(dictionary.Values.ToImmutableList()); }
/// <inheritdoc/> public IReadOnlyList <LocalizedString> GetAllStrings(CultureInfo culture, bool includeDefaults = true) { // TODO: Can be optimized (example: if it's already default dictionary, skip overriding) IDictionary <string, ILocalizationDictionary> dictionaries = DictionaryProvider.Dictionaries; //Create a temp dictionary to build var allStrings = new Dictionary <string, LocalizedString>(); if (includeDefaults) { //Fill all strings from default dictionary ILocalizationDictionary defaultDictionary = DictionaryProvider.DefaultDictionary; if (defaultDictionary != null) { foreach (LocalizedString defaultDictString in defaultDictionary.GetAllStrings()) { allStrings[defaultDictString.Name] = defaultDictString; } } //Overwrite all strings from the language based on country culture if (culture.Name.Contains("-")) { if (dictionaries.TryGetValue(GetBaseCultureName(culture.Name), out ILocalizationDictionary langDictionary)) { foreach (var langString in langDictionary.GetAllStrings()) { allStrings[langString.Name] = langString; } } } } //Overwrite all strings from the original dictionary if (!dictionaries.TryGetValue(culture.Name, out ILocalizationDictionary originalDictionary)) { return(allStrings.Values.ToImmutableList()); } foreach (LocalizedString originalLangString in originalDictionary.GetAllStrings()) { allStrings[originalLangString.Name] = originalLangString; } return(allStrings.Values.ToImmutableList()); }
public void Extend(ILocalizationDictionary dictionary) { //Add if (!Dictionaries.TryGetValue(dictionary.CultureInfo.Name, out ILocalizationDictionary existingDictionary)) { Dictionaries[dictionary.CultureInfo.Name] = dictionary; return; } //Override IReadOnlyList <LocalizedString> localizedStrings = dictionary.GetAllStrings(); foreach (LocalizedString localizedString in localizedStrings) { existingDictionary[localizedString.Name] = localizedString.Value; } }
/// <summary> /// Extends the source with given dictionary. /// </summary> /// <param name="dictionary">Dictionary to extend the source</param> public void Extend(ILocalizationDictionary dictionary) { //Add ILocalizationDictionary existingDictionary; if (!_dictionaries.TryGetValue(dictionary.CultureInfo.Name, out existingDictionary)) { _dictionaries[dictionary.CultureInfo.Name] = dictionary; return; } //Override var localizedStrings = dictionary.GetAllStrings(); foreach (var localizedString in localizedStrings) { existingDictionary[localizedString.Name] = localizedString.Value; } }
public virtual void Extend(ILocalizationDictionary dictionary) { //Add ILocalizationDictionary existingDictionary; if (!_internalProvider.Dictionaries.TryGetValue(dictionary.CultureInfo.Name, out existingDictionary)) { _internalProvider.Dictionaries[dictionary.CultureInfo.Name] = dictionary; return; } //Override var localizedStrings = dictionary.GetAllStrings(); foreach (var localizedString in localizedStrings) { existingDictionary[localizedString.Name] = localizedString.Value; } }
/// <inheritdoc/> public IReadOnlyList <LocalizedString> GetAllStrings(CultureInfo culture) { if (_defaultDictionary == null) { throw new AbpException("No default dictionary is defined!"); } //Create a temp dictionary to build var dict = new Dictionary <string, LocalizedString>(); //Fill all strings from default dictionary foreach (var defaultDictString in _defaultDictionary.GetAllStrings()) { dict[defaultDictString.Name] = defaultDictString; } //Overwrite all strings from the language based on country culture if (culture.Name.Length == 5) { ILocalizationDictionary langDictionary; if (_dictionaries.TryGetValue(culture.Name.Substring(0, 2), out langDictionary)) { foreach (var langString in langDictionary.GetAllStrings()) { dict[langString.Name] = langString; } } } //Overwrite all strings from the original dictionary ILocalizationDictionary originalDictionary; if (_dictionaries.TryGetValue(culture.Name, out originalDictionary)) { foreach (var originalLangString in originalDictionary.GetAllStrings()) { dict[originalLangString.Name] = originalLangString; } } return(dict.Values.ToImmutableList()); }
public IEnumerable <LocalizedString> GetAllStrings(bool includeParentCultures) { return(_localizationDictionary.GetAllStrings()); }