POEdit - ASP.NET (.cshtml) 文件的解析器
POEdit - Parser for ASP.NET (.cshtml) files
我正在开发一个 Orchard 模块并安装了 POEdit 来管理本地化 (.po) 文件。是否可以为 .cshtml 文件配置 POEdit?在设置中没有 *.cshtml 文件的解析器,所以我在 "C#" 语言中添加了它。这不太好用。
如果我的 cshtml 代码中有 C# 块,POEdit 会识别翻译项:
if (...)
{
@T("test translation")
}
如果我有一个 HTML 块,它无法识别翻译项:
<div title="@T("test translation inside html code")"></div>
有人知道怎么解决吗?
本地化 Orchard 最简单和最常用的方法是:
- 生成 .po 文件,使用 Translation Manager
- 使用 POEdit 或其他方式用正确的翻译填充生成的文件
翻译管理器工具扫描所有代码文件(包括 .cshtml 个)以查找 T(...)
调用并生成正确的 .po 文件。它还包括代码更改后 update/sync 现有翻译的命令,使其成为一个非常有用的工具。
感谢 Piotr Szmyd 的帮助。使用 Orchard 模块 Translation Manager
我可以更新我的 .po 文件。但我最初遇到了问题:
- 一键更新.po文件
- 在 POEdit 中打开 .po 文件(从翻译管理器中提取的文件未标记为 UTF-8)
解决方案是一个小的 VBS 脚本,它可能会帮助你们中的一些人解决同样的问题。只需将其保存到 updateHelper.vbs(不要忘记设置配置值):
' ####################
' Configuration
Const OrchardPath = "" ' Path to Orchard
Const Modules = "" ' e.g. Orchard.Blogs,Orchard.Pages
Const DefaultCulture = "en-us" ' default language
' ####################
OrchardWeb = OrchardPath & "\src\Orchard.Web"
OrchardBin = OrchardWeb & "\bin\"
WScript.Echo "Extracting T-strings from module..."
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run OrchardBin & "\Orchard extract default translation /Output:" & OrchardWeb & " /Extensions:" & Modules, 0, true
WScript.Echo "Extracting archive..."
ZipFile = OrchardWeb & "\Orchard." & DefaultCulture & ".po.zip"
ExtractTo = OrchardWeb
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
Set objShell = CreateObject("Shell.Application")
Set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
WScript.Echo "Deleting archive..."
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(ZipFile) Then
filesys.DeleteFile ZipFile
End If
For Each orchardModule in Split(Modules, ",")
WScript.Echo "Preparing files for module """ & orchardModule & """:"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set orchardModuleLanguages = objFSO.GetFolder(OrchardWeb & "\Modules\" & orchardModule & "\App_Data\Localization").Subfolders
For Each orchardModuleLanguage in orchardModuleLanguages
If NOT StrComp(orchardModuleLanguage.Name, DefaultCulture, vbTextCompare) = 0 Then
WScript.Echo "Synchronizing to """ & orchardModuleLanguage.Name & """..."
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run OrchardBin & "\Orchard sync translation /Input:" & OrchardWeb & " /Culture:" & orchardModuleLanguage.Name, 0, true
End If
WScript.Echo "Preparing """ & orchardModuleLanguage.Name & """ for POEdit..."
TranslationFile = OrchardWeb & "\Modules\" & orchardModule & "\App_Data\Localization\" & orchardModuleLanguage.Name & "\orchard.module.po"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(TranslationFile, 1) ' Reading
strContents = objFile.ReadAll
objFile.Close
Set objFile = objFSO.OpenTextFile(TranslationFile, 2) ' Writing
objFile.WriteLine "msgid """""
objFile.WriteLine "msgstr """""
objFile.WriteLine """Language: " & orchardModuleLanguage.Name & "\n"""
objFile.WriteLine """MIME-Version: 1.0\n"""
objFile.WriteLine """Content-Type: text/plain; charset=UTF-8\n"""
objFile.WriteLine """Content-Transfer-Encoding: 8bit\n"""
objFile.WriteLine """X-Poedit-SourceCharset: UTF-8\n"""
objFile.WriteLine vbCrLf & strContents
objFile.Close
Next
Next
WScript.Echo "Process completed!"
现在创建一个包含以下内容的.bat文件,以获取命令中的进度输出shell:
@echo off
cscript updateHelper.vbs
pause
脚本正在执行以下命令:
- 正在从特殊模块(翻译管理器)的默认语言中提取所有 T-strings
- 将提取的存档解压缩到您的模块文件夹并覆盖默认语言 .po 文件
- 正在删除存档
- 正在同步到当前位于模块本地化文件夹中的所有其他 .po 文件
- 为所有 .po 文件设置 header 数据,以便为 POEdit(作为 UTF-8)做好准备
我正在开发一个 Orchard 模块并安装了 POEdit 来管理本地化 (.po) 文件。是否可以为 .cshtml 文件配置 POEdit?在设置中没有 *.cshtml 文件的解析器,所以我在 "C#" 语言中添加了它。这不太好用。
如果我的 cshtml 代码中有 C# 块,POEdit 会识别翻译项:
if (...)
{
@T("test translation")
}
如果我有一个 HTML 块,它无法识别翻译项:
<div title="@T("test translation inside html code")"></div>
有人知道怎么解决吗?
本地化 Orchard 最简单和最常用的方法是:
- 生成 .po 文件,使用 Translation Manager
- 使用 POEdit 或其他方式用正确的翻译填充生成的文件
翻译管理器工具扫描所有代码文件(包括 .cshtml 个)以查找 T(...)
调用并生成正确的 .po 文件。它还包括代码更改后 update/sync 现有翻译的命令,使其成为一个非常有用的工具。
感谢 Piotr Szmyd 的帮助。使用 Orchard 模块 Translation Manager 我可以更新我的 .po 文件。但我最初遇到了问题:
- 一键更新.po文件
- 在 POEdit 中打开 .po 文件(从翻译管理器中提取的文件未标记为 UTF-8)
解决方案是一个小的 VBS 脚本,它可能会帮助你们中的一些人解决同样的问题。只需将其保存到 updateHelper.vbs(不要忘记设置配置值):
' ####################
' Configuration
Const OrchardPath = "" ' Path to Orchard
Const Modules = "" ' e.g. Orchard.Blogs,Orchard.Pages
Const DefaultCulture = "en-us" ' default language
' ####################
OrchardWeb = OrchardPath & "\src\Orchard.Web"
OrchardBin = OrchardWeb & "\bin\"
WScript.Echo "Extracting T-strings from module..."
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run OrchardBin & "\Orchard extract default translation /Output:" & OrchardWeb & " /Extensions:" & Modules, 0, true
WScript.Echo "Extracting archive..."
ZipFile = OrchardWeb & "\Orchard." & DefaultCulture & ".po.zip"
ExtractTo = OrchardWeb
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
Set objShell = CreateObject("Shell.Application")
Set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
WScript.Echo "Deleting archive..."
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(ZipFile) Then
filesys.DeleteFile ZipFile
End If
For Each orchardModule in Split(Modules, ",")
WScript.Echo "Preparing files for module """ & orchardModule & """:"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set orchardModuleLanguages = objFSO.GetFolder(OrchardWeb & "\Modules\" & orchardModule & "\App_Data\Localization").Subfolders
For Each orchardModuleLanguage in orchardModuleLanguages
If NOT StrComp(orchardModuleLanguage.Name, DefaultCulture, vbTextCompare) = 0 Then
WScript.Echo "Synchronizing to """ & orchardModuleLanguage.Name & """..."
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run OrchardBin & "\Orchard sync translation /Input:" & OrchardWeb & " /Culture:" & orchardModuleLanguage.Name, 0, true
End If
WScript.Echo "Preparing """ & orchardModuleLanguage.Name & """ for POEdit..."
TranslationFile = OrchardWeb & "\Modules\" & orchardModule & "\App_Data\Localization\" & orchardModuleLanguage.Name & "\orchard.module.po"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(TranslationFile, 1) ' Reading
strContents = objFile.ReadAll
objFile.Close
Set objFile = objFSO.OpenTextFile(TranslationFile, 2) ' Writing
objFile.WriteLine "msgid """""
objFile.WriteLine "msgstr """""
objFile.WriteLine """Language: " & orchardModuleLanguage.Name & "\n"""
objFile.WriteLine """MIME-Version: 1.0\n"""
objFile.WriteLine """Content-Type: text/plain; charset=UTF-8\n"""
objFile.WriteLine """Content-Transfer-Encoding: 8bit\n"""
objFile.WriteLine """X-Poedit-SourceCharset: UTF-8\n"""
objFile.WriteLine vbCrLf & strContents
objFile.Close
Next
Next
WScript.Echo "Process completed!"
现在创建一个包含以下内容的.bat文件,以获取命令中的进度输出shell:
@echo off
cscript updateHelper.vbs
pause
脚本正在执行以下命令:
- 正在从特殊模块(翻译管理器)的默认语言中提取所有 T-strings
- 将提取的存档解压缩到您的模块文件夹并覆盖默认语言 .po 文件
- 正在删除存档
- 正在同步到当前位于模块本地化文件夹中的所有其他 .po 文件
- 为所有 .po 文件设置 header 数据,以便为 POEdit(作为 UTF-8)做好准备