我正在开发Orchard模块并安装POEdit来管理本地化(.po)文件。是否可以为.cshtml文件配置POEdit?在设置中没有* .cshtml文件的解析器,所以我在" C#"语言。这不太好。
如果我的cshtml代码中有一个C#块,POEdit会识别翻译项目:
if (...)
{
@T("test translation")
}
如果我有HTML块,则无法识别翻译项目:
<div title="@T("test translation inside html code")"></div>
有谁知道如何解决这个问题?
答案 0 :(得分:3)
本地化Orchard最简单,最常用的方法是:
翻译管理器工具会扫描T(...)
次调用的所有代码文件(包括 .cshtml )并生成正确的.po文件。它还包括在代码更改后更新/同步现有翻译的命令,使其成为一个非常有用的工具。
答案 1 :(得分:0)
感谢Piotr Szmyd的帮助。使用Orchard模块Translation Manager 我可以更新我的.po文件。但我有初步问题:
解决方案是一个小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
脚本正在执行以下命令: