This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support 3rd party plugin translation (#109)
* add i18n.String.WithDefault, rename i18n.String.Copy * add id constructors to property * make schema group fields nil * change schema id pattern * fix test * refactor manifest translation * support 3rd party plugin translation
- Loading branch information
Showing
36 changed files
with
1,062 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,8 @@ | ||
package fs | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/reearth/reearth-backend/pkg/id" | ||
"github.com/reearth/reearth-backend/pkg/plugin/manifest" | ||
"github.com/reearth/reearth-backend/pkg/rerror" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
const ( | ||
assetDir = "assets" | ||
pluginDir = "plugins" | ||
publishedDir = "published" | ||
manifestFilePath = "reearth.yml" | ||
) | ||
|
||
func readManifest(fs afero.Fs, pid id.PluginID) (*manifest.Manifest, error) { | ||
f, err := fs.Open(filepath.Join(pluginDir, pid.String(), manifestFilePath)) | ||
if err != nil { | ||
return nil, rerror.ErrInternalBy(err) | ||
} | ||
defer func() { | ||
_ = f.Close() | ||
}() | ||
|
||
m, err := manifest.Parse(f, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return m, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fs | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/reearth/reearth-backend/pkg/i18n" | ||
"github.com/reearth/reearth-backend/pkg/plugin" | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPlugin(t *testing.T) { | ||
ctx := context.Background() | ||
fs := NewPlugin(mockPluginFS()) | ||
p, err := fs.FindByID(ctx, plugin.MustID("testplugin~1.0.0"), nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, plugin.New().ID(plugin.MustID("testplugin~1.0.0")).Name(i18n.String{ | ||
"en": "testplugin", | ||
"ja": "テストプラグイン", | ||
"zh-CN": "测试插件", | ||
}).MustBuild(), p) | ||
} | ||
|
||
func mockPluginFS() afero.Fs { | ||
files := map[string]string{ | ||
"plugins/testplugin~1.0.0/reearth.yml": `{ "id": "testplugin", "version": "1.0.0", "name": "testplugin" }`, | ||
"plugins/testplugin~1.0.0/reearth_ja.yml": `{ "name": "テストプラグイン" }`, | ||
"plugins/testplugin~1.0.0/reearth_zh-CN.yml": `{ "name": "测试插件" }`, | ||
} | ||
|
||
fs := afero.NewMemMapFs() | ||
for name, content := range files { | ||
f, _ := fs.Create(name) | ||
_, _ = f.WriteString(content) | ||
_ = f.Close() | ||
} | ||
return fs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.