diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..a597b67
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,16 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "C#: OrchardCoreContrib.PoExtractor Debug",
+ "type": "coreclr",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/OrchardCoreContrib.PoExtractor/bin/Debug/net8.0/OrchardCoreContrib.PoExtractor.dll",
+ "args": [],
+ "cwd": "${workspaceFolder}"
+ }
+ ]
+}
diff --git a/src/OrchardCoreContrib.PoExtractor.Razor/MetadataProviders/RazorMetadataProvider.cs b/src/OrchardCoreContrib.PoExtractor.Razor/MetadataProviders/RazorMetadataProvider.cs
index 01971a2..0ea7aaf 100644
--- a/src/OrchardCoreContrib.PoExtractor.Razor/MetadataProviders/RazorMetadataProvider.cs
+++ b/src/OrchardCoreContrib.PoExtractor.Razor/MetadataProviders/RazorMetadataProvider.cs
@@ -35,6 +35,7 @@ public string GetContext(SyntaxNode node)
ArgumentNullException.ThrowIfNull(node);
var path = node.SyntaxTree.FilePath.TrimStart(_basePath);
+ path = RemoveProjectNameFromPath(path);
path = RemoveRazorFileExtension(path);
return path.Replace(Path.DirectorySeparatorChar, '.');
@@ -108,4 +109,25 @@ private string GetSourceCodeLine(string path, int line)
return null;
}
+
+ private static string RemoveProjectNameFromPath(string path)
+ {
+ // Remove leading directory separator if present
+ if (path.StartsWith(Path.DirectorySeparatorChar))
+ {
+ path = path.Substring(1);
+ }
+
+ // Find the first directory separator to locate the project name
+ var firstSeparatorIndex = path.IndexOf(Path.DirectorySeparatorChar);
+
+ // If there's no separator, just return the path as is
+ if (firstSeparatorIndex == -1)
+ {
+ return path;
+ }
+
+ // Remove the project name (everything before the first separator)
+ return path.Substring(firstSeparatorIndex + 1);
+ }
}
diff --git a/src/OrchardCoreContrib.PoExtractor/Program.cs b/src/OrchardCoreContrib.PoExtractor/Program.cs
index a20204b..b46b938 100644
--- a/src/OrchardCoreContrib.PoExtractor/Program.cs
+++ b/src/OrchardCoreContrib.PoExtractor/Program.cs
@@ -110,7 +110,6 @@ public static void Main(string[] args)
{
var projectPath = Path.GetDirectoryName(projectFile);
var projectBasePath = Path.GetDirectoryName(projectPath) + Path.DirectorySeparatorChar;
- var projectRelativePath = projectPath[projectBasePath.Length..];
var rootedProject = projectPath == inputPath.Value
? projectPath
: projectPath[(projectPath.IndexOf(inputPath.Value, StringComparison.Ordinal) + inputPath.Value.Length + 1)..];
diff --git a/test/OrchardCoreContrib.PoExtractor.Razor.Tests/OrchardCoreContrib.PoExtractor.Razor.Tests.csproj b/test/OrchardCoreContrib.PoExtractor.Razor.Tests/OrchardCoreContrib.PoExtractor.Razor.Tests.csproj
new file mode 100644
index 0000000..c683456
--- /dev/null
+++ b/test/OrchardCoreContrib.PoExtractor.Razor.Tests/OrchardCoreContrib.PoExtractor.Razor.Tests.csproj
@@ -0,0 +1,16 @@
+
This is a sample view.
diff --git a/test/OrchardCoreContrib.PoExtractor.Razor.Tests/Sample/Views/Home/Index.cshtml b/test/OrchardCoreContrib.PoExtractor.Razor.Tests/Sample/Views/Home/Index.cshtml new file mode 100644 index 0000000..2bdd285 --- /dev/null +++ b/test/OrchardCoreContrib.PoExtractor.Razor.Tests/Sample/Views/Home/Index.cshtml @@ -0,0 +1,7 @@ +@* Sample Razor View *@ +@{ + ViewData["Title"] = "Home Page"; +} + +This is a sample view.