【问题标题】:How to exclude DBGrid.Column.FieldName in .pot file如何在 .pot 文件中排除 DBGrid.Column.FieldName
【发布时间】:2011-06-09 14:12:01
【问题描述】:

我用 Delphi 6 做了一个应用程序。 之后,我提取了一个包含所有要翻译的字符串的 .pot 文件。 问题是有些字符串不必翻译,如果翻译了就会产生问题。

其中一个是 TDBGrid.Columns[x].FiedlName

我尝试将这些行放入 ggexclude.cfg 文件中,但它们不起作用。

# exclude all occurences of the specified class
# and property in all DFM files in or below the
# path where "ggexclude.cfg" is in
[exclude-form-class-property]
TDBGrid......FieldName
TDBGrid.....FieldName
TDBGrid....FieldName
TDBGrid...FieldName
TDBGrid..FieldName
TDBGrid.FieldName
item.FieldName

TDBGrid.Columns.FieldName
TDBGrid.Columns.TDBGridColumns
TDBGrid.Columns.TDBGridColumns.FieldName
TDBGrid.Columns.Item.FieldName

TColumn.FieldName
TDBGridColumns.FieldName

FieldName

*.FieldName

我认为问题在于 .dfm 文件中的解析器不明白它们是 TColumn 对象的一部分

  inherited DBGTable: TDBGrid
    Height = 309
    DataSource = DMUsers.DSUser
    Columns = <
      item
        Expanded = False
        FieldName = 'USER'
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'CODE'
        Width = 31
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'NAME'
        Width = 244
        Visible = True
      end>
  end

有人有解决办法吗?

我不能相信自动 ignore.pot,因为有些字符串会导致误报。

【问题讨论】:

    标签: delphi gettext delphi-6


    【解决方案1】:

    ggexclude.cfg-File 的文档指出您无法访问属于集合的项目:

    一种特殊情况是表单中的集合(如 TDBGridColumns 中的 TDBGrid [...]) 您只能排除整个集合,但不能 集合的某些属性。

    所以解决方法是排除整个 Columns-Collection:

    TDBGrid.Columns
    

    但是这样你也会丢失 Title.Caption。

    我看到的唯一其他解决方法是修改 dxgettext。恕我直言,以下内容会很好:

    [always-exclude-property]
    FieldName
    

    编辑:我想链接到 ggexclude.cfg-documentation,但我现在无法在网上找到它。因此,我可以随意发布文档,因为它保存在我自己的 ggexclude.cfg 文件中 - 但没有任何保证:

    # Text in square brackets, like "[exclude-dir]", is called a "section".
    # Each line that is not empty, not a comment and not a section holds 
    # exactly 1 "value".
    # All lines below a section are scanned for values belonging to that 
    # section until the next section starts. You can use the same section 
    # several times. It will all be added up.
    
    [exclude-dir]
    # This section prevents a whole folder and all it's subfolder from being scanned.
    # Each value is exactly one folder. On Windows, it's not case-sensitive.
    # You can use relative or absolute paths. No wildcards allowed.
    
    # example:
    # subfolder
    
    # these are valid values as well:
    # another\folder
    # another\folder\
    # Windows: D:\yet\another\folder
    # Linux:  /home/zaphod/projects/subfolder/
    # You don't have to worry about the path delimiters, both "/" and "\"
    # can be used. They are converted to "/" internally
    
    [exclude-file]
    # This section prevents a whole file from being scanned.
    # Each value is exactly one file. On Windows, it's not case-sensitive.
    # You can use relative or absolute paths. Wildcards allowed.
    
    # example:
    # Unit4.dfm
    
    # Using the wildcard ".*" for a file extension means that the following
    # matching Delphi-files will be excluded: dfm, xfm, pas, inc, rc, dpr:
    # Unit5.*
    
    # If Unit3 is already excluded by the [exclude-dir] above, because it
    # is located in a subfolder of "subfolder", listing it here therefore 
    # has not further effect:
    # subfolder\subfolder\Unit3.dfm
    
    # you can use absolute paths as well, like this:
    # on Windows: D:\test\Unit.pas
    # on Linux:   /home/zaphod/projects/MainForm.*
    
    [exclude-form-class-property]
    # This section prevents a certain property of a class to
    # be excluded from scanning in all forms of the folder and subfolders
    # where "ggexclude.cfg" is located.
    # The format for a value is "Classname.Properyname". It's not case-sensitive. No wildcards allowed.
    # Classname is obvious, the propertyname has to be written the way it
    # is written in the form file. If you're in doubt about how a certain property
    # has to be stored here, just copy and paste the line from the DFM file here and
    # put the classname before that.
    # For simple strings the property name is one word:
    # TLabel.Caption
    
    # ...and for TStrings it's like this:
    # TListbox.Items.Strings
    # TMemo.Lines.Strings
    # TQuery.SQL.Strings
    
    # TEdit is listed in the [exclude-form-class]-section below which means
    # that the whole class will be excluded. Listing TEdit.Text here therefore
    # has no further effect
    # TEdit.Text
    
    # A special case are collections in forms (like TDBGridColumns in a TDBGrid,
    # TParams in a TQuery or TActionManager.ActionBars). You can exclude only
    # the whole collection, but not certain properties of a collection. That 
    # means as well that in the case of nested collections (see TActionManager.ActionBars
    # in the sample unit "nestedcollections.dfm"), everything that appears below
    # the collection with the highest level will be ignored.
    # Note that some collections are saved with another name than their propertyname. 
    # For example: "TQuery.Params" will be saved as "ParamData" in the form file.  
    # TQuery.ParamData
    # TDBGrid.Columns
    # TActionManager.ActionBars
    
    # these lines won't work:
    # TDBGrid.Columns.Title.Caption
    # TActionManager.ActionBars.ContextItems
    # ("ContextItems" is a nested collection, which can hold another nested collection and so on)
    
    [exclude-form-class]
    # This section prevents a whole class to
    # be excluded from scanning in all forms of the folder and subfolders
    # where "ggexclude.cfg" is located.
    # The format for a value is just "Classname". It's not case-sensitive.
    # A wildcard "*" can be used optionally.
    # A special case are collections, see [exclude-form-class-property] for that
    
    # Here, everything of TEdit in DFM/XFM-files will be ignored. Remember:
    # other classes derived from TEdit have to listed seperatly in order to 
    # exclude their properties as well. Inheritance is not recognized by dxgettext:
    # TEdit
    
    # Visual containers like TPanel or TScrollbox have to be treated slightly different. 
    # If you have a TPanel with a TLabel on it, writing "TPanel" would only
    # exclude the properties of TPanel itself. If you want to exclude
    # everything contained in a TPanel, use the wildcard "*" at the end, like this:
    # TPanel* 
    
    # The following only excludes the properties of TScrollbox itself, but not the controls
    # contained in Scrollboxes (except other classes explicitly listed here, like
    # TEdit above):
    # TScrollbox
    
    [exclude-form-instance]
    # This section prevents a certain instance (=object) of a class in a certain form file to
    # be excluded from scanning.
    # Each value is exactly one file with one instance. The format is 
    # "filename:instancename". On Windows, the "filename" part is not 
    # case-sensitive. You can use relative or absolute paths.
    # Note that if the instance is something like a container or menu, 
    # everything belonging to that will be excluded.
    # Note also that a frame on a form might contain a component with the
    # same name as a component on the form. They would both be excluded. 
    # Unit6.dfm:Popupmenu
    # Unit6.dfm:Label5
    

    【讨论】:

      【解决方案2】:

      你可能应该尝试运行

       msgmkignore filenamethatcontainsextrajunk.po -o autogenignore.po
      

      然后打开 autogenignore.po 并找到它声明所有字段名排除的特殊方式(这就是 msgmkignore 的工作)。每次自动生成它时,您都必须查看自动生成的排除规则。您似乎正在尝试手动生成所有排除规则。在我看来,您最好采用自动生成的包含并手动查看它们以排除所有数据库字段名称和列名称。

      正如您在问题中所说,您显然不能将“忽略”的整个工作交给 msgmkignore 工具,但您可以使用您的大脑,加上这个工具,并结合这些结果。

      【讨论】:

        猜你喜欢
        • 2020-01-18
        • 2011-06-08
        • 2012-04-22
        • 1970-01-01
        • 2019-03-26
        • 2011-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多