[Gambas-devel] Possible usefull addition to Gambas?
Benoît Minisini
gambas at ...1...
Thu Jan 15 23:55:52 CET 2015
Le 15/01/2015 21:12, Willy Raets a écrit :
> 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?
>
Desktop.Path already returns the path of the current user "Desktop"
directory by following the algorithm specified by the freedesktop standard.
For example, on my system it returns "/home/benoit/Bureau".
The same algorithm can be used when searching for the other directories
("Documents", "Download"...).
So I think it's better to add methods or properties to the gb.desktop
component that will return these other directories.
Regards,
--
Benoît Minisini
More information about the Devel
mailing list