We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, can you fix/add WithCulture and GetAllStrings
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using Microsoft.Extensions.Localization;
namespace Localization.SqlLocalizer.DbStringLocalizer { public class SqlStringLocalizer : IStringLocalizer {
private readonly Dictionary<string, string> _localizations; private readonly DevelopmentSetup _developmentSetup; private readonly string _resourceKey; private bool _returnKeyOnlyIfNotFound; private bool _createNewRecordWhenLocalisedStringDoesNotExist; private CultureInfo _currentCulture; public SqlStringLocalizer(Dictionary<string, string> localizations, DevelopmentSetup developmentSetup, string resourceKey, bool returnKeyOnlyIfNotFound, bool createNewRecordWhenLocalisedStringDoesNotExist, CultureInfo culture = null) { _localizations = localizations; _developmentSetup = developmentSetup; _resourceKey = resourceKey; _returnKeyOnlyIfNotFound = returnKeyOnlyIfNotFound; _createNewRecordWhenLocalisedStringDoesNotExist = createNewRecordWhenLocalisedStringDoesNotExist; _currentCulture = culture; } public LocalizedString this[string name] { get { bool notSucceed; var text = GetText(name, out notSucceed); return new LocalizedString(name, text,notSucceed); } } public LocalizedString this[string name, params object[] arguments] { get { return this[name]; } } public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures) { return _localizations.Select(x => new LocalizedString(x.Key, x.Value)); } public IStringLocalizer WithCulture(CultureInfo culture) { return new SqlStringLocalizer(_localizations, _developmentSetup, _resourceKey, _returnKeyOnlyIfNotFound, _createNewRecordWhenLocalisedStringDoesNotExist, culture); } private string GetText(string key,out bool notSucceed) {
#if NET451 var _culture = _currentCulture ?? System.Threading.Thread.CurrentThread.CurrentCulture; //var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString(); #elif NET46 var _culture = _currentCulture ?? System.Threading.Thread.CurrentThread.CurrentCulture; //var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString(); #else var _culture = _currentCulture ?? CultureInfo.CurrentCulture; //CultureInfo.CurrentCulture.ToString(); #endif
string culture = _culture.ToString(); 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; } } }
}
The text was updated successfully, but these errors were encountered:
could you fix this thanks
Sorry, something went wrong.
No branches or pull requests
Hi,
can you fix/add WithCulture and GetAllStrings
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.Extensions.Localization;
namespace Localization.SqlLocalizer.DbStringLocalizer
{
public class SqlStringLocalizer : IStringLocalizer
{
#if NET451
var _culture = _currentCulture ?? System.Threading.Thread.CurrentThread.CurrentCulture; //var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#elif NET46
var _culture = _currentCulture ?? System.Threading.Thread.CurrentThread.CurrentCulture; //var culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
#else
var _culture = _currentCulture ?? CultureInfo.CurrentCulture; //CultureInfo.CurrentCulture.ToString();
#endif
}
The text was updated successfully, but these errors were encountered: