[Gambas-devel] Possible usefull addition to Gambas?
Willy Raets
willy at ...732...
Thu Jan 15 21:12:40 CET 2015
Hi all,
I have been running into trouble with localisation making certain Linux
folder names being different, depending on language.
Like folder Desktop is not Desktop for all languages so when doing
User.Home &/ "Desktop" your application gets into trouble on for example
a system running Dutch where "Desktop" folder becomes "Bureaublad"
folder.
I have solved this problem with creating a function in my Gambas library
that gets the proper folder named based on the local language settings.
I think it might be a good addition for the User class to for example
have User.DesktopFolder return the User Desktop folder path taking into
account localisation.
The function is as follows (and could be added to User class):
'' To convert standard linux folder names to user localised folder
names.<br />
'' Possible values for FolderName are: <br />
'' Desktop, Documents, Download, Music, Pictures and Videos
Public Function FolderLocales(FolderName As String) As String
Dim sHelp As String
FolderName = Upper(FolderName)
Select FolderName
Case "DESKTOP", "DOCUMENTS", "DOWNLOAD", "MUSIC", "PICTURES",
"VIDEOS"
Exec ["xdg-user-dirs-update"] Wait
Exec ["xdg-user-dir", FolderName] Wait To sHelp Left(sHelp, -1)
Return Left(sHelp, -1)
Case Else
sHelp = Subst(("Illegal argument &1 for FolderName! Use either
Desktop, Documents, Download, Music, Pictures or Videos."), FolderName)
Message.Error(sHelp)
Error.Raise(sHelp)
End Select
Catch
Error.Clear
Return Null
End
Now User.DesktopFolder could return this:
Return Subst(User.Home &/ "&1", FolderLocales("Desktop"))
User.MusicFolder could return:
Return Subst(User.Home &/ "&1", FolderLocales("Music"))
and so on....
What do you think, a useful addition?
--
Kind regards,
Willy (aka gbWilly)
http://gambasshowcase.org/
http://howtogambas.org
http://gambos.org
More information about the Devel
mailing list