Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<IsPackable>false</IsPackable>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>OrchardCoreContrib.PoExtractor</AssemblyName>
<ToolCommandName>extractpo</ToolCommandName>
<PackAsTool>true</PackAsTool>
<Version>1.3.0</Version>
<Version>1.3.1</Version>
<Authors>The Orchard Core Contrib Team</Authors>
<Company />
<Description>.NET Core global tool for extracting translatable strings from the OrchardCore source files.</Description>
Expand Down
8 changes: 5 additions & 3 deletions src/OrchardCoreContrib.PoExtractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public static void Main(string[] args)
option.DefaultValue = "C#";
});
var template = app.Option("-t|--template <TEMPLATE>", "Specifies the template engine to extract the translatable strings from.", CommandOptionType.SingleValue, option =>
option.Accepts(cfg => cfg.Values("Razor", "Liquid"))
);
{
option.Accepts(cfg => cfg.Values(TemplateEngine.Both, TemplateEngine.Razor, TemplateEngine.Liquid));
option.DefaultValue = TemplateEngine.Both;
});
var ignoredProjects = app.Option("-i|--ignore <IGNORED_PROJECTS>", "Ignores extracting PO files from a given project(s).", CommandOptionType.MultipleValue);
var localizers = app.Option("--localizer <LOCALIZERS>", "Specifies the name of the localizer(s) that will be used during the extraction process.", CommandOptionType.MultipleValue);
var single = app.Option("-s|--single <FILE_NAME>", "Specifies the single output file.", CommandOptionType.SingleValue);
Expand Down Expand Up @@ -112,7 +114,7 @@ public static void Main(string[] args)
var projectBasePath = Path.GetDirectoryName(projectPath) + Path.DirectorySeparatorChar;
var projectRelativePath = projectPath[projectBasePath.Length..];
var rootedProject = projectPath == inputPath.Value
? projectPath
? projectPath
: projectPath[(projectPath.IndexOf(inputPath.Value, StringComparison.Ordinal) + inputPath.Value.Length + 1)..];
if (IgnoredProject.ToList().Any(p => rootedProject.StartsWith(p)))
{
Expand Down
63 changes: 63 additions & 0 deletions test/OrchardCoreContrib.PoExtractor.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Xunit;

namespace OrchardCoreContrib.PoExtractor.Tests;

public class ProgramTests
{
[Fact]
public void Main_NoTemplateOption_UsesBothRazorAndLiquid()
{
// Arrange
var root = Path.Combine(Path.GetTempPath(), "PoExtractorTests", Guid.NewGuid().ToString("N"));
var input = Path.Combine(root, "input");
var output = Path.Combine(root, "output");
var project = Path.Combine(input, "TestModule");

Directory.CreateDirectory(project);
Directory.CreateDirectory(output);

File.WriteAllText(Path.Combine(project, "TestModule.csproj"), """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>
""");

File.WriteAllText(Path.Combine(project, "Index.cshtml"), """
@T["Hello from Razor"]
""");

File.WriteAllText(Path.Combine(project, "index.liquid"), """
{{ "Hello from Liquid" | t }}
""");

var potFileName = "all.pot";

try
{
// Act
Program.Main(
[
input,
output,
"--single", potFileName
]);

// Assert
var potPath = Path.Combine(output, potFileName);
Assert.True(File.Exists(potPath));

var pot = File.ReadAllText(potPath);
Assert.Contains("Hello from Razor", pot);
Assert.Contains("Hello from Liquid", pot);
}
finally
{
if (Directory.Exists(root))
{
Directory.Delete(root, recursive: true);
}
}
}
}
Loading