Skip to content
New issue

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

Pr 33 chat page localization #34

Merged
merged 7 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ yarn-error.log*
*.userrules

# Build results
./dist
dist

#Azurite files
__azurite_db_*
78 changes: 78 additions & 0 deletions ChatGptBlazorApp/ChatGptBlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,82 @@
<PackageReference Include="System.IO.Abstractions" Version="19.2.29"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Resource.fi-Fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.fi-Fi.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Shared\MainLayout.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>MainLayout.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\en\Resource.en-US.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.en-US.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Shared\MainLayout.fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>MainLayout.fi.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Pages\Chat.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Chat.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Pages\Chat.fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Chat.fi.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Components\ChatSessionsList.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ChatSessionsList.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Components\ChatSessionsList.fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ChatSessionsList.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Pages\UserProfile.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>UserProfile.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Pages\UserProfile.fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>UserProfile.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Components\CultureSelector.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CultureSelector.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Components\CultureSelector.fi.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CultureSelector.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Resource.fi-Fi.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.fi-Fi.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Shared\MainLayout.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MainLayout.resx</DependentUpon>
</Compile>
<Compile Update="Resources\en\Resource.en-US.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.en-US.resx</DependentUpon>
</Compile>
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions ChatGptBlazorApp/Components/ChatSessionsList.fi.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="NewChat" xml:space="preserve">
<value>Uusi keskustelu</value>
</data>
</root>
3 changes: 2 additions & 1 deletion ChatGptBlazorApp/Components/ChatSessionsList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
@inject IChatSessionRepository ChatSessionRepository
@inject NavigationManager NavigationManager
@inject IToastService ToastService
@inject IStringLocalizer<ChatSessionsList> Loc

<div class="sidebar">
<div class="nav-scrollable">
<div class="nav-item mb-2">
<button class="btn btn-primary" @onclick="NavigateToNewChat">New chat</button>
<button class="btn btn-primary" @onclick="NavigateToNewChat">@Loc["NewChat"]</button>
</div>
@{
var topicsGroupedByDate = SessionTopics.GroupBy(x => x.Created.Date);
Expand Down
30 changes: 30 additions & 0 deletions ChatGptBlazorApp/Components/ChatSessionsList.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="NewChat" xml:space="preserve">
<value>New chat</value>
</data>
</root>
30 changes: 30 additions & 0 deletions ChatGptBlazorApp/Components/CultureSelector.fi.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="lblLanguage" xml:space="preserve">
<value>Valitse kieli</value>
</data>
</root>
51 changes: 51 additions & 0 deletions ChatGptBlazorApp/Components/CultureSelector.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@using System.Globalization
@inject NavigationManager Navigation
@inject IStringLocalizer<CultureSelector> Loc

<p>
<label>
@Loc["lblLanguage"]
<select @bind="Culture">
@foreach (var culture in supportedCultures)
{
<option value="@culture">@culture.DisplayName</option>
}
</select>
</label>
</p>

@code
{
[Parameter]
public string Id { get; set; }

private CultureInfo[] supportedCultures =
{
new CultureInfo("en-US"),
new CultureInfo("fi-FI")
};

protected override void OnInitialized()
{
Culture = CultureInfo.CurrentCulture;
}

private CultureInfo Culture
{
get => CultureInfo.CurrentCulture;
set
{
if (CultureInfo.CurrentCulture != value)
{
var uri = new Uri(Navigation.Uri)
.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
var cultureEscaped = Uri.EscapeDataString(value.Name);
var uriEscaped = Uri.EscapeDataString(uri);

Navigation.NavigateTo(
$"Culture/Set?culture={cultureEscaped}&redirectUri={uriEscaped}",
true);
}
}
}
}
30 changes: 30 additions & 0 deletions ChatGptBlazorApp/Components/CultureSelector.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="lblLanguage" xml:space="preserve">
<value>Choose locale</value>
</data>
</root>
19 changes: 19 additions & 0 deletions ChatGptBlazorApp/Controllers/CultureController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;

namespace ChatGptBlazorApp.Controllers;

[Route("[controller]/[action]")]
public class CultureController : Controller
{
public IActionResult Set(string culture, string redirectUri)
{
if (culture != null)
HttpContext.Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(
new RequestCulture(culture, culture)));

return LocalRedirect(redirectUri);
}
}
37 changes: 37 additions & 0 deletions ChatGptBlazorApp/Pages/Chat.fi.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<data name="NewTopic" xml:space="preserve">
<value>Uusi aihe</value>
</data>
<data name="TextBoxPlaceHolder" xml:space="preserve">
<value>Kirjoita uusi viesti avustajalle</value>
</data>
<data name="Send" xml:space="preserve">
<value>Lähetä</value>
</data>

</root>
8 changes: 4 additions & 4 deletions ChatGptBlazorApp/Pages/Chat.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IUserRepository UserRepository
@inject IChatSessionRepository ChatSessionRepository
@inject IStringLocalizer<Chat> Loc


<div class="row">
Expand Down Expand Up @@ -67,12 +68,11 @@

<form onsubmit="@Send">
<div class="mb-3">
<label for="chatInput" class="form-label">User prompt:</label>
<textarea class="form-control" id="chatInput" placeholder="write a message to your assistant" @bind="_currentPrompt"></textarea>
<textarea class="form-control" id="chatInput" placeholder="@Loc["TextBoxPlaceHolder"]" @bind="_currentPrompt"></textarea>
</div>

<div class="col-md-2">
<button type="submit" class="form-control mt-2 btn btn-primary">Send</button>
<button type="submit" class="form-control mt-2 btn btn-primary">@Loc["Send"]</button>
</div>
</form>
@if (_waitingForResponse)
Expand Down Expand Up @@ -295,7 +295,7 @@
UserId = userId,
Entries = new List<ChatEntry>(),
Created = DateTime.Now,
Topic = "New topic",
Topic = Loc["NewTopic"],
Tags = new List<string>()
};

Expand Down
Loading
Loading