leonelquinteros / gotext

Go (Golang) GNU gettext utilities package
Other
432 stars 58 forks source link

Support more FileSystems #17

Closed Dexus closed 6 years ago

Dexus commented 6 years ago

Please describe your issue

Is this a bug, an improvement, a proposal or something else?

Briefly explain your issue

Support more FileSystems like VFS, go-bindata, fileb0x etc.

What's the expected behaviour?

Creation of an abstraction of file systems to be used. So that it is possible to use not only the system file system but also other virtual file systems.

What's the actual behaviour?

Only supported the system file systems.

Comments

It should be possible to have an embedded filesystem, so that it is possible to have a binary only application. Without having to pass the locale to an external directory for each instance.

leonelquinteros commented 6 years ago

@Dexus I'll follow the same approach as in #18

I think it's the package user who should decide how to handle content storage. For simplicity, convenience and following the gettext principles, the package implements the OS filesystem access to .po files so anybody can start using it quickly. I would like to avoid an entire file system abstraction layer inside this package, because isn't the purpose.

That said, you have a very valid point and the use case should be covered by this package.

I think this could be already covered by just using Po objects instead of Locale objects, anybody could do:

poContent := loadPoContent() // Loads the content of a Po file from wherever...
myPo := new(gotext.Po)
myPo.Parse(poContent)

fmt.Println(myPo.Get("Some text"))

But I get this method would be losing some convenient language and domain management that the Locale object has.

So maybe we should implement the content loading abstraction (instead of the file system one). Just one "Consumer" interface that can handle func LoadPo(language, domain string) *Po so the NewLocale(p, l string) *Locale becomes NewLocale(c Consumer) *Locale.

From there, I'd just only include the file system consumer on this package and leave others outside the scope. So: loc := gotext.NewLocale(gotext.FileSystemConsumer("/path/to/tr", "en_UK")).

Note: I don't like the Consumer interface name, but couldn't think any better now xD

What do you think?

Dexus commented 6 years ago

As already written in #18, I will push something for the next days, then maybe it will be a bit clearer and we will be able to install something like that. We work with a singleton so that we can process everything in one place and our application can work with it.

Maybe it's not elegant, but you can form your own opinion in a few days and maybe you can work with it.

Greetings, Josef

leonelquinteros commented 6 years ago

Having the option to load a Po file from any source, and now, the option to implement external Translator objects that can work with other translation sources, I'll leave this feature to be implemented by any third party or package users when convenient.

Not going to include this feature in the package.