Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/go-i18n.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Lindström <lindztr@gmail.com>2021-03-17 05:32:16 +0300
committerGitHub <noreply@github.com>2021-03-17 05:32:16 +0300
commit2180cd9f35b3e125cfe3773a6bf3ea483347f060 (patch)
tree97dacd40463a142d217c3f674704486d9331a299
parent5d2ec5fba990a664cbe711f626a9a448f894b793 (diff)
Add support for loading bundle from fs.FS (#246)
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.
-rw-r--r--v2/i18n/bundlefs.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/v2/i18n/bundlefs.go b/v2/i18n/bundlefs.go
new file mode 100644
index 0000000..50c794b
--- /dev/null
+++ b/v2/i18n/bundlefs.go
@@ -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)
+}