Johann ELSASS пре 5 година
родитељ
комит
7db4e078c8

+ 17 - 0
lazpaint/lazpaintdialogs.inc

@@ -230,6 +230,23 @@ begin
     result := srCancelledByUser;
 end;
 
+function TLazPaintInstance.ScriptTranslateText(AVars: TVariableSet): TScriptResult;
+var
+  textVar, resVar: TScriptVariableReference;
+  i: Integer;
+begin
+  textVar := AVars.GetVariable('Text');
+  if not AVars.IsReferenceDefined(textVar) then exit(srException);
+  if AVars.IsList(textVar) then
+  begin
+    resVar := AVars.AddStringList('Result');
+    for i := 0 to AVars.GetListCount(textVar)-1 do
+      AVars.AppendString(resVar, DoTranslate('', AVars.GetStringAt(textVar, i)));
+  end else
+    AVars.Strings['Result'] := DoTranslate('', AVars.Strings['Text']);
+  result := srOk;
+end;
+
 function TLazPaintInstance.ShowResampleDialog(AParameters: TVariableSet): boolean;
 begin
   FormsNeeded;

+ 3 - 1
lazpaint/lazpaintinstance.pas

@@ -59,6 +59,7 @@ type
     function ScriptImageResample(AParams: TVariableSet): TScriptResult;
     function ScriptLazPaintGetVersion(AVars: TVariableSet): TScriptResult;
     function ScriptShowDirectoryDialog(AVars: TVariableSet): TScriptResult;
+    function ScriptTranslateText(AVars: TVariableSet): TScriptResult;
     procedure SelectionInstanceOnRun(AInstance: TLazPaintCustomInstance);
     procedure ToolFillChanged(Sender: TObject);
     procedure PythonScriptCommand({%H-}ASender: TObject; ACommand, AParam: UTF8String; out
@@ -267,7 +268,7 @@ type
 
 implementation
 
-uses LCLType, Types, Forms, Dialogs, FileUtil, StdCtrls, LCLIntf, BGRAUTF8,
+uses LCLType, Types, Forms, Dialogs, FileUtil, StdCtrls, LCLIntf, BGRAUTF8, UTranslation,
 
      URadialBlur, UMotionBlur, UEmboss, UTwirl, UWaveDisplacement,
      unewimage, uresample, UPixelate, unoisefilter, ufilters,
@@ -394,6 +395,7 @@ begin
   ScriptContext.RegisterScriptFunction('ShowDirectoryDialog',@ScriptShowDirectoryDialog,ARegister);
   ScriptContext.RegisterScriptFunction('InputBox',@ScriptInputBox,ARegister);
   ScriptContext.RegisterScriptFunction('LazPaintGetVersion',@ScriptLazPaintGetVersion,ARegister);
+  ScriptContext.RegisterScriptFunction('TranslateText',@ScriptTranslateText,ARegister);
 end;
 
 function TLazPaintInstance.ScriptFileGetTemporaryName(AVars: TVariableSet): TScriptResult;

+ 38 - 2
lazpaint/utranslation.pas

@@ -30,12 +30,16 @@ function LazPaintLanguageFile(ALanguage: string): string;
 procedure FillLanguageList(AConfig: TLazPaintConfig);
 procedure TranslateLazPaint(AConfig: TIniFile);
 function GetResourcePath(AResource: string): string;
+function DoTranslate(AId, AText: string): string;
 
 implementation
 
 uses Forms, LCLProc, LazUTF8, BGRAUTF8, LCLTranslator, LResources, Translations,
   LazPaintType, LCVectorOriginal;
 
+var
+  FMainPoFile: TPOFile;
+
 {$ifdef Darwin}
 function GetDarwinResourcesPath: string;
 var
@@ -84,6 +88,37 @@ begin
   {$ENDIF}
 end;
 
+function DoTranslate(AId, AText: string): string;
+var
+  item: TPOFileItem;
+begin
+  if Assigned(FMainPoFile) then
+  begin
+    item := FMainPoFile.FindPoItem(AId);
+    if (AId <> '') and Assigned(item) then
+      exit(item.Translation) else
+    begin
+      item := FMainPoFile.OriginalToItem(AText);
+      if Assigned(item) then exit(item.Translation) else
+      begin
+        item := FMainPoFile.OriginalToItem(AText+':');
+        if item = nil then item := FMainPoFile.OriginalToItem(AText+' :');
+        if Assigned(item) then
+        begin
+          result := item.Translation.TrimRight;
+          if result.EndsWith(':') then
+          begin
+            delete(result, length(result), 1);
+            result := result.TrimRight;
+          end;
+          exit;
+        end;
+      end;
+    end;
+  end;
+  result := AText;
+end;
+
 function LanguagePathUTF8: string;
 begin
   result := GetResourcePath('i18n');
@@ -127,8 +162,9 @@ begin
 
   if FileExistsUTF8(POFile) then
   begin
-    LRSTranslator:=TPoTranslator.Create(POFile);
-    TranslateResourceStrings(POFile);
+    FMainPoFile := TPOFile.Create(POFile, true);
+    LRSTranslator:=TPoTranslator.Create(FMainPoFile);
+    TranslateResourceStrings(FMainPoFile);
     ActiveLanguage:= Language;
   end;
 

+ 9 - 6
resources/scripts/layerfx_innerlight.py

@@ -13,8 +13,11 @@ except ImportError:
 from lazpaint import colors, image, layer, filters, tools, selection
 import math
 
+english = ["Layer is empty", "Radius", "Angle", "Opacity", "Ok", "Cancel"]
+translation = dict(zip(english, dialog.translate_text(english)))
+
 if layer.is_empty():
-    dialog.show_message("Layer is empty")
+    dialog.show_message(translation["Layer is empty"])
     exit()
 
 ############ image processing
@@ -221,19 +224,19 @@ window.resizable(False, False)
 frame = Frame(window)
 frame.pack()
 
-label_radius = Label(frame, text="Radius:")
+label_radius = Label(frame, text=translation["Radius"])
 label_radius.grid(column=0, row=0)
 scale_radius = Scale(frame, from_=0, to=MAX_RADIUS, orient=HORIZONTAL, command=scale_radius_update)
 scale_radius.grid(column=1, row=0, sticky=W+E, padx=10)
 scale_radius.set(chosen_radius)
 
-label_angle = Label(frame, text="Angle:")
+label_angle = Label(frame, text=translation["Angle"])
 label_angle.grid(column=0, row=1)
 scale_angle = Scale(frame, from_=0, to=MAX_ANGLE, orient=HORIZONTAL, command=scale_angle_update)
 scale_angle.grid(column=1, row=1, sticky=W+E, padx=10)
 scale_angle.set(chosen_angle)
 
-label_opacity = Label(frame, text="Opacity:")
+label_opacity = Label(frame, text=translation["Opacity"])
 label_opacity.grid(column=0, row=2)
 scale_opacity = Scale(frame, from_=0, to=MAX_OPACITY, orient=HORIZONTAL, command=scale_opacity_update)
 scale_opacity.grid(column=1, row=2, sticky=W+E, padx=10)
@@ -245,9 +248,9 @@ frame.rowconfigure(0, pad=20)
 frame.rowconfigure(1, pad=20)
 frame.rowconfigure(2, pad=20)
 
-button_ok = Button(window, text="Ok", command=button_ok_click)
+button_ok = Button(window, text=translation["Ok"], command=button_ok_click)
 button_ok.pack(side=RIGHT, padx=10, pady=10)
-button_cancel = Button(window, text="Cancel", command=button_cancel_click)
+button_cancel = Button(window, text=translation["Cancel"], command=button_cancel_click)
 button_cancel.pack(side=RIGHT, pady=10)
 
 image.do_begin()

+ 9 - 6
resources/scripts/layerfx_innershadow.py

@@ -13,8 +13,11 @@ except ImportError:
 from lazpaint import colors, image, layer, filters, tools, selection
 import math
 
+english = ["Layer is empty", "Radius", "Angle", "Opacity", "Ok", "Cancel"]
+translation = dict(zip(english, dialog.translate_text(english)))
+
 if layer.is_empty():
-    dialog.show_message("Layer is empty")
+    dialog.show_message(translation["Layer is empty"])
     exit()
 
 ############ image processing
@@ -221,19 +224,19 @@ window.resizable(False, False)
 frame = Frame(window)
 frame.pack()
 
-label_radius = Label(frame, text="Radius:")
+label_radius = Label(frame, text=translation["Radius"])
 label_radius.grid(column=0, row=0)
 scale_radius = Scale(frame, from_=0, to=MAX_RADIUS, orient=HORIZONTAL, command=scale_radius_update)
 scale_radius.grid(column=1, row=0, sticky=W+E, padx=10)
 scale_radius.set(chosen_radius)
 
-label_angle = Label(frame, text="Angle:")
+label_angle = Label(frame, text=translation["Angle"])
 label_angle.grid(column=0, row=1)
 scale_angle = Scale(frame, from_=0, to=MAX_ANGLE, orient=HORIZONTAL, command=scale_angle_update)
 scale_angle.grid(column=1, row=1, sticky=W+E, padx=10)
 scale_angle.set(chosen_angle)
 
-label_opacity = Label(frame, text="Opacity:")
+label_opacity = Label(frame, text=translation["Opacity"])
 label_opacity.grid(column=0, row=2)
 scale_opacity = Scale(frame, from_=0, to=MAX_OPACITY, orient=HORIZONTAL, command=scale_opacity_update)
 scale_opacity.grid(column=1, row=2, sticky=W+E, padx=10)
@@ -245,9 +248,9 @@ frame.rowconfigure(0, pad=20)
 frame.rowconfigure(1, pad=20)
 frame.rowconfigure(2, pad=20)
 
-button_ok = Button(window, text="Ok", command=button_ok_click)
+button_ok = Button(window, text=translation["Ok"], command=button_ok_click)
 button_ok.pack(side=RIGHT, padx=10, pady=10)
-button_cancel = Button(window, text="Cancel", command=button_cancel_click)
+button_cancel = Button(window, text=translation["Cancel"], command=button_cancel_click)
 button_cancel.pack(side=RIGHT, pady=10)
 
 image.do_begin()

+ 10 - 7
resources/scripts/layerfx_shadow.py

@@ -12,8 +12,11 @@ except ImportError:
         
 from lazpaint import colors, image, layer, filters, tools, selection
 
+english = ["Layer is empty", "Shadow of ", "Radius", "Offset", "Opacity", "Ok", "Cancel"]
+translation = dict(zip(english, dialog.translate_text(english)))
+
 if layer.is_empty():
-    dialog.show_message("Layer is empty")
+    dialog.show_message(translation["Layer is empty"])
     exit()
 
 ############ image processing
@@ -65,7 +68,7 @@ def create_shadow_layer():
         layer.remove()
     layer.select_id(source_layer_id)
     layer.duplicate()
-    layer.set_name("Shadow of "+source_layer_name)
+    layer.set_name(translation["Shadow of "]+source_layer_name)
     layer.set_registry("shadow-source-layer-id", source_layer_id)
     shadow_layer_id = layer.get_id()
     shadow_index = image.get_layer_index()
@@ -176,13 +179,13 @@ window.resizable(False, False)
 frame = Frame(window)
 frame.pack()
 
-label_radius = Label(frame, text="Radius:")
+label_radius = Label(frame, text=translation["Radius"])
 label_radius.grid(column=0, row=0)
 scale_radius = Scale(frame, from_=0, to=MAX_RADIUS, orient=HORIZONTAL, command=scale_radius_update)
 scale_radius.grid(column=1, row=0, sticky=W+E, padx=10)
 scale_radius.set(chosen_radius)
 
-label_offset = Label(frame, text="Offset:")
+label_offset = Label(frame, text=translation["Offset"])
 label_offset.grid(column=0, row=1)
 scale_offset_x = Scale(frame, from_=-MAX_OFFSET, to=MAX_OFFSET, orient=HORIZONTAL, command=scale_offset_update)
 scale_offset_x.grid(column=1, row=1, sticky=W+E, padx=10)
@@ -191,7 +194,7 @@ scale_offset_y = Scale(frame, from_=-MAX_OFFSET, to=MAX_OFFSET, orient=HORIZONTA
 scale_offset_y.grid(column=1, row=2, sticky=W+E, padx=10)
 scale_offset_y.set(chosen_offset[1])
 
-label_opacity = Label(frame, text="Opacity:")
+label_opacity = Label(frame, text=translation["Opacity"])
 label_opacity.grid(column=0, row=3)
 scale_opacity = Scale(frame, from_=0, to=MAX_OPACITY, orient=HORIZONTAL, command=scale_opacity_update)
 scale_opacity.grid(column=1, row=3, sticky=W+E, padx=10)
@@ -204,9 +207,9 @@ frame.rowconfigure(1, pad=20)
 frame.rowconfigure(2, pad=20)
 frame.rowconfigure(3, pad=20)
 
-button_ok = Button(window, text="Ok", command=button_ok_click)
+button_ok = Button(window, text=translation["Ok"], command=button_ok_click)
 button_ok.pack(side=RIGHT, padx=10, pady=10)
-button_cancel = Button(window, text="Cancel", command=button_cancel_click)
+button_cancel = Button(window, text=translation["Cancel"], command=button_cancel_click)
 button_cancel.pack(side=RIGHT, pady=10)
 
 image.do_begin()

+ 10 - 7
resources/scripts/layerfx_stroke.py

@@ -12,8 +12,11 @@ except ImportError:
         
 from lazpaint import colors, image, layer, filters, tools, selection
 
+english = ["Layer is empty", "Radius", "Color", "Opacity", "Ok", "Cancel"]
+translation = dict(zip(english, dialog.translate_text(english)))
+
 if layer.is_empty():
-    dialog.show_message("Layer is empty")
+    dialog.show_message(translation["Layer is empty"])
     exit()
 
 ############ image processing
@@ -176,21 +179,21 @@ window.resizable(False, False)
 frame = Frame(window)
 frame.pack()
 
-label_radius = Label(frame, text="Radius:")
+label_radius = Label(frame, text=translation["Radius"])
 label_radius.grid(column=0, row=0)
 scale_radius = Scale(frame, from_=0, to=MAX_RADIUS, orient=HORIZONTAL, command=scale_radius_update)
 scale_radius.grid(column=1, row=0, sticky=W+E, padx=10)
 scale_radius.set(chosen_radius)
 
-label_opacity = Label(frame, text="Opacity:")
+label_opacity = Label(frame, text=translation["Opacity"])
 label_opacity.grid(column=0, row=1)
 scale_opacity = Scale(frame, from_=0, to=MAX_OPACITY, orient=HORIZONTAL, command=scale_opacity_update)
 scale_opacity.grid(column=1, row=1, sticky=W+E, padx=10)
 scale_opacity.set(chosen_opacity)
 
-label_color = Label(frame, text="Color:")
+label_color = Label(frame, text=translation["Color"])
 label_color.grid(column=0, row=2)
-button_color = Button(frame, text="Color...", command=button_color_click)
+button_color = Button(frame, text=translation["Color"] + "...", command=button_color_click)
 button_color.grid(column=1, row=2)
 
 frame.columnconfigure(0, pad=20)
@@ -199,9 +202,9 @@ frame.rowconfigure(0, pad=20)
 frame.rowconfigure(1, pad=20)
 frame.rowconfigure(2, pad=20)
 
-button_ok = Button(window, text="Ok", command=button_ok_click)
+button_ok = Button(window, text=translation["Ok"], command=button_ok_click)
 button_ok.pack(side=RIGHT, padx=10, pady=10)
-button_cancel = Button(window, text="Cancel", command=button_cancel_click)
+button_cancel = Button(window, text=translation["Cancel"], command=button_cancel_click)
 button_cancel.pack(side=RIGHT, pady=10)
 
 image.do_begin()

+ 3 - 1
resources/scripts/lazpaint/dialog.py

@@ -15,5 +15,7 @@ def input_value(prompt, default):
   return ast.literal_eval(input_text(prompt, str(default)))
 
 def show_color_dialog(color=None) -> str:
-  return command.send('ShowColorDialog?', Color=color);
+  return command.send('ShowColorDialog?', Color=color)
 
+def translate_text(text):
+  return command.send('TranslateText?', Text=text)