File: ignoredetector.pas

package info (click to toggle)
mysql-query-browser 1.1.6-1sarge0
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 36,320 kB
  • ctags: 24,680
  • sloc: pascal: 203,479; xml: 136,561; ansic: 47,502; cpp: 28,926; sh: 12,433; objc: 4,823; java: 1,849; php: 1,485; python: 1,225; sql: 1,128; makefile: 872
file content (146 lines) | stat: -rw-r--r-- 3,926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
unit ignoredetector;
(****************************************************************)
(*                                                              *)
(*  (C) Copyright by Lars B. Dybdahl                            *)
(*  E-mail: Lars@dybdahl.dk, phone +45 70201241                 *)
(*  You received this file under the Mozilla Public License 1.1 *)
(*                                                              *)
(*  See http://dybdahl.dk/dxgettext/ for more information       *)
(*                                                              *)
(****************************************************************)

interface

uses
  PoParser;

// Determines if entry is translatable. If not, it will add some comments to entry.
function IsProbablyTranslatable (entry: TPoEntry):boolean;


implementation

uses
  SysUtils;
  
function IsProbablyTranslatable (entry: TPoEntry):boolean;
var
  i:integer;
  hasletters,hasdigits,haswhitespace:boolean;
  c:char;
  utf8:utf8string;
  found:boolean;
  s:string;
begin
  // Check for msgid ""
  if entry.MsgId='' then begin
    Result:=True;
    exit;
  end;

  utf8:=utf8encode(entry.msgid);
  
  // Check for text types
  hasletters:=False;
  hasdigits:=False;
  haswhitespace:=False;
  for i:=1 to length(utf8) do begin
    c:=utf8[i];
    if (c in ['a'..'z','A'..'Z']) or (c>=#128) then
      hasletters:=True;
    if c in ['0'..'9'] then
      hasdigits:=True;
    if c in [#0..#32] then
      haswhitespace:=True;
  end;
  if (not haswhitespace) and hasletters and hasdigits then begin
    entry.UserCommentList.Add('#  Doesn''t look like text');
    Result:=False;
    exit;
  end;
  if not hasletters then begin
    entry.UserCommentList.Add('#  Doesn''t have any letters');
    Result:=False;
    exit;
  end;

  // Check for font names, component names etc.
  found:=False;
  for i:=0 to entry.AutoCommentList.Count-1 do begin
    s:=trim(entry.AutoCommentList.Strings[i]);
    if copy(s,1,2)='#.' then
    if uppercase(copy(s,length(s)-8,9))='FONT.NAME' then begin
      Found:=True;
    end else begin
      Found:=False;
      break;
    end;
  end;
  if Found then begin
    entry.UserCommentList.Add('#  Seems like a Font.Name extract');
    Result:=False;
    exit;
  end;

  // Check for fieldnames
  found:=False;
  for i:=0 to entry.AutoCommentList.Count-1 do begin
    s:=uppercase(trim(entry.AutoCommentList.Strings[i]));
    if copy(s,1,2)='#.' then
    if (pos('DATAFIELD',s)<>0) or (pos('FIELDNAME',s)<>0) or (pos('LOOKUPFIELD',s)<>0)
    or (pos('INDEXNAME',s)<>0) or (pos('KEYFIELDS',s)<>0) or (pos('LOOKUPKEYFIELDS',s)<>0)
    or (pos('DATABASENAME',s)<>0) or (pos('SESSIONNAME',s)<>0) then begin
      Found:=True;
    end else begin
      Found:=False;
      break;
    end;
  end;
  if Found then begin
    entry.UserCommentList.Add('#  Seems like a Database field name or index field name');
    Result:=False;
    exit;
  end;

  // Check for font names, component names etc.
  found:=False;
  for i:=0 to entry.AutoCommentList.Count-1 do begin
    s:=uppercase(trim(entry.AutoCommentList.Strings[i]));
    if copy(s,1,2)='#.' then
    if copy(s,length(s)-7,8)='....NAME' then begin
      Found:=True;
    end else begin
      Found:=False;
      break;
    end;
  end;
  if Found then begin
    entry.UserCommentList.Add('#  Seems like a component name');
    Result:=False;
    exit;
  end;

  // Check for file masks and file extensions
  s:=utf8;
  if (copy(s,1,1)='*') and (length(s)=5) or (length(s)=4) then begin
    if length(s)=5 then
      delete (s,1,1);
    if copy(s,1,1)='.' then begin
      delete (s,1,1);
      for i:=1 to 3 do begin
        found:=(s[i] in ['a'..'z','A'..'Z']);
        if not found then break;
      end;
      if found then begin
        entry.UserCommentList.Add('#  Looks like a file extension or file mask');
        Result:=False;
        exit;
      end;
    end;
  end;

  Result:=True;
end;

end.