How to work with system/user parameters.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
How to work with system/user parameters.
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
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
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
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.
Thank's this help.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"
Need test how it work with translated texts.
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
Re: How to work with system/user parameters.
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.
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
- Знімок екрана з 2022-06-29 19-48-30.png (120.26 KiB) Viewed 1182 times
-
- Fig3. Open Preferences tab
- Знімок екрана з 2022-06-29 19-47-33.png (154.99 KiB) Viewed 1182 times
-
- Fig2. After run and exit on "fresh" system
- Знімок екрана з 2022-06-29 19-46-53.png (172.25 KiB) Viewed 1182 times
-
- Fig1. First run on "fresh" system
- Знімок екрана з 2022-06-29 19-46-40.png (119.87 KiB) Viewed 1182 times
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
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.
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?
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
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
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?
what for? when a config is not present it's supposed to use the default value
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
this: https://github.com/FreeCAD/FreeCAD/blob ... New.py#L25 should probably be changed to
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?
Code: Select all
FreeCADGui.runCommand('Std_New')
On a separate note, why shouldn't the stuff in App have translation? Doesn't Qt have support for translating command line apps too?
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
@Kuzma30 I did a draft PR changing those, please test https://github.com/FreeCAD/FreeCAD/pull/7119
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: How to work with system/user parameters.
according to this post: https://forum.freecadweb.org/viewtopic. ... 30#p600030 it might be possible to translate stuff at the App level now.