Skip to content

Commit

Permalink
Add support for loading bundle from fs.FS
Browse files Browse the repository at this point in the history
This commit aims to add a method for loading bundles from fs.FS. The
change is done to be able to get a nice way to load bundles from an
embedded file system.

Since this can be done by implementing the exported API and using
ParseMessageFileBytes externally, this is not a change that is a must
have. Rather a nice shorthand for using the fs.FS.
  • Loading branch information
antonlindstrom committed Mar 4, 2021
1 parent 5d2ec5f commit 58515e2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions v2/i18n/bundlefs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build go1.16

package i18n

import (
"io/fs"
)

// LoadMessageFileFS is like LoadMessageFile but instead of reading from the
// hosts operating system's file system it reads from the fs file system.
func (b *Bundle) LoadMessageFileFS(fsys fs.FS, path string) (*MessageFile, error) {
buf, err := fs.ReadFile(fsys, path)
if err != nil {
return nil, err
}

return b.ParseMessageFileBytes(buf, path)
}

0 comments on commit 58515e2

Please sign in to comment.