-
Notifications
You must be signed in to change notification settings - Fork 36
Add plugin support for other templates languages #102
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
Changes from 12 commits
1f1cac7
9eb4f21
a8d4f00
f3420df
c172b43
aeaa3bd
31224e0
11b7fd5
e7c2a10
8716a94
bd6cfd5
d634380
132d4f4
e4abfa7
07798dc
9cf8265
857c41f
f6e0443
1517c35
4654924
3a30702
bb7aa16
af5a94a
85448b9
20ecc7d
1c03367
284e8b3
ffac438
9ec159c
dd927ad
fa7ec12
c5ba5db
935a85e
04f6630
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<!-- Ignore global configuration --> | ||
<clear /> | ||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" /> | ||
<add key="OrchardCore" value="https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json" /> | ||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The feed is already there?!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops, I didn't notice. I've reverted the name. My point was just to remove the If you need the Orchard Core preview feed in the future, I suggest adding the full |
||
</packageSources> | ||
</configuration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Reflection; | ||
using Microsoft.CodeAnalysis.CSharp.Scripting; | ||
using Microsoft.CodeAnalysis.Scripting; | ||
|
||
namespace OrchardCoreContrib.PoExtractor; | ||
|
||
public static class PluginHelper | ||
{ | ||
public static async Task ProcessPluginsAsync( | ||
IList<string> plugins, | ||
List<IProjectProcessor> projectProcessors, | ||
List<string> projectFiles, | ||
IEnumerable<Assembly> assemblies) | ||
{ | ||
var options = ScriptOptions.Default.AddReferences(assemblies); | ||
|
||
foreach (var plugin in plugins) | ||
{ | ||
var code = await File.ReadAllTextAsync(plugin); | ||
await CSharpScript.EvaluateAsync(code, options, new PluginContext(projectProcessors, projectFiles)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why this is in Abstractions while it relies heavily on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where should it be then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason is that this class only relies on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not familiar with POe but anything that is related to c# plugins should be in a separate project or in the main assembly, not abstraction. No reference, no class. |
||
} | ||
} | ||
|
||
public record PluginContext(List<IProjectProcessor> projectProcessors, List<string> projectFiles); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace OrchardCoreContrib.PoExtractor; | ||
|
||
public class GetCliOptionsResult | ||
{ | ||
public string Language { get; set; } | ||
public string TemplateEngine { get; set; } | ||
public string SingleOutputFile { get; set; } | ||
public IList<string> Plugins { get; set; } = new List<string>(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
using OrchardCoreContrib.PoExtractor; | ||
|
||
// This example plugin implements processing for a very simplistic subset of the i18next JSON format. It only supports | ||
// strings and other objects, and the files must be located in i18n/{language}.json. Even though this is only meant as a | ||
// demo, even this much can be useful in a real life scenario if paired with a backend API that generates the files for | ||
// other languages using PO files, to centralize the localization tooling. | ||
public class BasicJsonLocalizationProcessor : IProjectProcessor | ||
{ | ||
public void Process(string path, string basePath, LocalizableStringCollection strings) | ||
{ | ||
ArgumentException.ThrowIfNullOrEmpty(path); | ||
ArgumentException.ThrowIfNullOrEmpty(basePath); | ||
ArgumentNullException.ThrowIfNull(strings); | ||
|
||
var jsonFilePaths = Directory.GetFiles(path, "*.json", SearchOption.AllDirectories) | ||
.Where(path => Path.GetFileNameWithoutExtension(path).ToUpperInvariant() is "EN" or "00" or "IV") | ||
.Where(path => Path.GetFileName(Path.GetDirectoryName(path))?.ToUpperInvariant() is "I18N") | ||
.GroupBy(Path.GetDirectoryName) | ||
.Select(group => group | ||
.OrderBy(path => Path.GetFileNameWithoutExtension(path).ToUpperInvariant() switch | ||
{ | ||
"EN" => 0, | ||
"00" => 1, | ||
"IV" => 2, | ||
_ => 3, | ||
}) | ||
.ThenBy(path => path) | ||
.First()); | ||
|
||
foreach (var jsonFilePath in jsonFilePaths) | ||
{ | ||
try | ||
{ | ||
ProcessJson( | ||
jsonFilePath, | ||
strings, | ||
JObject.Parse(File.ReadAllText(jsonFilePath)), | ||
string.Empty); | ||
} | ||
catch | ||
{ | ||
Console.WriteLine("Process failed for: {0}", path); | ||
} | ||
} | ||
} | ||
|
||
private static void ProcessJson(string path, LocalizableStringCollection strings, JsonNode json, string prefix) | ||
{ | ||
if (json is JsonObject jsonObject) | ||
{ | ||
foreach (var (name, value) in jsonObject) | ||
{ | ||
var newPrefix = string.IsNullOrEmpty(prefix) ? name : $"{prefix}.{name}"; | ||
ProcessJson(path, strings, value, newPrefix); | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (json is JsonValue jsonValue) | ||
{ | ||
var value = jsonValue.GetObjectValue()?.ToString(); | ||
strings.Add(new() | ||
{ | ||
Context = prefix, | ||
Location = new() { SourceFile = path }, | ||
Text = value, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
projectProcessors.Add(new BasicJsonLocalizationProcessor()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"about": { | ||
"title": "About us", | ||
"notes": "Title for main menu" | ||
}, | ||
"home": { | ||
"title": "Home page", | ||
"context": "Displayed on the main website page" | ||
}, | ||
"admin.login": { | ||
"title": "Administrator login" | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.