[Gambas-devel] Possible usefull addition to Gambas?
Tobias Boege
taboege at ...176...
Thu Jan 15 21:28:08 CET 2015
On Thu, 15 Jan 2015, Willy Raets wrote:
> 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
Maybe do this once in your _init(), not on every query?
I don't have these scripts installed but from the ArchWiki[0], it seems that
xdg-user-dirs-update *creates* directories. I see the following problem:
when I explain workflow things in the IDE to German-only-speaking Gambas
users I need to switch my IDE to German (when it's normally English). I
don't want these directories to be created automatically when the IDE tries
to query some directory.
Normally I only keep the Documents directory anyway. I don't want to delete
the others on a regular basis.
A good solution would be an optional parameter EnsureExist = False per
default. Then the program can decide if the existence of a particular
directory is really necessary for it to function.
> 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
Why Error.Clear() in Catch? I haven't seen this pattern anywhere in the
sources yet and grep shows that indeed this method is only used in the
IDE somewhere and there not inside a Catch block.
I'm curious what you want to accomplish.
> 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?
>
Using xdg scripts reminds me more of gb.desktop... There are already
Desktop.CacheDir and Desktop.DataDir there.
Regards,
Tobi
[0] https://wiki.archlinux.org/index.php/Xdg_user_directories
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the Devel
mailing list