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

Added support for multiple languages #362

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
with:
# Comment out the below 'repository' line if you want to build from
# your fork instead of the author's.
repository: lucent-sea/Remotely
repository: vincywindy/Remotely
fetch-depth: 0

# Test the Server URL to make sure it's valid
Expand Down
22 changes: 22 additions & 0 deletions Server/API/CultureController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;

namespace Remotely.Server.API
{
[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);
}
}
}
4 changes: 3 additions & 1 deletion Server/Areas/Identity/Pages/Account/ConfirmEmail.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@page
@model ConfirmEmailModel
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Confirm email";
ViewData["Title"] = Localizer["Confirm email"];
}

<h1>@ViewData["Title"]</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@page
@model ConfirmEmailChangeModel
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Confirm email change";
ViewData["Title"] = Localizer["Confirm email change"];
}

<h1>@ViewData["Title"]</h1>
Expand Down
10 changes: 6 additions & 4 deletions Server/Areas/Identity/Pages/Account/ForgotPassword.cshtml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
@page
@model ForgotPasswordModel
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Forgot your password?";
ViewData["Title"] = Localizer["Forgot your password?"];
}

<h1>@ViewData["Title"]</h1>
<h4>Enter your email.</h4>
<h4>@Localizer["Enter your email."]</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<label asp-for="Input.Email">@Localizer["Email"]</label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="submit" class="btn btn-primary">@Localizer["Submit"]</button>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ForgotPasswordModel(UserManager<RemotelyUser> userManager,
public class InputModel
{
[Required]
[EmailAddress]
[EmailAddress(ErrorMessage = "The true field is not a valid e-mail address.")]
public string Email { get; set; }
}

Expand Down
21 changes: 11 additions & 10 deletions Server/Areas/Identity/Pages/Account/Login.cshtml
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
@page
@model LoginModel

@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Log in";
ViewData["Title"] = Localizer["Log in"];
}

<h1>@ViewData["Title"]</h1>
<div class="row">
<div class="col-md-4">
<section>
<form id="account" method="post">
<h4>Use a local account to log in.</h4>
<h4>@Localizer["Use a local account to log in."]</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<label asp-for="Input.Email">@Localizer["Email"]</label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<label asp-for="Input.Password">@Localizer["Password"]</label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<div class="checkbox">
<label asp-for="Input.RememberMe">
<input asp-for="Input.RememberMe" />
@Html.DisplayNameFor(m => m.Input.RememberMe)
@Localizer["RememberMe"]
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Log in</button>
<button type="submit" class="btn btn-primary">@Localizer["Log in"]</button>
</div>
<div class="form-group">
<p>
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
<a id="forgot-password" asp-page="./ForgotPassword">@Localizer["Forgot your password?"]</a>
</p>
<p>
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">@Localizer["Register as a new user"]</a>
</p>
<p>
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">@Localizer["Resend email confirmation"]</a>
</p>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion Server/Areas/Identity/Pages/Account/Login.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public LoginModel(SignInManager<RemotelyUser> signInManager,
public class InputModel
{
[Required]
[EmailAddress]
[EmailAddress(ErrorMessage = "The true field is not a valid e-mail address.")]
public string Email { get; set; }

[Required]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
@page
@model EnableAuthenticatorModel
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Configure authenticator app";
ViewData["Title"] = Localizer["Configure authenticator app"];
ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
}

<partial name="_StatusMessage" for="StatusMessage" />
<h4>@ViewData["Title"]</h4>
<div>
<p>To use an authenticator app go through the following steps:</p>
<p>@Localizer["To use an authenticator app go through the following steps:"]</p>
<ol class="list">
<li>
<p>
Download a two-factor authenticator app like Microsoft Authenticator for
@Localizer["Download a two-factor authenticator app like Microsoft Authenticator for"]
<a href="https://go.microsoft.com/fwlink/?Linkid=825072">Android</a> and
<a href="https://go.microsoft.com/fwlink/?Linkid=825073">iOS</a> or
Google Authenticator for
@Localizer["Google Authenticator for"]
<a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;hl=en">Android</a> and
<a href="https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8">iOS</a>.
</p>
</li>
<li>
<p>Scan the QR Code or enter this key <kbd>@Model.SharedKey</kbd> into your two factor authenticator app. Spaces and casing do not matter.</p>
<p>@Localizer["Scan the QR Code or enter this key"] <kbd>@Model.SharedKey</kbd> @Localizer["into your two factor authenticator app. Spaces and casing do not matter."]</p>

<div id="qrCode"></div>
<div id="qrCodeData" data-url="@Html.Raw(@Model.AuthenticatorUri)"></div>
</li>
<li>
<p>
Once you have scanned the QR code or input the key above, your two factor authentication app will provide you
with a unique code. Enter the code in the confirmation box below.
@Localizer["Once you have scanned the QR code or input the key above, your two factor authentication app will provide you with a unique code. Enter the code in the confirmation box below."]
</p>
<div class="row">
<div class="col-md-6">
<form id="send-code" method="post">
<div class="form-group">
<label asp-for="Input.Code" class="control-label">Verification Code</label>
<label asp-for="Input.Code" class="control-label">@Localizer["Verification Code"]</label>
<input asp-for="Input.Code" class="form-control" autocomplete="off" />
<span asp-validation-for="Input.Code" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Verify</button>
<button type="submit" class="btn btn-primary">@Localizer["Verify"]</button>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
</form>
</div>
Expand Down
10 changes: 6 additions & 4 deletions Server/Areas/Identity/Pages/Account/Manage/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@page
@model IndexModel
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Profile";
ViewData["Title"] = Localizer["Profile"];
ViewData["ActivePage"] = ManageNavPages.Index;
}

Expand All @@ -12,15 +14,15 @@
<form id="profile-form" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Username"></label>
<label asp-for="Username">@Localizer["Username"]</label>
<input asp-for="Username" class="form-control" disabled />
</div>
<div class="form-group">
<label asp-for="Input.PhoneNumber"></label>
<label asp-for="Input.PhoneNumber">@Localizer["PhoneNumber"]</label>
<input asp-for="Input.PhoneNumber" class="form-control" />
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
</div>
<button id="update-profile-button" type="submit" class="btn btn-primary">Save</button>
<button id="update-profile-button" type="submit" class="btn btn-primary">@Localizer["Save"]</button>
</form>
</div>
</div>
Expand Down
14 changes: 8 additions & 6 deletions Server/Areas/Identity/Pages/Account/Manage/_ManageNav.cshtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
@inject SignInManager<RemotelyUser> SignInManager
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any();
}
<ul class="nav nav-pills flex-column">
<li class="nav-item"><a class="nav-link @ManageNavPages.IndexNavClass(ViewContext)" id="profile" asp-page="./Index">Profile</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.EmailNavClass(ViewContext)" id="email" asp-page="./Email">Email</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.ChangePasswordNavClass(ViewContext)" id="change-password" asp-page="./ChangePassword">Password</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.IndexNavClass(ViewContext)" id="profile" asp-page="./Index">@Localizer["Profile"]</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.EmailNavClass(ViewContext)" id="email" asp-page="./Email">@Localizer["Email"]</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.ChangePasswordNavClass(ViewContext)" id="change-password" asp-page="./ChangePassword">@Localizer["Password"]</a></li>
@if (hasExternalLogins)
{
<li id="external-logins" class="nav-item"><a id="external-login" class="nav-link @ManageNavPages.ExternalLoginsNavClass(ViewContext)" asp-page="./ExternalLogins">External logins</a></li>
<li id="external-logins" class="nav-item"><a id="external-login" class="nav-link @ManageNavPages.ExternalLoginsNavClass(ViewContext)" asp-page="./ExternalLogins">@Localizer["External logins"]</a></li>
}
<li class="nav-item"><a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)" id="two-factor" asp-page="./TwoFactorAuthentication">Two-factor authentication</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)" id="personal-data" asp-page="./PersonalData">Personal data</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.TwoFactorAuthenticationNavClass(ViewContext)" id="two-factor" asp-page="./TwoFactorAuthentication">@Localizer["Two-factor authentication"]</a></li>
<li class="nav-item"><a class="nav-link @ManageNavPages.PersonalDataNavClass(ViewContext)" id="personal-data" asp-page="./PersonalData">@Localizer["Personal data"]</a></li>
</ul>
16 changes: 9 additions & 7 deletions Server/Areas/Identity/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@page
@model RegisterModel
@inject Remotely.Server.Services.IApplicationConfig AppConfig
@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
@{
ViewData["Title"] = "Register";
ViewData["Title"] =Localizer["Register"];
}

<h1>@ViewData["Title"]</h1>
Expand All @@ -12,32 +14,32 @@
{
<div class="col-md-4">
<form asp-route-returnUrl="@Model.ReturnUrl" method="post">
<h4>Create a new account.</h4>
<h4>@Localizer["Create a new account."]</h4>
<hr />
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Email"></label>
<label asp-for="Input.Email">@Localizer["Email"]</label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Password"></label>
<label asp-for="Input.Password">@Localizer["Password"]</label>
<input asp-for="Input.Password" class="form-control" />
<span asp-validation-for="Input.Password" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.ConfirmPassword"></label>
<label asp-for="Input.ConfirmPassword">@Localizer["ConfirmPassword"]</label>
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Register</button>
<button type="submit" class="btn btn-primary">@Localizer["Register"]</button>
</form>
</div>
}
else
{
<div class="col-sm-12">
<h5>Registration is disabled.</h5>
<h5>@Localizer["Registration is disabled."]</h5>
</div>
}

Expand Down
2 changes: 1 addition & 1 deletion Server/Areas/Identity/Pages/Account/Register.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public RegisterModel(
public class InputModel
{
[Required]
[EmailAddress]
[EmailAddress(ErrorMessage = "The true field is not a valid e-mail address.")]
[Display(Name = "Email")]
public string Email { get; set; }

Expand Down
11 changes: 6 additions & 5 deletions Server/Areas/Identity/Pages/Shared/_LoginPartial.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
@inject Remotely.Server.Services.IApplicationConfig AppConfig
@inject Remotely.Server.Services.IDataService DataService
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@using Microsoft.Extensions.Localization
@inject IStringLocalizer Localizer
<ul class="navbar-nav">
@if (SignInManager.IsSignedIn(User))
{
<li class="nav-item">
<a class="nav-link" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Account</a>
<a class="nav-link" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">@Localizer["Account"]</a>
</li>
<li class="nav-item">
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="/" method="post">
<button type="submit" class="nav-link btn btn-link">Logout</button>
<button type="submit" class="nav-link btn btn-link">@Localizer["Logout"]</button>
</form>
</li>
}
Expand All @@ -22,12 +23,12 @@
@if (AppConfig.MaxOrganizationCount < 0 || DataService.GetOrganizationCount() < AppConfig.MaxOrganizationCount)
{
<li class="nav-item">
<a class="nav-link" asp-area="Identity" asp-page="/Account/Register">Register</a>
<a class="nav-link" asp-area="Identity" asp-page="/Account/Register">@Localizer["Register"]</a>
</li>
}

<li class="nav-item">
<a class="nav-link" asp-area="Identity" asp-page="/Account/Login">Login</a>
<a class="nav-link" asp-area="Identity" asp-page="/Account/Login">@Localizer["Login"]</a>
</li>
}
</ul>
Loading