diff --git a/PoyoLang.Test/Program.cs b/PoyoLang.Test/Program.cs index c041419..68c9f1a 100644 --- a/PoyoLang.Test/Program.cs +++ b/PoyoLang.Test/Program.cs @@ -22,4 +22,4 @@ Console.WriteLine(); var original = translator.TranslateFromPoyo(translated); Console.WriteLine("Translated back from Poyo:"); -Console.WriteLine(original); \ No newline at end of file +Console.WriteLine(original); diff --git a/PoyoLang.Translator.Web/Components/App.razor b/PoyoLang.Translator.Web/Components/App.razor new file mode 100644 index 0000000..1b1df12 --- /dev/null +++ b/PoyoLang.Translator.Web/Components/App.razor @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/Layout/MainLayout.razor b/PoyoLang.Translator.Web/Components/Layout/MainLayout.razor new file mode 100644 index 0000000..75d05d3 --- /dev/null +++ b/PoyoLang.Translator.Web/Components/Layout/MainLayout.razor @@ -0,0 +1,101 @@ +@inherits LayoutComponentBase + + + + + + + + PoyoLang + + + + + + + @Body + + + + + +
+ An unhandled error has occurred. + Reload + 🗙 +
+ +@code { + private bool _drawerOpen = true; + private bool _isDarkMode = true; + private MudTheme? _theme = null; + + protected override void OnInitialized() + { + base.OnInitialized(); + + _theme = new() + { + PaletteLight = _lightPalette, + PaletteDark = _darkPalette, + LayoutProperties = new LayoutProperties() + }; + } + + private void DrawerToggle() + { + _drawerOpen = !_drawerOpen; + } + + private void DarkModeToggle() + { + _isDarkMode = !_isDarkMode; + } + + private readonly PaletteLight _lightPalette = new() + { + Black = "#110e2d", + AppbarText = "#424242", + AppbarBackground = "rgba(255,255,255,0.8)", + DrawerBackground = "#ffffff", + GrayLight = "#e8e8e8", + GrayLighter = "#f9f9f9", + }; + + private readonly PaletteDark _darkPalette = new() + { + Primary = "#7e6fff", + Surface = "#1e1e2d", + Background = "#1a1a27", + BackgroundGray = "#151521", + AppbarText = "#92929f", + AppbarBackground = "rgba(26,26,39,0.8)", + DrawerBackground = "#1a1a27", + ActionDefault = "#74718e", + ActionDisabled = "#9999994d", + ActionDisabledBackground = "#605f6d4d", + TextPrimary = "#b2b0bf", + TextSecondary = "#92929f", + TextDisabled = "#ffffff33", + DrawerIcon = "#92929f", + DrawerText = "#92929f", + GrayLight = "#2a2833", + GrayLighter = "#1e1e2d", + Info = "#4a86ff", + Success = "#3dcb6c", + Warning = "#ffb545", + Error = "#ff3f5f", + LinesDefault = "#33323e", + TableLines = "#33323e", + Divider = "#292838", + OverlayLight = "#1e1e2d80", + }; + + public string DarkLightModeButtonIcon => _isDarkMode switch + { + true => Icons.Material.Rounded.AutoMode, + false => Icons.Material.Outlined.DarkMode, + }; + +} \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/Pages/Counter.razor b/PoyoLang.Translator.Web/Components/Pages/Counter.razor new file mode 100644 index 0000000..9a1cf03 --- /dev/null +++ b/PoyoLang.Translator.Web/Components/Pages/Counter.razor @@ -0,0 +1,19 @@ +@page "/counter" + +Counter + +Counter + +Current count: @currentCount + +Click me + +@code { + private int currentCount = 0; + + private void IncrementCount() + { + currentCount++; + } + +} \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/Pages/Error.razor b/PoyoLang.Translator.Web/Components/Pages/Error.razor new file mode 100644 index 0000000..30c1b33 --- /dev/null +++ b/PoyoLang.Translator.Web/Components/Pages/Error.razor @@ -0,0 +1,38 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) +{ +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + + [CascadingParameter] + private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; + +} \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/Pages/Home.razor b/PoyoLang.Translator.Web/Components/Pages/Home.razor new file mode 100644 index 0000000..7bf6287 --- /dev/null +++ b/PoyoLang.Translator.Web/Components/Pages/Home.razor @@ -0,0 +1,145 @@ +@page "/" +@using PoyoLang.Translator +@inject PoyoLangTranslator Translator +@inject IJSRuntime JsRuntime +@inject ISnackbar Snackbar + +Home + +PoyoLang Translator +Using this website you can freely translate from and to the Poyo language. + This language only use variations of the word "poyo" (320 of them!) to write sentences using the latin alphabet. + If you want more information about how this language works and how it is possible to translate to and from it, + check out the source code of this whole project. + + + + + + +@* Wide screen display *@ + + + + + + + + + + + + + + + + + + + + + + + + + + +@* Mobile display *@ + + + + + + + + + + + + + + + + + + + + + + + + + + +@code { + + private const string EnglishSourceLanguage = "English"; + private const string PoyoSourceLanguage = "PoyoLang"; + + private string _sourceText = ""; + private string _translatedText = ""; + private string _sourceLanguage = EnglishSourceLanguage; + + protected override void OnInitialized() + { + Snackbar.Configuration.PositionClass = Defaults.Classes.Position.BottomCenter; + } + + private void SourceLanguageUpdated() + { + UpdateTranslatedText(); + } + + private void SwapArrowClicked() + { + _sourceLanguage = _sourceLanguage switch + { + PoyoSourceLanguage => EnglishSourceLanguage, + _ => PoyoSourceLanguage + }; + + SwapLanguages(); + } + + private void SwapLanguages() + { + _sourceText = _translatedText; + + UpdateTranslatedText(); + } + + private void UpdateTranslatedText() + { + string result; + + if (_sourceLanguage is PoyoSourceLanguage) + { + result = Translator.TranslateFromPoyo(_sourceText); + } + else + { + result = Translator.TranslateToPoyo(_sourceText); + } + + _translatedText = result; + } + + private async Task CopyResultClicked() + { + await JsRuntime.InvokeVoidAsync("navigator.clipboard.writeText", _translatedText); + + Snackbar.Add("Translation result copied to clipboard!", Severity.Info); + } + + private void ClearButtonClicked() + { + _sourceText = string.Empty; + } + +} \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/Routes.razor b/PoyoLang.Translator.Web/Components/Routes.razor new file mode 100644 index 0000000..ae94e9e --- /dev/null +++ b/PoyoLang.Translator.Web/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Components/_Imports.razor b/PoyoLang.Translator.Web/Components/_Imports.razor new file mode 100644 index 0000000..92a62ee --- /dev/null +++ b/PoyoLang.Translator.Web/Components/_Imports.razor @@ -0,0 +1,12 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using MudBlazor +@using MudBlazor.Services +@using PoyoLang.Translator.Web +@using PoyoLang.Translator.Web.Components \ No newline at end of file diff --git a/PoyoLang.Translator.Web/PoyoLang.Translator.Web.csproj b/PoyoLang.Translator.Web/PoyoLang.Translator.Web.csproj new file mode 100644 index 0000000..c001c64 --- /dev/null +++ b/PoyoLang.Translator.Web/PoyoLang.Translator.Web.csproj @@ -0,0 +1,20 @@ + + + + net9.0 + enable + enable + PoyoLang.Translator.Web + 0.1.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Program.cs b/PoyoLang.Translator.Web/Program.cs new file mode 100644 index 0000000..76586c9 --- /dev/null +++ b/PoyoLang.Translator.Web/Program.cs @@ -0,0 +1,34 @@ +using MudBlazor.Services; +using PoyoLang.Translator; +using PoyoLang.Translator.Web.Components; + +var builder = WebApplication.CreateBuilder(args); + +// Add MudBlazor services +builder.Services.AddMudServices(); + +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); + +builder.Services.AddSingleton(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + +app.UseAntiforgery(); + +app.MapStaticAssets(); +app.MapRazorComponents() + .AddInteractiveServerRenderMode(); + +app.Run(); \ No newline at end of file diff --git a/PoyoLang.Translator.Web/Properties/launchSettings.json b/PoyoLang.Translator.Web/Properties/launchSettings.json new file mode 100644 index 0000000..a738dbf --- /dev/null +++ b/PoyoLang.Translator.Web/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5083", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7137;http://localhost:5083", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } diff --git a/PoyoLang.Translator.Web/appsettings.Development.json b/PoyoLang.Translator.Web/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/PoyoLang.Translator.Web/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/PoyoLang.Translator.Web/appsettings.json b/PoyoLang.Translator.Web/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/PoyoLang.Translator.Web/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/PoyoLang.Translator.Web/wwwroot/favicon.ico b/PoyoLang.Translator.Web/wwwroot/favicon.ico new file mode 100644 index 0000000..8ec8bd6 Binary files /dev/null and b/PoyoLang.Translator.Web/wwwroot/favicon.ico differ diff --git a/PoyoLang.Translator.Web/wwwroot/favicon.png b/PoyoLang.Translator.Web/wwwroot/favicon.png new file mode 100644 index 0000000..df40e90 Binary files /dev/null and b/PoyoLang.Translator.Web/wwwroot/favicon.png differ diff --git a/PoyoLang.Translator.Web/wwwroot/favicon_x512.png b/PoyoLang.Translator.Web/wwwroot/favicon_x512.png new file mode 100644 index 0000000..b96f71a Binary files /dev/null and b/PoyoLang.Translator.Web/wwwroot/favicon_x512.png differ diff --git a/PoyoLang.sln b/PoyoLang.sln index 5d85d8e..ac233c6 100644 --- a/PoyoLang.sln +++ b/PoyoLang.sln @@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoyoLang.Translator.SourceG EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoyoLang.Translator", "PoyoLang.Translator\PoyoLang.Translator.csproj", "{079808D0-16FB-4D01-A502-5366018312CB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoyoLang.Translator.Web", "PoyoLang.Translator.Web\PoyoLang.Translator.Web.csproj", "{4620AA2D-D39E-4393-980C-E4DD25E624C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,5 +38,9 @@ Global {079808D0-16FB-4D01-A502-5366018312CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {079808D0-16FB-4D01-A502-5366018312CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {079808D0-16FB-4D01-A502-5366018312CB}.Release|Any CPU.Build.0 = Release|Any CPU + {4620AA2D-D39E-4393-980C-E4DD25E624C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4620AA2D-D39E-4393-980C-E4DD25E624C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4620AA2D-D39E-4393-980C-E4DD25E624C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4620AA2D-D39E-4393-980C-E4DD25E624C3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/docker-publish.sh b/docker-publish.sh new file mode 100644 index 0000000..f00fc47 --- /dev/null +++ b/docker-publish.sh @@ -0,0 +1,12 @@ +#!/bin/sh +version=$(grep -oPm1 "(?<=)[^<]+" PoyoLang.Translator.Web/PoyoLang.Translator.Web.csproj) + +dotnet.exe publish PoyoLang.Translator.Web \ + -c Release \ + -r linux-x64 \ + -p:PublishProfile=DefaultContainer \ + -p:InvariantGlobalization=true \ + -p:ContainerFamily=alpine \ + -p:ContainerRegistry=git.ilysix.fr \ + -p:ContainerRepository=Eveldee/PoyoLang \ + -p:ContainerImageTags="\"$version;latest\"" \ No newline at end of file