mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added ability to log out missing translations (#8477)
This commit is contained in:
@@ -34,6 +34,13 @@
|
|||||||
<priority value="WARN" />
|
<priority value="WARN" />
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
|
<logger name="Orchard.Localization.Services.DefaultLocalizedStringManager">
|
||||||
|
<!-- Setting priority higher than INFO will prevent stuff being added to this logger
|
||||||
|
Because in code this is filled by a Logger.Information -->
|
||||||
|
<priority value="OFF" />
|
||||||
|
<appender-ref ref="localization-file" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
<logger name="NHibernate.Cache">
|
<logger name="NHibernate.Cache">
|
||||||
<!-- This source is very verbose - setting priority here to avoid flooding trace if root priority is lowered. -->
|
<!-- This source is very verbose - setting priority here to avoid flooding trace if root priority is lowered. -->
|
||||||
<priority value="ERROR" />
|
<priority value="ERROR" />
|
||||||
@@ -104,4 +111,25 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
<appender name="localization-file" type="Orchard.Logging.OrchardFileAppender">
|
||||||
|
<file value="App_Data/Logs/orchard-localization" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<!-- Allow extended character sets (e.g. Chinese, Russian...) -->
|
||||||
|
<encoding value="utf-8" />
|
||||||
|
<!-- Immediate flush on error log, to avoid data loss with sudden termination. -->
|
||||||
|
<immediateFlush value="true" />
|
||||||
|
<staticLogFileName value="false" />
|
||||||
|
<rollingStyle value="Date" />
|
||||||
|
<datepattern value="-yyyy.MM.dd'.log'" />
|
||||||
|
<!-- Prevents Orchard.exe from displaying locking debug messages. -->
|
||||||
|
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||||
|
<!-- Only add to this log the information about strings to localize -->
|
||||||
|
<filter type="log4net.Filter.StringMatchFilter">
|
||||||
|
<stringToMatch value="##CULTURE##" />
|
||||||
|
</filter>
|
||||||
|
<filter type="log4net.Filter.DenyAllFilter" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date %logger - %P{Tenant} - %level% [ExecutionId=%P{ExecutionId}]%newline[%P{Url}]%newline%message%newline " />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
</log4net>
|
</log4net>
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using Orchard.Caching;
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
|
using Orchard.Environment.Descriptor.Models;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.FileSystems.WebSite;
|
using Orchard.FileSystems.WebSite;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
using Orchard.Environment.Descriptor.Models;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Collections;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Orchard.Localization.Services {
|
namespace Orchard.Localization.Services {
|
||||||
public class DefaultLocalizedStringManager : ILocalizedStringManager {
|
public class DefaultLocalizedStringManager : ILocalizedStringManager {
|
||||||
@@ -46,12 +45,30 @@ namespace Orchard.Localization.Services {
|
|||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
public bool DisableMonitoring { get; set; }
|
public bool DisableMonitoring { get; set; }
|
||||||
|
|
||||||
public FormatForScope GetLocalizedString(IEnumerable<string> scopes, string text, string cultureName) {
|
public FormatForScope GetLocalizedString(IEnumerable<string> scopes, string text, string cultureName) {
|
||||||
var result = InnerGetLocalizedString(scopes, text, cultureName);
|
var result = InnerGetLocalizedString(scopes, text, cultureName);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
/*
|
||||||
|
* Log out messages that look like what we would have in the .po files
|
||||||
|
* Prepend that with a line telling the target culture for which the localization is missing
|
||||||
|
msgctxt "Orchard.Users.Activities.CreateUserActivity"
|
||||||
|
msgid "InvalidPassword"
|
||||||
|
msgstr "**InvalidPassword**"
|
||||||
|
*/
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
// The configured appender for the localizations file will only consider
|
||||||
|
// messages that contain "##CULTURE##"
|
||||||
|
sb.AppendLine("##CULTURE## " + cultureName);
|
||||||
|
// These three lines math those found in .po files.
|
||||||
|
sb.AppendLine("msgctxt \"" + scopes.FirstOrDefault() + "\"");
|
||||||
|
sb.AppendLine("msgid \"" + text + "\"");
|
||||||
|
sb.AppendLine("msgstr \"**" + text + "**\"");
|
||||||
|
// to enable/disable logging this information, search in log4net.config
|
||||||
|
// for the logger named Orchard.Localization.Services.DefaultLocalizedStringManager
|
||||||
|
Logger.Information(sb.ToString());
|
||||||
return new FormatForScope(text, scopes.FirstOrDefault());
|
return new FormatForScope(text, scopes.FirstOrDefault());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user