Browse Source

Add `GoogleTranslation` feature to Docs module.

pull/20181/head
maliming 2 years ago
parent
commit
c4cb9e1a8c
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 56
      modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240707104226_Initial.Designer.cs
  2. 38
      modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240707104226_Initial.cs
  3. 54
      modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/VoloDocsDbContextModelSnapshot.cs
  4. 5
      modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs
  5. 38
      modules/docs/src/Volo.Docs.Web/DocsWebGoogleTranslationOptions.cs
  6. 43
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  7. 33
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.css

56
modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240214150418_Initial.Designer.cs → modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240707104226_Initial.Designer.cs

@ -13,7 +13,7 @@ using VoloDocs.EntityFrameworkCore;
namespace Migrations
{
[DbContext(typeof(VoloDocsDbContext))]
[Migration("20240214150418_Initial")]
[Migration("20240707104226_Initial")]
partial class Initial
{
/// <inheritdoc />
@ -22,7 +22,7 @@ namespace Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
@ -262,6 +262,58 @@ namespace Migrations
b.ToTable("AbpSecurityLogs", (string)null);
});
modelBuilder.Entity("Volo.Abp.Identity.IdentitySession", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("ClientId")
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("Device")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("DeviceInfo")
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("IpAddresses")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<DateTime?>("LastAccessed")
.HasColumnType("datetime2");
b.Property<string>("SessionId")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<DateTime>("SignedIn")
.HasColumnType("datetime2");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.Property<Guid>("UserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("Device");
b.HasIndex("SessionId");
b.HasIndex("TenantId", "UserId");
b.ToTable("AbpSessions", (string)null);
});
modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b =>
{
b.Property<Guid>("Id")

38
modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240214150418_Initial.cs → modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/20240707104226_Initial.cs

@ -170,6 +170,26 @@ namespace Migrations
table.PrimaryKey("PK_AbpSecurityLogs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AbpSessions",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
SessionId = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
Device = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
DeviceInfo = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ClientId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
IpAddresses = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
SignedIn = table.Column<DateTime>(type: "datetime2", nullable: false),
LastAccessed = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpSessions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AbpSettingDefinitions",
columns: table => new
@ -573,6 +593,21 @@ namespace Migrations
table: "AbpSecurityLogs",
columns: new[] { "TenantId", "UserId" });
migrationBuilder.CreateIndex(
name: "IX_AbpSessions_Device",
table: "AbpSessions",
column: "Device");
migrationBuilder.CreateIndex(
name: "IX_AbpSessions_SessionId",
table: "AbpSessions",
column: "SessionId");
migrationBuilder.CreateIndex(
name: "IX_AbpSessions_TenantId_UserId",
table: "AbpSessions",
columns: new[] { "TenantId", "UserId" });
migrationBuilder.CreateIndex(
name: "IX_AbpSettingDefinitions_Name",
table: "AbpSettingDefinitions",
@ -654,6 +689,9 @@ namespace Migrations
migrationBuilder.DropTable(
name: "AbpSecurityLogs");
migrationBuilder.DropTable(
name: "AbpSessions");
migrationBuilder.DropTable(
name: "AbpSettingDefinitions");

54
modules/docs/app/VoloDocs.EntityFrameworkCore/Migrations/VoloDocsDbContextModelSnapshot.cs

@ -19,7 +19,7 @@ namespace Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
@ -259,6 +259,58 @@ namespace Migrations
b.ToTable("AbpSecurityLogs", (string)null);
});
modelBuilder.Entity("Volo.Abp.Identity.IdentitySession", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("ClientId")
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("Device")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("DeviceInfo")
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.Property<string>("IpAddresses")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<DateTime?>("LastAccessed")
.HasColumnType("datetime2");
b.Property<string>("SessionId")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<DateTime>("SignedIn")
.HasColumnType("datetime2");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.Property<Guid>("UserId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("Device");
b.HasIndex("SessionId");
b.HasIndex("TenantId", "UserId");
b.ToTable("AbpSessions", (string)null);
});
modelBuilder.Entity("Volo.Abp.Identity.IdentityUser", b =>
{
b.Property<Guid>("Id")

5
modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs

@ -163,6 +163,11 @@ namespace VoloDocs.Web
{
options.Conventions.AddPageRoute("/Error", "error/{statusCode}");
});
Configure<DocsWebGoogleTranslationOptions>(options =>
{
options.UseGoogleTranslation = true;
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

38
modules/docs/src/Volo.Docs.Web/DocsWebGoogleTranslationOptions.cs

@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace Volo.Docs;
public class DocsWebGoogleTranslationOptions
{
public bool UseGoogleTranslation { get; set; }
/// <summary>
/// https://cloud.google.com/translate/docs/languages
/// </summary>
public List<string> IncludedLanguages { get; set; }
public DocsWebGoogleTranslationOptions()
{
UseGoogleTranslation = false;
IncludedLanguages =
[
"en",
"tr",
"zh-CN",
"zh-TW",
"ar",
"cs",
"hu",
"hr",
"fi",
"fr",
"hi",
"it",
"pt",
"ru",
"sk",
"de",
"es"
];
}
}

43
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

@ -1,5 +1,11 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Options
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Blockquote
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Grid
@using Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Anchor
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Clipboard
@ -8,13 +14,14 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@using Volo.Docs
@using Volo.Docs.Areas.Documents.TagHelpers
@using Volo.Docs.Localization
@using Volo.Docs.Pages.Documents.Project
@using Volo.Docs.Pages.Documents.Shared.ErrorComponent
@using Volo.Docs.Pages.Shared.Components.Head
@inject IThemeManager ThemeManager
@inject IPageLayout PageLayout
@inject IHtmlLocalizer<DocsResource> L
@inject IOptions<DocsWebGoogleTranslationOptions> DocsWebOptions
@model IndexModel
@{
@ -36,7 +43,7 @@
}
@section scripts {
@if (Model.LoadSuccess)
{
<abp-script-bundle name="@typeof(IndexModel).FullName">
@ -50,6 +57,23 @@
<abp-script src="/Pages/Documents/Shared/Scripts/vs.js"/>
<abp-script src="/Pages/Documents/Project/index.js"/>
</abp-script-bundle>
if (DocsWebOptions.Value.UseGoogleTranslation)
{
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en',
autoDisplay: false,
disableAutoTranslation: true,
includedLanguages: '@string.Join(",", DocsWebOptions.Value.IncludedLanguages)',
floatPosition: 0,
layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL
},
'google_translate_element');
}
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
}
}
else
{
@ -96,6 +120,13 @@
<div class="docs-tree-list">
<div class="row gx-2 mb-2 ">
@if (DocsWebOptions.Value.UseGoogleTranslation)
{
<div>
<span class="google_translate_text">Google Translate</span>
<div id="google_translate_element" class="mb-3"></div>
</div>
}
@if (Model.ShowProjectsCombobox && Model.ProjectSelectItems.Count > 1)
{
<div class="col-12 mb-2">
@ -341,7 +372,7 @@
var rowCount = count / maxCellCount + (count % maxCellCount > 0 ? 1 : 0);
var cellSize = 12 / (count > maxCellCount ? maxCellCount : count);
var latestCellSize = 12 / count - (rowCount - 1) * maxCellCount;
string BuildParameterDivClass(int index)
{
var row = index / maxCellCount;
@ -349,7 +380,7 @@
var currentCellSize = isLastRow ? latestCellSize : cellSize;
return $"col-12 col-lg-{currentCellSize} mb-lg-{(isLastRow ? "0" : "2")} {(index == count - 1 ? "" : "mb-2")}";
}
for (var i = 0; i < count; ++i)
{
var parameter = Model.DocumentPreferences.Parameters[i];
@ -391,11 +422,11 @@
</abp-alert>
}
@Html.Raw(Model.Document.Content)
@if (Model.DocumentNavigationsDto.HasValues)
{
<hr class="my-4"/>
<div class="row navigation">
<div class="col-6">
@if (Model.DocumentNavigationsDto.HasPrevious)

33
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.css

@ -20,4 +20,37 @@
color: #0B1621;
}
body {
top: 0px !important;
}
.skiptranslate iframe {
display: none !important;
}
.google_translate_text {
color: #aaa;
font-family: var(--bs-body-font-family);
font-size: 10pt;
margin-left: 2px;
font-weight: 500;
}
.goog-te-gadget {
white-space: break-spaces !important;
}
.goog-te-combo {
width: 100%;
height: auto;
padding: 0.75rem 2.25rem 0.75rem 0.75rem !important;
border-radius: 5px;
background-color: #1e2227 !important;
border: 0;
min-height: 30px;
font-size: 1.17em;
background-color: transparent;
color: rgba(255, 255, 255, 0.7);
}
/*# sourceMappingURL=Index.css.map */

Loading…
Cancel
Save