Is it possible to get or edit the user servoy.properties file?
I know I can add properties by doing ```
application.setUserProperty(‘showOrders’,‘1’)
but I also like to be able to set the language, font and LAF settings at startup per user.
Is it possible to get or edit the user servoy.properties file?
I know I can add properties by doing ```
application.setUserProperty(‘showOrders’,‘1’)
but I also like to be able to set the language, font and LAF settings at startup per user.
Hi Karel,
freecolours:
Is it possible to get or edit the user servoy.properties file?
I know I can add properties by doing ```
application.setUserProperty(‘showOrders’,‘1’)but I also like to be able to set the language, font and LAF settings at startup per user.
You mixing 2 things up here.
The servoy.properties file is on the server and setUserProperty won’t touch that file.
Instead it set/gets things in the servoy_client.properties file. This file is located in the .servoy directory that is located in the users home directory.
Using application.setUserProperty(‘showOrders’,‘1’) will add a property named user.showOrders=1;
The font property is ‘font=’.
So what you want is not possible right now. I suggest you file a feature request.
Another way to control the font issue is to use a stylesheet and set that when a user logs in. Downside of this is that you need to reload the solution if you want to reset this when you want another user to log into the same solution instance.
Hope this helps.
freecolours:
Is it possible to get or edit the user servoy.properties file?
Re-reading this line I see you meant the servoy_client.properties file.
ROCLASI:
freecolours:
Is it possible to get or edit the user servoy.properties file?Re-reading this line I see you meant the servoy_client.properties file.
Yes, sorry about that… I meant the servoy_client.properties file…
It shouldn’t be that hard to get / set info from that file, wouldn’t it?
Well you could use the file plugin to edit the file. That doesn’t mean that Servoy client will use it for that session though.
It would most likely require a restart of the client.
So come to think of it what you actually want is to set the properties for that session only in memory.
It is fairly easy to do this in a plugin and is a lot safer. We are using this in our inhouse toolkit plugin for example to read the last logged in user name. If you edit the file by “hand”, you risk that your changes are overwritten when Servoy is quit. Sounds like a great addition to the tools plugin of Marcel.
I once had this for the server properties but removed it.
It is potentially dangerous when you don’t really know what you are doing.
When you are already able to edit client properties you can simply find out what the property name for locale etc is and use that to edit the property. Or do I miss something?
BTW setting a property on startup will 90% sure not edit the properties for that session! As soon as those properties are available they are already read by Servoy. Stuff like locale etc. is, if I am not mistaken, set at startup…
What I want is be able to set the language, LAF and Font properties in my solution, instead of having the client doing that in the Rich Client Preferences. If the client changes his (own) user settings, restarting is indeed required…
See the language settings at the user info dialog below:
Issue is, that when I set the i18n language at user login, some labels still display (wrong) language values, set from the servoy_client.properties language.
So if I can set the servoy_client.properties language, I wouldn’t have that issue at all…
patrick:
Sounds like a great addition to the tools plugin of Marcel.
I do think so too
So, the anwer remains to be the same I guess.
use application.setUserProperty but use one of these (and many other) property names/values:
locale.dateformat=dd-MM-yyyy
locale.default=en,US,
locale.integerformat=\#\#\#\#
locale.numberformat=\#.\#\#
I really don’t see why this should be done in a plug-in
IT2Be:
So, the anwer remains to be the same I guess.use application.setUserProperty but use one of these (and many other) property names/values:
locale.dateformat=dd-MM-yyyy
locale.default=en,US,
locale.integerformat=####
locale.numberformat=#.##
I really don't see why this should be done in a plug-in <img src="{SMILIES_PATH}/icon_question.gif" alt=":?:" title="Question" />
If that would work, then I’m happy enough… but that doesn’t work…
You only can set/get a ‘custom’ user.something property.
I wrote a method that writes the user properties (again) with new settings.
This way I’m able to edit any property, but you need to know what the properties need to look like.
I used Marcel’s data plugin for reading the file (and avoiding a Select File dialog) and Marcel’s Tools plugin to get the users home directory and servoy_client.properties file.
//get user properties file location (using IT2BE Tool plug)
var _homePath = plugins.it2be_tools.client().userHome,
_file = _homePath + '\\' + '.servoy' + '\\' + 'servoy_client.properties',
//get text from properties file into an array (using IT2BE Data plug)
_textArray = plugins.it2be_data.txt().getArray(_file, true),
_size,
_name,
_newText = new Array(),
_counter = 0,
_language = language_key;
//loop through text
for (_size in _textArray)
{
_name = _textArray[_size][0]
//write new array, but ommit local properties line
if(utils.stringLeft(_name, 14) != 'locale.default') {
_newText[_counter] = _name
_counter++
}
}
//add user language property to array
_newText.push('locale.default=' + _language.toLowerCase() + ',' + _language.toUpperCase())
//make a proper textfile
_newText = _newText.join('\n')
//write new properties
var _succes = plugins.file.writeTXTFile(_file,_newText)
It’s doable, but I think this would be a lot nicer :
i18n.setDefaultLocale(language, country)
and what is wrong with:
i18n.setLocale(String language, String country)
Hi Karel, still don’t get it,
because this:
//Set the locale, all forms not yet loaded will change (execeute this in solution startup or first form)
//The language argument is a valid ISO Language Code.
//These codes are the lower-case, two-letter codes as defined by ISO-639.
//You can find a full list of these codes at a number of sites, such as:
//http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
//The country argument is a valid ISO Country Code.
//These codes are the upper-case, two-letter codes as defined by ISO-3166.
//You can find a full list of these codes at a number of sites, such as:
//http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
//Warning: already created form elements with i18n text lookup will not change,
//so call this method in the solution startup method or in methods from first form
i18n.setLocale('en','US');
does the same??
ah Johan, you beat me!
jcompagner:
and what is wrong with:
i18n.setLocale(String language, String country)
I use my own security, so my first login form contains labels set by the default language in the servoy_client.properties file.
The solution only knows which language to use AFTER the client performs his first login.
Problem with this is, that some buttons on the second form (after the login form) do not display the user language, but the default language from the properties file.
My solution to this issue is to set the default language in the servoy_client.properties, but this might be solved in another way?
just set the default_language that you want to have in the solution startup method. as the first thing. Then it goes fine.
also don’t touch the second form at any place when your are going/showing the login form. fist call setLocale before you touch anything else and it should go ok
you can fix that, by making your login screen a seperate solution/module.
After setting the locale, you do:
application.closeSolution(myOtherSolution)
HJK:
//Warning: already created form elements with i18n text lookup will not change,
//so call this method in the solution startup method or in methods from first form
This is indeed the actual issue…
HJK:
you can fix that, by making your login screen a seperate solution/module.
After setting the locale, you do:application.closeSolution(myOtherSolution)
Hmmm… close and open my solution after login is a bit of drastic option to solve some i18n issues…
But… the solution to solve the language issue is even more simple: just set a custom language property in the servoy_client.properties with
application.setUserProperty('userLang', language)
application.setUserProperty('userCountry, country)
and load these values in the solution startup method with
i18n.setLocale(application.getUserProperty('userLang'), application.getUserProperty('userCountry'))
Should have thought about that 18 posts ago…
Thank y’all for thinking along Servoyians!
(Now I’ll start thinking about setting default Font and LAf settings…
)