-
Notifications
You must be signed in to change notification settings - Fork 0
/
UTranslate.pas
51 lines (43 loc) · 1.2 KB
/
UTranslate.pas
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
unit UTranslate;
{$mode objfpc}
interface
uses
Classes, SysUtils;
type
TTranslator = class
public
constructor Create; // we need the ceation of a singleton here. and maybe we should reconsider a start/stop of the translator
function translate(const In: String): String;
end;
implementation
uses
Ulog,
UPLatform;
function TTranslator.translate(const In: String): String;
var
LanguageFilePath: string;
MOFile: TMOFile;
index: integer;
begin
TTranslator.translate := In;
LanguageFilePath := getLanguageFilePath(locale);
if not FileExists(LanguageFilePath) then
begin
Logger.Output ('PreferencesForm', 'File ' + LanguageFilePath + ' not found!');
Logger.Output ('PreferencesForm', 'Continuing with default language, i.e. English!');
end
else
begin
try
MOFile := TMOFile.Create(LanguageFilePath);
except
on EMOFileError do
Logger.Output ('PreferencesForm', 'Invalid .mo file header');
end;
if assigned(MOFile) then
begin
TTranslator.translate := MOFile.translate(In);
MOFile.Destroy;
end;
end;
end.