Skip to content

Commit 70d154a

Browse files
Ra/po loc/hishamco /8 (dotnet#28376)
* Add PO Localization Sample for .NET 5 * Add docs for both 6.x & 5.x * Update aspnetcore/fundamentals/portable-object-localization.md * Update aspnetcore/fundamentals/portable-object-localization.md * Update aspnetcore/fundamentals/portable-object-localization.md * Update aspnetcore/fundamentals/portable-object-localization.md * Update portable-object-localization.md * Update aspnetcore/fundamentals/portable-object-localization.md * Loc sample PO version /8 * Loc sample PO version /8 --------- Co-authored-by: Hisham Bin Ateya <[email protected]>
1 parent f877182 commit 70d154a

18 files changed

+521
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="OrchardCore.Localization.Core" Version="1.2.0" />
9+
</ItemGroup>
10+
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@page
2+
@using Microsoft.AspNetCore.Mvc.Localization
3+
@inject IViewLocalizer Localizer
4+
@{
5+
ViewData["Title"] = "Home";
6+
}
7+
8+
<div class="text-center">
9+
<h1 class="display-4">Welcome</h1>
10+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
11+
</div>
12+
13+
<p>@Localizer["Hello world!"]</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@{
3+
ViewData["Title"] = "Privacy Policy";
4+
}
5+
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - POLocalization</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
</head>
10+
<body>
11+
<header>
12+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
13+
<div class="container">
14+
<a class="navbar-brand" asp-area="" asp-page="/Index">POLocalization</a>
15+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
16+
aria-expanded="false" aria-label="Toggle navigation">
17+
<span class="navbar-toggler-icon"></span>
18+
</button>
19+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
20+
<ul class="navbar-nav flex-grow-1">
21+
<li class="nav-item">
22+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
23+
</li>
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
26+
</li>
27+
</ul>
28+
</div>
29+
</div>
30+
</nav>
31+
</header>
32+
<div class="container">
33+
<main role="main" class="pb-3">
34+
@RenderBody()
35+
</main>
36+
</div>
37+
38+
<footer class="border-top footer text-muted">
39+
<div class="container">
40+
&copy; 2022 - POLocalization - <a asp-area="" asp-page="/Privacy">Privacy</a>
41+
</div>
42+
</footer>
43+
44+
<script src="~/lib/jquery/dist/jquery.js"></script>
45+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
46+
<script src="~/js/site.js" asp-append-version="true"></script>
47+
48+
@await RenderSectionAsync("Scripts", required: false)
49+
</body>
50+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@namespace POLocalization.Pages
2+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace POLocalization
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Mvc.Razor;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
7+
8+
namespace POLocalization
9+
{
10+
public class Startup
11+
{
12+
public Startup(IConfiguration configuration)
13+
{
14+
Configuration = configuration;
15+
}
16+
17+
public IConfiguration Configuration { get; }
18+
19+
// This method gets called by the runtime. Use this method to add services to the container.
20+
#region snippet_ConfigureServices
21+
public void ConfigureServices(IServiceCollection services)
22+
{
23+
services.AddRazorPages()
24+
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
25+
26+
services.AddPortableObjectLocalization();
27+
28+
services.Configure<RequestLocalizationOptions>(options => options
29+
.AddSupportedCultures("fr", "cs")
30+
.AddSupportedUICultures("fr", "cs")
31+
);
32+
}
33+
#endregion
34+
35+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36+
#region snippet_Configure
37+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
38+
{
39+
if (env.IsDevelopment())
40+
{
41+
app.UseDeveloperExceptionPage();
42+
}
43+
else
44+
{
45+
app.UseExceptionHandler("/Error");
46+
}
47+
48+
app.UseRouting();
49+
app.UseStaticFiles();
50+
51+
app.UseRequestLocalization();
52+
53+
app.UseEndpoints(endpoint => endpoint.MapRazorPages());
54+
}
55+
#endregion
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
msgid "Hello world!"
2+
msgstr "Ahoj světe!!"
3+
4+
msgid "There is one item."
5+
msgid_plural "There are {0} items."
6+
msgstr[0] "Existuje jedna položka."
7+
msgstr[1] "Existují {0} položky."
8+
msgstr[2] "Existuje {0} položek."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
msgid "Hello world!"
2+
msgstr "Bonjour le monde!"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
/* Provide sufficient contrast against white background */
11+
a {
12+
color: #0366d6;
13+
}
14+
15+
.btn-primary {
16+
color: #fff;
17+
background-color: #1b6ec2;
18+
border-color: #1861ac;
19+
}
20+
21+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
22+
color: #fff;
23+
background-color: #1b6ec2;
24+
border-color: #1861ac;
25+
}
26+
27+
/* Sticky footer styles
28+
-------------------------------------------------- */
29+
html {
30+
font-size: 14px;
31+
}
32+
33+
@media (min-width: 768px) {
34+
html {
35+
font-size: 16px;
36+
}
37+
}
38+
39+
.border-top {
40+
border-top: 1px solid #e5e5e5;
41+
}
42+
43+
.border-bottom {
44+
border-bottom: 1px solid #e5e5e5;
45+
}
46+
47+
.box-shadow {
48+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
49+
}
50+
51+
button.accept-policy {
52+
font-size: 1rem;
53+
line-height: inherit;
54+
}
55+
56+
/* Sticky footer styles
57+
-------------------------------------------------- */
58+
html {
59+
position: relative;
60+
min-height: 100%;
61+
}
62+
63+
body {
64+
/* Margin bottom by footer height */
65+
margin-bottom: 60px;
66+
}
67+
68+
.footer {
69+
position: absolute;
70+
bottom: 0;
71+
width: 100%;
72+
white-space: nowrap;
73+
line-height: 60px; /* Vertically center the text there */
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Write your JavaScript code.

aspnetcore/fundamentals/localization/sample/6.x/POLocalization/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
var builder = WebApplication.CreateBuilder(args);
66

7+
#region snippet_LocalizationServices
78
builder.Services.AddPortableObjectLocalization();
89

910
builder.Services
@@ -14,6 +15,7 @@
1415
builder.Services
1516
.AddRazorPages()
1617
.AddViewLocalization();
18+
#endregion
1719

1820
var app = builder.Build();
1921

0 commit comments

Comments
 (0)