Page 1 of 2

How to work with system/user parameters.

Posted: Tue Jun 28, 2022 2:43 pm
by Kuzma30
I make string parameter in Preferences -> General -> Document, I need set default value for it when there are no config files yet (like fresh install).

My code partially work. When there is no config files (I delete it) if you open Preferences, I can see New Document Name (my parameter) = "Unnamed". Then if I exit from Preferences dialog without saving parameter I get empty string in my code. If I save parameters, then It read OK.
https://github.com/Kuzma30/FreeCAD/comm ... 2cabfd4c0f
On src/App/Application.cpp I want to read this string.
src/Gui/DlgSettingsDocumentImp.cpp I trying to catch situation when user leave empty string.

https://github.com/Kuzma30/FreeCAD/comm ... fd93743ca7 this code to add string to .ui

Re: How to work with system/user parameters.

Posted: Tue Jun 28, 2022 3:58 pm
by adrianinsaval
IIRC the second argument of GetASCII (you used just "" in your code) is the default value to be used when the parameter doesn't exist, at least that is how it works in python, try changing that to "Unnamed"

Re: How to work with system/user parameters.

Posted: Tue Jun 28, 2022 4:49 pm
by Kuzma30
adrianinsaval wrote: Tue Jun 28, 2022 3:58 pm IIRC the second argument of GetASCII (you used just "" in your code) is the default value to be used when the parameter doesn't exist, at least that is how it works in python, try changing that to "Unnamed"
Thank's this help.
Need test how it work with translated texts.

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 4:35 am
by Kuzma30
Test with translation
Looks like FreeCAD create "full" config files after you open Preferences and press Apply or OK. (see file sizes on Fig1 -Fig4)
On Fig3 new document's name is translated ("Без Назви").
Result - translation of parameter working if I simply open Preferences tab and save parameters.

This is not what I want. I want make it work on "fresh" system without need open Preferences.

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 11:26 am
by adrianinsaval
IMO translated words should not be saved on a parameter, better to use an empty string as default and in code have a conditional to use a translated string instead of the parameter when it is empty.

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 1:56 pm
by Kuzma30
Big problem that I use this parameter in src/App/Application.cpp. All files in this directory Yorik want leave "translation free". If you know how to transfer translated text to variable for new document it's will be great. I am trying do this with parameter.

When I use userName = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Document")->GetASCII("prefNewDocumentName","");
it return empty string...

Not related to "new name" issues question. Why FreeCAD don't create all config files on first "fresh" start?

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 2:28 pm
by adrianinsaval
Kuzma30 wrote: Thu Jun 30, 2022 1:56 pm Big problem that I use this parameter in src/App/Application.cpp. All files in this directory Yorik want leave "translation free"
Then IMO it is better to leave untranslated or find a way to translate on GUI only, parameters is no place for translation strings IMO, when you change language the parameter will not be updated.
Looks like it should be translated at creation: https://github.com/FreeCAD/FreeCAD/blob ... c.cpp#L607
where are you getting it untranslated?
Kuzma30 wrote: Thu Jun 30, 2022 1:56 pm Not related to "new name" issues question. Why FreeCAD don't create all config files on first "fresh" start?
what for? when a config is not present it's supposed to use the default value

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 3:03 pm
by adrianinsaval
this: https://github.com/FreeCAD/FreeCAD/blob ... New.py#L25 should probably be changed to

Code: Select all

FreeCADGui.runCommand('Std_New')
this: https://github.com/FreeCAD/FreeCAD/blob ... .cpp#L1276 also needs changing, either include the translated name in the newDocument call or use Std_New instead

On a separate note, why shouldn't the stuff in App have translation? Doesn't Qt have support for translating command line apps too?

Re: How to work with system/user parameters.

Posted: Thu Jun 30, 2022 4:02 pm
by adrianinsaval
@Kuzma30 I did a draft PR changing those, please test https://github.com/FreeCAD/FreeCAD/pull/7119

Re: How to work with system/user parameters.

Posted: Sat Jul 09, 2022 4:31 pm
by adrianinsaval
according to this post: https://forum.freecadweb.org/viewtopic. ... 30#p600030 it might be possible to translate stuff at the App level now.