From 58515e2893351be0239fef3a65a8be6b995a70fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Lindstr=C3=B6m?= Date: Thu, 25 Feb 2021 08:42:43 +0100 Subject: [PATCH] Add support for loading bundle from fs.FS 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. --- v2/i18n/bundlefs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 v2/i18n/bundlefs.go diff --git a/v2/i18n/bundlefs.go b/v2/i18n/bundlefs.go new file mode 100644 index 00000000..50c794b6 --- /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) +}