View Issue Details

IDProjectCategoryView StatusLast Update
0035432LazarusLCLpublic2019-08-19 14:17
ReporterDavidAssigned ToMaxim Ganetsky 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionreopened 
Product Version2.0.3 (SVN)Product Build 
Target VersionFixed in Version2.2 
Summary0035432: Command line switch for language non-standard
DescriptionThe command line switch to switch an application to a specific language relies on a space between the --lang and the desired value. For example, to select the Spanish language, you would put "--lang es" on the command line. However, the normal approach for long command line arguments in Lazarus applications is to separate the switch from a value using an equals sign - "--lang=es"

The attached patch retains the spaced based behaviour but also allows the Lazarus style '=' one as well.

Davo
Steps To ReproduceIn a simple application, add LCLTranslator, DefaultTranslator; to the uses clause and provide appropriate po or mo files in, eg, ./locale that support another language (for as a minium, the form's caption, "Form1"). Set run time parameter or start the app from the command line eg

./project1 --lang es <enter>

The 'es' above indicates spanish and will require a translated messages file, ./locale/project1.es.mo

Repeat the exercise with a more Lazarus like syntax -

./project1 --lang=es <enter>

And it won't change from the default language.
Additional InformationI have only tested on Linux but having looked at the existing code, seems pretty sure its a cross platform issue and a cross platform solution.
TagsNo tags attached.
Fixed in Revision61041
LazTarget-
Widgetset
Attached Files
  • Lang_switch.patch (772 bytes)
    Index: lcl/lcltranslator.pas
    ===================================================================
    --- lcl/lcltranslator.pas	(revision 60923)
    +++ lcl/lcltranslator.pas	(working copy)
    @@ -263,6 +263,8 @@
     begin
       Result := '';
     
    +  if Application.HasOption('l', 'lang') then
    +    lang := Application.GetOptionValue('l', 'lang');
       if Lang = '' then
         for i := 1 to Paramcount - 1 do
           if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    @@ -269,7 +271,7 @@
             (ParamStrUTF8(i) = '--lang') then
             Lang := ParamStrUTF8(i + 1);
     
    -  //Win32 user may decide to override locale with LANG variable.
    +  //Win32 and Linux user may decide to override locale with LANG variable.
       if Lang = '' then
         Lang := GetEnvironmentVariableUTF8('LANG');
     
    
    Lang_switch.patch (772 bytes)

Activities

David

2019-04-23 14:04

reporter  

Lang_switch.patch (772 bytes)
Index: lcl/lcltranslator.pas
===================================================================
--- lcl/lcltranslator.pas	(revision 60923)
+++ lcl/lcltranslator.pas	(working copy)
@@ -263,6 +263,8 @@
 begin
   Result := '';
 
+  if Application.HasOption('l', 'lang') then
+    lang := Application.GetOptionValue('l', 'lang');
   if Lang = '' then
     for i := 1 to Paramcount - 1 do
       if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
@@ -269,7 +271,7 @@
         (ParamStrUTF8(i) = '--lang') then
         Lang := ParamStrUTF8(i + 1);
 
-  //Win32 user may decide to override locale with LANG variable.
+  //Win32 and Linux user may decide to override locale with LANG variable.
   if Lang = '' then
     Lang := GetEnvironmentVariableUTF8('LANG');
 
Lang_switch.patch (772 bytes)

Maxim Ganetsky

2019-04-24 02:02

developer   ~0115756

I decided not to rely on Application object availability, just to be on the safe side.

Please test and close if OK.

David

2019-06-16 11:32

reporter   ~0116747

Tested, all good.
Thanks Maxim.

David

2019-08-19 14:17

reporter   ~0117736

This fix has not made it into 2.0.4 nor fixes. Its not listed to be merged on the wiki.
Can I ask that it happen please ?

Issue History

Date Modified Username Field Change
2019-04-23 14:04 David New Issue
2019-04-23 14:04 David File Added: Lang_switch.patch
2019-04-24 01:33 Maxim Ganetsky Assigned To => Maxim Ganetsky
2019-04-24 01:33 Maxim Ganetsky Status new => assigned
2019-04-24 02:02 Maxim Ganetsky Status assigned => resolved
2019-04-24 02:02 Maxim Ganetsky Resolution open => fixed
2019-04-24 02:02 Maxim Ganetsky Fixed in Version => 2.2
2019-04-24 02:02 Maxim Ganetsky Fixed in Revision => 61041
2019-04-24 02:02 Maxim Ganetsky LazTarget => -
2019-04-24 02:02 Maxim Ganetsky Note Added: 0115756
2019-06-16 11:32 David Status resolved => closed
2019-06-16 11:32 David Note Added: 0116747
2019-08-19 14:17 David Status closed => assigned
2019-08-19 14:17 David Resolution fixed => reopened
2019-08-19 14:17 David Note Added: 0117736