View Issue Details

IDProjectCategoryView StatusLast Update
0023986LazarusLCLpublic2013-03-04 14:54
ReporterMario Ray MahardhikaAssigned ToMaxim Ganetsky 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.1 (SVN)Product Build40323 
Target VersionFixed in Version1.1 (SVN) 
Summary0023986: Code optimization in DefaultTranslator unit
DescriptionThe attached patch reduces the amount of repeated code in DefaultTranslator unit
TagsNo tags attached.
Fixed in Revision40470
LazTarget-
Widgetset
Attached Files
  • defaulttranslator.diff (6,327 bytes)
    Index: defaulttranslator.pas
    ===================================================================
    --- defaulttranslator.pas	(revision 40323)
    +++ defaulttranslator.pas	(working copy)
    @@ -87,78 +87,74 @@
       function GetLocaleFileName(const LangID, LCExt: string): string;
       var
         LangShortID: string;
    +    AppDir,LCFileName,FullLCFileName: String;
       begin
         if LangID <> '' then
         begin
    +      AppDir := ExtractFilePath(ParamStrUTF8(0));
    +      LCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
    +
           //ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + LangID +
    -        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + LangID + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + LangID +
    -        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'languages' + DirectorySeparator + LangID +
    +        DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
    -        + LangID + DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'locale' + DirectorySeparator + LangID +
    +        DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
    -        + LangID + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'locale' + DirectorySeparator + LangID +
    +        DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
           {$IFDEF UNIX}
           //In unix-like systems we can try to search for global locale
    -      Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
           {$ENDIF}
           //Let us search for reducted files
           LangShortID := copy(LangID, 1, 2);
           //At first, check all was checked
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + LangShortID +
    -        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + LangShortID + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
    -        LangShortID + DirectorySeparator + ChangeFileExt(
    -        ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'languages' + DirectorySeparator +
    +        LangShortID + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
    -        + LangShortID + DirectorySeparator + ChangeFileExt(
    -        ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'locale' + DirectorySeparator
    +        + LangShortID + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
    -        + LangShortID + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +      Result := AppDir + 'locale' + DirectorySeparator + LangShortID +
    +        DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
           //Full language in file name - this will be default for the project
           //We need more careful handling, as it MAY result in incorrect filename
           try
    -        Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
    +        Result := AppDir + FullLCFileName;
             if FileExistsUTF8(Result) then
               exit;
             //Common location (like in Lazarus)
    -        Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
    -          ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
    +        Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
             if FileExistsUTF8(Result) then
               exit;
     
    -        Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' +
    -          DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
    +        Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
             if FileExistsUTF8(Result) then
               exit;
           except
    @@ -166,22 +162,22 @@
           end;
           {$IFDEF UNIX}
           Result := '/usr/share/locale/' + LangShortID + '/LC_MESSAGES/' +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    +        LCFileName;
           if FileExistsUTF8(Result) then
             exit;
           {$ENDIF}
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(
    -        ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
    +
    +      FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
    +
    +      Result := AppDir + FullLCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
    +      Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
           if FileExistsUTF8(Result) then
             exit;
     
    -      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
    -        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
    +      Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
           if FileExistsUTF8(Result) then
             exit;
         end;
    
    defaulttranslator.diff (6,327 bytes)

Activities

Mario Ray Mahardhika

2013-03-03 14:36

reporter  

defaulttranslator.diff (6,327 bytes)
Index: defaulttranslator.pas
===================================================================
--- defaulttranslator.pas	(revision 40323)
+++ defaulttranslator.pas	(working copy)
@@ -87,78 +87,74 @@
   function GetLocaleFileName(const LangID, LCExt: string): string;
   var
     LangShortID: string;
+    AppDir,LCFileName,FullLCFileName: String;
   begin
     if LangID <> '' then
     begin
+      AppDir := ExtractFilePath(ParamStrUTF8(0));
+      LCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
+
       //ParamStrUTF8(0) is said not to work properly in linux, but I've tested it
-      Result := ExtractFilePath(ParamStrUTF8(0)) + LangID +
-        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + LangID + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + LangID +
-        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'languages' + DirectorySeparator + LangID +
+        DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
-        + LangID + DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'locale' + DirectorySeparator + LangID +
+        DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
-        + LangID + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'locale' + DirectorySeparator + LangID +
+        DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
       {$IFDEF UNIX}
       //In unix-like systems we can try to search for global locale
-      Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := '/usr/share/locale/' + LangID + '/LC_MESSAGES/' + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
       {$ENDIF}
       //Let us search for reducted files
       LangShortID := copy(LangID, 1, 2);
       //At first, check all was checked
-      Result := ExtractFilePath(ParamStrUTF8(0)) + LangShortID +
-        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + LangShortID + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
-        LangShortID + DirectorySeparator + ChangeFileExt(
-        ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'languages' + DirectorySeparator +
+        LangShortID + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
-        + LangShortID + DirectorySeparator + ChangeFileExt(
-        ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'locale' + DirectorySeparator
+        + LangShortID + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
-        + LangShortID + DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+      Result := AppDir + 'locale' + DirectorySeparator + LangShortID +
+        DirectorySeparator + 'LC_MESSAGES' + DirectorySeparator + LCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
       //Full language in file name - this will be default for the project
       //We need more careful handling, as it MAY result in incorrect filename
       try
-        Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
+        Result := AppDir + FullLCFileName;
         if FileExistsUTF8(Result) then
           exit;
         //Common location (like in Lazarus)
-        Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
-          ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
+        Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
         if FileExistsUTF8(Result) then
           exit;
 
-        Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' +
-          DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangID) + LCExt;
+        Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
         if FileExistsUTF8(Result) then
           exit;
       except
@@ -166,22 +162,22 @@
       end;
       {$IFDEF UNIX}
       Result := '/usr/share/locale/' + LangShortID + '/LC_MESSAGES/' +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
+        LCFileName;
       if FileExistsUTF8(Result) then
         exit;
       {$ENDIF}
-      Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(
-        ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
+
+      FullLCFileName := ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
+
+      Result := AppDir + FullLCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
+      Result := AppDir + 'locale' + DirectorySeparator + FullLCFileName;
       if FileExistsUTF8(Result) then
         exit;
 
-      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
-        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), '.' + LangShortID) + LCExt;
+      Result := AppDir + 'languages' + DirectorySeparator + FullLCFileName;
       if FileExistsUTF8(Result) then
         exit;
     end;
defaulttranslator.diff (6,327 bytes)

Maxim Ganetsky

2013-03-03 23:29

developer   ~0065998

Applied, thanks.

You are added to contributors list.

Issue History

Date Modified Username Field Change
2013-03-03 14:36 Mario Ray Mahardhika New Issue
2013-03-03 14:36 Mario Ray Mahardhika File Added: defaulttranslator.diff
2013-03-03 22:38 Maxim Ganetsky Assigned To => Maxim Ganetsky
2013-03-03 22:38 Maxim Ganetsky Status new => assigned
2013-03-03 23:29 Maxim Ganetsky Fixed in Revision => 40470
2013-03-03 23:29 Maxim Ganetsky LazTarget => -
2013-03-03 23:29 Maxim Ganetsky Note Added: 0065998
2013-03-03 23:29 Maxim Ganetsky Status assigned => resolved
2013-03-03 23:29 Maxim Ganetsky Fixed in Version => 1.1 (SVN)
2013-03-03 23:29 Maxim Ganetsky Resolution open => fixed
2013-03-04 14:54 Mario Ray Mahardhika Status resolved => closed