How to work with system/user parameters.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

How to work with system/user parameters.

Post 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
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post 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"
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: How to work with system/user parameters.

Post 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.
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: How to work with system/user parameters.

Post 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.
Attachments
Fig4. After pressing save parameters
Fig4. After pressing save parameters
Знімок екрана з 2022-06-29 19-48-30.png (120.26 KiB) Viewed 1086 times
Fig3. Open Preferences tab
Fig3. Open Preferences tab
Знімок екрана з 2022-06-29 19-47-33.png (154.99 KiB) Viewed 1086 times
Fig2. After run and exit on "fresh" system
Fig2. After run and exit on "fresh" system
Знімок екрана з 2022-06-29 19-46-53.png (172.25 KiB) Viewed 1086 times
Fig1. First run on "fresh" system
Fig1. First run on "fresh" system
Знімок екрана з 2022-06-29 19-46-40.png (119.87 KiB) Viewed 1086 times
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post 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.
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: How to work with system/user parameters.

Post 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?
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post 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
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post 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?
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post by adrianinsaval »

@Kuzma30 I did a draft PR changing those, please test https://github.com/FreeCAD/FreeCAD/pull/7119
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: How to work with system/user parameters.

Post 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.
Post Reply