public Table AddTable <T>(string tableName, ILocalizationStore localizationStore) { var table = TableGenerator.GetTable(typeof(T), tableName, localizationStore); Add(table); return(table); }
public DynamicLanguageProvider( ILocalizationStore store, IOptions <AbpLocalizationOptions> options) { Store = store; Options = options.Value; }
public virtual void Initialize(LocalizationResourceInitializationContext context) { _logger = context.ServiceProvider.GetService <ILogger <DynamicLocalizationResourceContributor> >(); _store = context.ServiceProvider.GetRequiredService <ILocalizationStore>(); _subscriber = context.ServiceProvider.GetRequiredService <ILocalizationSubscriber>(); _subscriber.Subscribe(OnChanged); }
public LocalizationStartupService(IStringLocalizer <LocalizationStartupService> localizer, ILocalizationStore store, IOptionsMonitor <RequestLocalizationOptions> options, ILogger <LocalizationStartupService> logger) { _localizer = localizer; _store = store; _options = options; _logger = logger; _semaphore = new SemaphoreSlim(1); _disposable = _options.OnChange(o => { AddMissingTranslations(CancellationToken.None); }); _translations = ScanAssembliesForTranslations(); }
/// <summary> /// Loads localization data into global dictioanry from directory /// of json files. /// </summary> /// <param name="localizationStore"> /// Instance of <see cref="ILocalizationStore"/>. /// </param> /// <param name="localePath"> /// Path to directory containing localization files. /// File pattern should match following example "foo.de-DE.json". /// </param> public static async Task LoadLocalizationFromDirectoryAsync( this ILocalizationStore localizationStore, string localePath) { JsonSerializer serializer = new JsonSerializer(); CultureInfo[] cultures = CultureInfo.GetCultures( CultureTypes.AllCultures & ~CultureTypes.NeutralCultures); foreach (var filePath in Directory.GetFiles(localePath, "*.json")) { string[] filePathChunks = filePath.Split('.'); if (filePathChunks.Length <= 2) { // Not valid file name continue; } string cultureCode = filePathChunks .ElementAtOrDefault(filePathChunks.Length - 2); CultureInfo culture = cultures .FirstOrDefault(c => c.Name.Equals( cultureCode, StringComparison.OrdinalIgnoreCase)); if (culture == null) { // Not valid culture code continue; } using (StreamReader file = File.OpenText(filePath)) { Dictionary <string, string> keyValuePairs = (Dictionary <string, string>)serializer .Deserialize(file, typeof(Dictionary <string, string>)); await localizationStore .WriteAsync(culture.Name, keyValuePairs); } } }
public ApiStringLocalizer(ILocalizationStore store, IHttpContextAccessor accessor, string scope) { _store = store; _accessor = accessor; _scope = scope; }
public static Table GetTable(Type rowType, String tableName, ILocalizationStore localizationStore) { List <TableColumn> columns = new List <TableColumn>(); List <GroupingLevel> groups = new List <GroupingLevel>(); List <List <GroupByAttribute> > groupByAttributes = new List <List <GroupByAttribute> >(); var loc = GetTableLocalization(rowType, localizationStore); var gas = AttributeHelper.GetCustomAttributes <GroupingLevelAttribute>(rowType, false); foreach (var ga in gas.OrderBy(a => a.Level)) { if (ga.Level != groups.Count) { throw new InvalidOperationException(String.Format("Invalid group level: {0}. Expected: {1}", ga.Level, groups.Count)); } var g = new GroupingLevel { CaptionFormat = ga.CaptionFormat, FooterFormat = ga.FooterFormat, ShowCaption = ga.ShowCaption, ShowFooter = ga.ShowFooter, ShowHeader = ga.ShowHeader }; List <ColLoc> gloc; if (loc != null && loc.TryGetValue("GroupingLevel-" + ga.Level, out gloc)) { foreach (var gl in gloc) { switch (gl.Property) { case "CaptionFormat": g.CaptionFormat = gl.LocalizedText; break; case "FooterFormat": g.FooterFormat = gl.LocalizedText; break; } } } groups.Add(g); groupByAttributes.Add(new List <GroupByAttribute>()); } foreach (var p in rowType.GetProperties()) { var tca = AttributeHelper.GetCustomAttribute <TableColumnAttribute>(p, false); if (tca != null) { var cal = tca.CellAlignment == CellAlignment.Inherit ? CellAlignment.Auto : tca.CellAlignment; var c = new TableColumn { AggregateFunction = tca.AggregateFunction, AggregateWeightDataField = tca.AggregateWeightDataField, CellAlignment = cal, DataField = tca.DataField ?? p.Name, FooterAlignment = tca.FooterAlignment == CellAlignment.Inherit ? cal : tca.FooterAlignment, FooterColSpan = tca.FooterColSpan, FooterFormat = tca.FooterFormat ?? tca.Format, FooterText = tca.FooterText, FooterType = tca.FooterType, Format = tca.Format, HeaderAlignment = tca.HeaderAlignment == CellAlignment.Inherit ? cal : tca.HeaderAlignment, HeaderText = tca.HeaderText ?? p.Name, ColumnType = tca.IsRowFooter ? TableColumnType.FooterColumn : tca.IsRowHeader ? TableColumnType.HeaderColumn : TableColumnType.Normal, LookupDisplayField = tca.LookupDisplayField, LookupField = tca.LookupField, LookupTable = tca.LookupTable, SortDirection = tca.SortDirection, SortIndex = tca.SortIndex, CellDisplayMode = tca.CellDisplayMode }; List <ColLoc> colLoc; if (loc != null && loc.TryGetValue(c.DataField, out colLoc)) { foreach (var cl in colLoc) { switch (cl.Property) { case "HeaderText": c.HeaderText = cl.LocalizedText; break; case "Format": c.Format = cl.LocalizedText; break; case "FooterText": c.FooterText = cl.LocalizedText; break; case "FooterFormat": c.FooterFormat = cl.LocalizedText; break; } } } columns.Add(c); } var gcas = AttributeHelper.GetCustomAttributes <GroupByAttribute>(p, false); foreach (var gca in gcas) { if (gca.Level < 0 || gca.Level >= groups.Count) { throw new InvalidOperationException(String.Format("Invalid GroupBy level on column '{0}'.", p.Name)); } gca.DataField = gca.DataField ?? p.Name; groupByAttributes[gca.Level].Add(gca); } } for (var level = 0; level < groups.Count; level++) { groups[level].GroupByColumns.AddRange(groupByAttributes[level].OrderBy(a => a.FieldOrder).Select(gca => new GroupByColumn { DataField = gca.DataField, SortDirection = gca.SortDirection })); } if (groups.Count == 0) { groups.Add(new GroupingLevel { ShowHeader = true }); } return(new Table { DataTable = tableName, Columns = columns.ToArray(), Groups = groups.ToArray() }); }
static Dictionary <String, List <ColLoc> > GetTableLocalization(Type rowType, ILocalizationStore localizationStore) { var fields = localizationStore == null ? null : localizationStore.GetTypeLocalizationData(rowType); Dictionary <String, List <ColLoc> > loc = null; if (fields != null) { loc = new Dictionary <string, List <ColLoc> >(); foreach (var field in fields) { var parts = field.FieldName.Split(':'); if (parts.Length == 2) { List <ColLoc> props; if (!loc.TryGetValue(parts[0], out props)) { loc[parts[0]] = props = new List <ColLoc>(); } props.Add(new ColLoc { Property = parts[1], LocalizedText = field.LocalizedText }); } } } return(loc); }
public ApiStringLocalizerFactory(ILocalizationStore store, IHttpContextAccessor accessor) { _store = store; _accessor = accessor; }
public LocalizationProvider(ILocalizationStore store, ILocaleResolver localeResolver) { _store = store; _localeResolver = localeResolver; }
public LocalizationController(ILocalizationStore store, IOptionsSnapshot <RequestLocalizationOptions> options) { _store = store; _options = options; }
public static Table GetTable(Type rowType, String tableName, ILocalizationStore localizationStore) { List<TableColumn> columns = new List<TableColumn>(); List<GroupingLevel> groups = new List<GroupingLevel>(); List<List<GroupByAttribute>> groupByAttributes = new List<List<GroupByAttribute>>(); var loc = GetTableLocalization(rowType, localizationStore); var gas = AttributeHelper.GetCustomAttributes<GroupingLevelAttribute>(rowType, false); foreach (var ga in gas.OrderBy(a => a.Level)) { if (ga.Level != groups.Count) throw new InvalidOperationException(String.Format("Invalid group level: {0}. Expected: {1}", ga.Level, groups.Count)); var g = new GroupingLevel { CaptionFormat = ga.CaptionFormat, FooterFormat = ga.FooterFormat, ShowCaption = ga.ShowCaption, ShowFooter = ga.ShowFooter, ShowHeader = ga.ShowHeader }; List<ColLoc> gloc; if (loc != null && loc.TryGetValue("GroupingLevel-" + ga.Level, out gloc)) { foreach (var gl in gloc) { switch (gl.Property) { case "CaptionFormat": g.CaptionFormat = gl.LocalizedText; break; case "FooterFormat": g.FooterFormat = gl.LocalizedText; break; } } } groups.Add(g); groupByAttributes.Add(new List<GroupByAttribute>()); } foreach (var p in rowType.GetProperties()) { var tca = AttributeHelper.GetCustomAttribute<TableColumnAttribute>(p, false); if (tca != null) { var cal = tca.CellAlignment == CellAlignment.Inherit ? CellAlignment.Auto : tca.CellAlignment; var c = new TableColumn { AggregateFunction = tca.AggregateFunction, AggregateWeightDataField = tca.AggregateWeightDataField, CellAlignment = cal, DataField = tca.DataField ?? p.Name, FooterAlignment = tca.FooterAlignment == CellAlignment.Inherit ? cal : tca.FooterAlignment, FooterColSpan = tca.FooterColSpan, FooterFormat = tca.FooterFormat ?? tca.Format, FooterText = tca.FooterText, FooterType = tca.FooterType, Format = tca.Format, HeaderAlignment = tca.HeaderAlignment == CellAlignment.Inherit ? cal : tca.HeaderAlignment, HeaderText = tca.HeaderText ?? p.Name, ColumnType = tca.IsRowFooter ? TableColumnType.FooterColumn : tca.IsRowHeader ? TableColumnType.HeaderColumn : TableColumnType.Normal, LookupDisplayField = tca.LookupDisplayField, LookupField = tca.LookupField, LookupTable = tca.LookupTable, SortDirection = tca.SortDirection, SortIndex = tca.SortIndex, CellDisplayMode = tca.CellDisplayMode }; List<ColLoc> colLoc; if (loc != null && loc.TryGetValue(c.DataField, out colLoc)) foreach (var cl in colLoc) { switch (cl.Property) { case "HeaderText": c.HeaderText = cl.LocalizedText; break; case "Format": c.Format = cl.LocalizedText; break; case "FooterText": c.FooterText = cl.LocalizedText; break; case "FooterFormat": c.FooterFormat = cl.LocalizedText; break; } } columns.Add(c); } var gcas = AttributeHelper.GetCustomAttributes<GroupByAttribute>(p, false); foreach (var gca in gcas) { if (gca.Level < 0 || gca.Level >= groups.Count) throw new InvalidOperationException(String.Format("Invalid GroupBy level on column '{0}'.", p.Name)); gca.DataField = gca.DataField ?? p.Name; groupByAttributes[gca.Level].Add(gca); } } for (var level = 0; level < groups.Count; level++) groups[level].GroupByColumns.AddRange(groupByAttributes[level].OrderBy(a => a.FieldOrder).Select(gca => new GroupByColumn { DataField = gca.DataField, SortDirection = gca.SortDirection })); if (groups.Count == 0) groups.Add(new GroupingLevel { ShowHeader = true }); return new Table { DataTable = tableName, Columns = columns.ToArray(), Groups = groups.ToArray() }; }
static Dictionary<String, List<ColLoc>> GetTableLocalization(Type rowType, ILocalizationStore localizationStore) { var fields = localizationStore == null ? null : localizationStore.GetTypeLocalizationData(rowType); Dictionary<String, List<ColLoc>> loc = null; if (fields != null) { loc = new Dictionary<string, List<ColLoc>>(); foreach (var field in fields) if (!String.IsNullOrEmpty(field.LocalizedText)) { var parts = field.FieldName.Split(':'); if (parts.Length == 2) { List<ColLoc> props; if (!loc.TryGetValue(parts[0], out props)) loc[parts[0]] = props = new List<ColLoc>(); props.Add(new ColLoc { Property = parts[1], LocalizedText = field.LocalizedText }); } } } return loc; }