Browse Source
Get `pageLanguage` from `CurrentUICulture`.
pull/20181/head
maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
15 additions and
1 deletions
-
modules/docs/src/Volo.Docs.Web/DocsWebGoogleTranslationOptions.cs
-
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
|
|
|
@ -1,4 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
|
|
|
|
namespace Volo.Docs; |
|
|
|
|
|
|
|
@ -11,6 +13,8 @@ public class DocsWebGoogleTranslationOptions |
|
|
|
/// </summary>
|
|
|
|
public List<string> IncludedLanguages { get; set; } |
|
|
|
|
|
|
|
public Func<CultureInfo, string> GetCultureLanguageCode { get; set; } |
|
|
|
|
|
|
|
public DocsWebGoogleTranslationOptions() |
|
|
|
{ |
|
|
|
UseGoogleTranslation = false; |
|
|
|
@ -34,5 +38,14 @@ public class DocsWebGoogleTranslationOptions |
|
|
|
"de", |
|
|
|
"es" |
|
|
|
]; |
|
|
|
GetCultureLanguageCode = culture => |
|
|
|
{ |
|
|
|
return culture.Name switch |
|
|
|
{ |
|
|
|
"zh-Hans" => "zh-CN", |
|
|
|
"zh-Hant" => "zh-TW", |
|
|
|
_ => culture.TwoLetterISOLanguageName |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
@page |
|
|
|
@using System.Globalization |
|
|
|
@using Microsoft.AspNetCore.Mvc.Localization |
|
|
|
@using Microsoft.AspNetCore.Mvc.TagHelpers |
|
|
|
@using Microsoft.Extensions.Options |
|
|
|
@ -62,7 +63,7 @@ |
|
|
|
<script type="text/javascript"> |
|
|
|
function googleTranslateElementInit() { |
|
|
|
new google.translate.TranslateElement({ |
|
|
|
pageLanguage: 'en', |
|
|
|
pageLanguage: '@DocsWebOptions.Value.GetCultureLanguageCode(CultureInfo.CurrentUICulture)', |
|
|
|
autoDisplay: false, |
|
|
|
disableAutoTranslation: true, |
|
|
|
includedLanguages: '@string.Join(",", DocsWebOptions.Value.IncludedLanguages)', |
|
|
|
|