### PSLOC在PSD1本地化文件中表示什么

时间:2017-09-02 14:12:38

标签: powershell

在几乎每个使用本地化文件的Microsoft项目中都有文本###PSLOC 资源字符串块之前和之后。这是一个例子:

ConvertFrom-StringData @'
###PSLOC
MyString=This is a string.
###PSLOC
'@
来自Here is an example repo。

PowerShellGet

我无法在任何帮助文件中找到对此的任何引用。我查看了about_Data_SectionsConvertFrom-StringDataabout_Script_Internationalization。并且###PSLOC的唯一实例 PowerShell源位于如上所示的资源文件中。

更具体地说,我很想知道:

  1. 它的存在或缺席告诉PowerShell引擎
  2. 最好还在处理PowerShell源的位置

2 个答案:

答案 0 :(得分:5)

我已经搜索了一段时间,得出的结论是###PSLOC 只是惯例而没有特殊含义,即使我找不到正式文件。

我找到了一些微软文档,这些文件让我得出了这个结论。例如:" Microsoft Baseline Configuration Analyzer Model Authoring Guide"在第20页上显示了此示例:

  

内容文件样本
  以下是防病毒模型的内容文件示例:Antivirus.psd1

   # Only add new (name,value) pairs to the end of this table
   # Do not remove, insert or re-arrange entries
   ConvertFrom-StringData @'
   ###PSLOC start localizing
    #
    # helpID="ScanBootSector"
    #
    ScanBootSector_title = Boot Sector Scan (Indicator Setting {0})
    ScanBootSector_problem = tbd: Problem for Constant name issue-1
    ScanBootSector_impact = tbd: Impact for Constant name issue-1
    ScanBootSector_resolution = tbd: Resolution for Constant name issue-1
    ScanBootSector_compliant =  tbd: Compliant for Constant name issue-1
    #
    # helpID="AutoUpdateStatus"
    #
    AutoUpdateStatus_title = Auto Update Status (Indicator Setting {0})
    AutoUpdateStatus_problem = tbd: Problem for Constant name issue-2
    AutoUpdateStatus_impact = tbd: Impact for Constant name issue-2
    AutoUpdateStatus_resolution = tbd: Resolution for Constant name issue-2
    AutoUpdateStatus_compliant =  tbd: Compliant for Constant name issue-2
  '@

请注意,###PSLOC后跟其他说明和更简单的评论,并且没有结束###PSLOC

本书" Pro PowerShell for Database Developers"作者:Bryan P. Cafferky在第二页上的节目。 140 ConvertFrom-StringData部分根本不包含###PSLOC块/标记。

另一条线索来自我自己的Windows 10系统 我搜索了所有* .psd1文件,并了解到有些文件没有正确关闭###PSLOC - 阻止/标记但是###PSCLOCC文件夹,例如c:\ windows \ WinSxS \ amd64_microsoft-windows-pnpdevice-powershell_31bf3856ad364e35_10.0.15063.0_none_e99b05a055a1e6c4 \ PnpDevice.Resource.psd1(这也可能是一个错误)。

最后,我搜索了Powershell(核心)回购,但找不到###PSLOC的任何处理。

因此,案件并非100%明确。但可以说我发现了一些没有特殊意义的好证据。

答案 1 :(得分:3)

构建Windows时,内部本地化工具使用

###PSLOC。该评论对PowerShell引擎没有任何特殊意义。

本地化工具是可扩展的,支持许多不同的文件解析器,以提取资源以进行进一步的本地化处理。

PowerShell的扩展基于ini文件解析器,注释用于告诉解析器何时忽略行。这允许psd1文件的作者混合适当的PowerShell和ini文件解析器没有问题的行。