Skip to content

Commit

Permalink
Merged global resx into BlazingCoffee.Shared
Browse files Browse the repository at this point in the history
  • Loading branch information
EdCharbeneau committed Jul 22, 2020
1 parent 3380bfd commit c6f2945
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 97 deletions.
1 change: 1 addition & 0 deletions BlazingCoffee.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_AutoCreateNewLanguageFiles = False
SolutionGuid = {76189520-AA6D-4932-9B9C-908171584431}
EndGlobalSection
EndGlobal
6 changes: 0 additions & 6 deletions BlazingCoffee/Client/BlazingCoffee.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@
<ProjectReference Include="..\Shared\BlazingCoffee.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Pages\Index.resx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
11 changes: 0 additions & 11 deletions BlazingCoffee/Client/Global.cs

This file was deleted.

24 changes: 11 additions & 13 deletions BlazingCoffee/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
@page "/"
@inject IStringLocalizer<Index> L
@inject IStringLocalizer<Global> G

@inject ITelerikStringLocalizer L
<div class="card-menu">
<Card Title="@L["Sales"]" ImageUrl="./img/Sales.jpg">
<CardContent>
<p>@L["Sales_Card_Title"]</p>
<p>@L["Index_SalesCard_Description"]</p>
</CardContent>
<ActionTemplate>
<span class="k-card-action"><a href="/sales" class="k-button k-flat k-primary">@L["Sales"]</a></span>
</ActionTemplate>
<FooterTemplate>
<span title="@G["Login_Required_ToolTip"]"><TelerikIcon Icon="@IconName.Lock" /></span>
<span title="@L["ToolTip_LoginRequired"]"><TelerikIcon Icon="@IconName.Lock" /></span>
</FooterTemplate>
</Card>
<Card Title="@G["Human_Capital"]" ImageUrl="./img/Schedule.jpg">
<Card Title="@L["HumanCapital"]" ImageUrl="./img/Schedule.jpg">
<CardContent>
<p>@L["HumanCapital_Card_Title"]</p>
<p>@L["Index_SalesCard_Description"]</p>
</CardContent>
<ActionTemplate>
<span class="k-card-action"><a href="/manage-employees" class="k-button k-flat k-primary">@G["Human_Capital"]</a></span>
<span class="k-card-action"><a href="/manage-employees" class="k-button k-flat k-primary">@L["HumanCapital"]</a></span>
</ActionTemplate>
<FooterTemplate>
<span title="@G["Login_Required_ToolTip"]"><TelerikIcon Icon="@IconName.Lock" /></span>
<span title="@L["ToolTip_LoginRequired"]"><TelerikIcon Icon="@IconName.Lock" /></span>
</FooterTemplate>
</Card>
<Card Title="@G["Manage_Products"]" ImageUrl="./img/coffee.jpg">
<Card Title="@L["ManageProducts"]" ImageUrl="./img/coffee.jpg">
<CardContent>
<p>@L["ManageProducts_Card_Title"]</p>
<p>@L["Index_ProductsCard_Description"]</p>
</CardContent>
<ActionTemplate>
<span class="k-card-action"><a href="/manage-products" class="k-button k-flat k-primary">@G["Manage_Products"]</a></span>
<span class="k-card-action"><a href="/manage-products" class="k-button k-flat k-primary">@L["ManageProducts"]</a></span>
</ActionTemplate>
<FooterTemplate>
<span title="@G["Login_Required_ToolTip"]"><TelerikIcon Icon="@IconName.Lock" /></span>
<span title="@L["ToolTip_LoginRequired"]"><TelerikIcon Icon="@IconName.Lock" /></span>
</FooterTemplate>
</Card>
<TelerikTooltip TargetSelector=".k-card-footer>span[title]" Position=@TooltipPosition.Top ShowOn="@TooltipShowEvent.Hover" />
Expand Down
9 changes: 5 additions & 4 deletions BlazingCoffee/Client/Pages/ManageProducts.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@inject HttpClient Http
@inject NavigationManager NavigationManager
@inject IAccessTokenProvider accessTokenProvider
@inject ITelerikStringLocalizer L

<CardContainer Title="Manage Products">
<TelerikGrid Data="Products" Groupable="true" EditMode="GridEditMode.Popup"
Expand Down Expand Up @@ -82,10 +83,10 @@
</EditorTemplate>
</GridColumn>
<GridCommandColumn>
<GridCommandButton Command="Edit" Icon="edit" Class="k-primary">Edit</GridCommandButton>
<GridCommandButton Command="Save" Icon="save" Class="k-primary" ShowInEdit="true">Update</GridCommandButton>
<GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton>
<GridCommandButton Command="Delete" Icon="delete" ShowInEdit="false">Delete</GridCommandButton>
<GridCommandButton Command="Edit" Icon="edit" Class="k-primary">@L["Grid_Edit"]</GridCommandButton>
<GridCommandButton Command="Save" Icon="save" Class="k-primary" ShowInEdit="true">@L["Grid_Update"]</GridCommandButton>
<GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">@L["Grid_Cancel"]</GridCommandButton>
<GridCommandButton Command="Delete" Icon="delete" ShowInEdit="false">@L["Grid_Delete"]</GridCommandButton>
</GridCommandColumn>
</GridColumns>
</TelerikGrid>
Expand Down
49 changes: 25 additions & 24 deletions BlazingCoffee/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using System.Xml.Serialization;
using BlazingCoffee.Services;
using Telerik.Blazor.Services;
using BlazingCoffee.Shared.Localization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.JSInterop;
using System;
using System.Globalization;
using System.Net.Http;
using System.Threading.Tasks;
using Telerik.Blazor.Services;

namespace BlazingCoffee.Client
{
Expand All @@ -23,20 +18,9 @@ public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTelerikBlazor();

builder.Services.AddHttpClient<PublicClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress));
builder.Services.AddHttpClient("BlazingCoffee.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
ConfigureServices(builder);

// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("BlazingCoffee.ServerAPI"));

builder.Services.AddApiAuthorization();
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
// register a custom localizer for the Telerik components, after registering the Telerik services
builder.Services.AddSingleton(typeof(ITelerikStringLocalizer), typeof(TelerikLocalizer));

var host = builder.Build();
var jsInterop = host.Services.GetRequiredService<IJSRuntime>();
var result = await jsInterop.InvokeAsync<string>("blazorCulture.get");
Expand All @@ -49,5 +33,22 @@ public static async Task Main(string[] args)

await host.RunAsync();
}

private static void ConfigureServices(WebAssemblyHostBuilder builder)
{
builder.Services.AddTelerikBlazor();

builder.Services.AddHttpClient<PublicClient>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress));
builder.Services.AddHttpClient("BlazingCoffee.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("BlazingCoffee.ServerAPI"));
builder.Services.AddApiAuthorization();

// register a custom localizer for the Telerik components, after registering the Telerik services
builder.Services.AddSingleton<ITelerikStringLocalizer, TelerikLocalizer>();
builder.Services.AddLocalization();
}
}
}
18 changes: 9 additions & 9 deletions BlazingCoffee/Client/Shared/Layouts/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@namespace BlazingCoffee.Client.Shared
@inherits LayoutComponentBase
@inject NavigationManager navigationManger
@inject IStringLocalizer<Global> G

@using BlazingCoffee.Shared.Resources
@using BlazingCoffee.Client.Shared.NavMenu
@inject NavigationManager navigationManger
@inject ITelerikStringLocalizer L


<TelerikRootComponent>
<TelerikDrawer @bind-Expanded="@Expanded" Width="280px" Data="Data" Mode="DrawerMode.Push" Position="DrawerPosition.Left" MiniMode="true">
Expand Down Expand Up @@ -65,19 +68,16 @@
new List<DrawerItem>
{
new DrawerItem{ Text = "Home", Icon = IconName.ArrowRoot, Url="/", Group = "app"},
new DrawerItem{ Text = G["Sales"], Icon = IconName.Dollar, Url="/sales", Group = "app"},
new DrawerItem{ Text = G["Human_Capital"], Icon = IconName.TellAFriend, Url="/manage-employees", Group = "app"},
new DrawerItem{ Text = G["Manage_Products"], Icon = IconName.Grid, Url="/manage-products", Group = "app"},
new DrawerItem{ Text = L["Sales"], Icon = IconName.Dollar, Url="/sales", Group = "app"},
new DrawerItem{ Text = L["HumanCapital"], Icon = IconName.TellAFriend, Url="/manage-employees", Group = "app"},
new DrawerItem{ Text = L["ManageProducts"], Icon = IconName.Grid, Url="/manage-products", Group = "app"},
new DrawerItem{ Text = "GitHub", Icon = IconName.Share, Url="https://github.com/telerik/blazing-coffee", Group = "ext"},
new DrawerItem{ Text = "Telerik", Icon = IconName.HyperlinkGlobe, Url="https://telerik.com", Group = "ext"},
new DrawerItem{ Text = "Documentation", Icon = IconName.Html, Url="https://docs.telerik.com/blazor-ui/introduction", Group = "ext"},
new DrawerItem{ Text = "Support", Icon = IconName.Question, Url="https://www.telerik.com/account/support-tickets", Group = "ext"}
};
};

string SelectedTheme = "auto";
IEnumerable<string> Themes => new List<string> { "auto" }; // TODO add manual settings, "light", "dark" };
string SelectedLanguage = "en";
IEnumerable<string> Languages => new List<string> { "en" }; // TODO add Globalization
}
19 changes: 10 additions & 9 deletions BlazingCoffee/Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
@using System.Net.Http
@using System.Net.Http.Json
@using System.Collections.ObjectModel
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@using Telerik.DataSource
@using Telerik.Blazor
@using Telerik.Blazor.Components
@using Telerik.Blazor.Services
@using BlazingCoffee.Client
@using BlazingCoffee.Client.Shared
@using BlazingCoffee.Shared
@using BlazingCoffee.Shared.Models
@using Telerik.Blazor.Components
@using Telerik.DataSource
@using Telerik.Blazor
@using System.Collections.ObjectModel
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.Extensions.Localization
@using BlazingCoffee.Shared.Models
12 changes: 11 additions & 1 deletion BlazingCoffee/Shared/BlazingCoffee.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="3.1.6" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.Text.Json" Version="4.7.1" />
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.15.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\TelerikMessages.designer.cs">
<Compile Update="Resources\Global.designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Global.resx</DependentUpon>
</Compile>
<Compile Update="Resources\TelerikMessages.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>TelerikMessages.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Global.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Global.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\TelerikMessages.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>TelerikMessages.Designer.cs</LastGenOutput>
Expand Down
23 changes: 13 additions & 10 deletions BlazingCoffee/Shared/Localization/TelerikLocalizer.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
using BlazingCoffee.Shared.Resources;
using System;
using System.Collections.Generic;
using System.Text;
using Telerik.Blazor.Resources;
using Microsoft.Extensions.Localization;
using Telerik.Blazor.Services;

namespace BlazingCoffee.Shared.Localization
{
public class TelerikLocalizer : ITelerikStringLocalizer
{
public string this[string name]
private readonly IStringLocalizer<Global> globalLocalizer;

public TelerikLocalizer(IStringLocalizer<Global> globalLocalizer)
{
get
{
return GetStringFromResource(name);
}
this.globalLocalizer = globalLocalizer;
}

public string this[string name] => GetStringFromResource(name);

public string GetStringFromResource(string key)
{
return TelerikMessages.ResourceManager.GetString(key, TelerikMessages.Culture);
var localString = TelerikMessages.ResourceManager.GetString(key, TelerikMessages.Culture);
if (string.IsNullOrWhiteSpace(localString))
{
return globalLocalizer.GetString(key);
}
return localString;
}
}
}
Loading

0 comments on commit c6f2945

Please sign in to comment.