Files
Yeuoly 7f463e32f6 feat(plugin_decoder): add support for internationalized readme files (#393)
* feat(plugin_decoder): add support for internationalized readme files

- Introduced the AvailableI18nReadme method in the PluginDecoder interface to retrieve available readme files in multiple languages.
- Implemented the method in FSPluginDecoder and ZipPluginDecoder to read localized readme files from the filesystem and zip archives.
- Enhanced UnixPluginDecoder to handle readme files in a structured manner, including support for reading from a dedicated "readme" directory.
- Added unit tests to verify the functionality of the AvailableI18nReadme method and ensure correct retrieval of localized readme content.

* feat(plugin): add support for multilingual README generation

- Introduced functionality to create README files in multiple languages (Simplified Chinese, Japanese, Portuguese) based on user selection.
- Enhanced the profile management to include options for enabling internationalized README and selecting languages.
- Added new language choice structure to manage language options and their selection state.
- Implemented rendering and writing of language-specific README files during plugin creation.
- Included new README template files for each supported language.

* feat(plugin): add README command and list functionality

- Introduced a new `readme` command to the plugin CLI for managing README files.
- Added `list` subcommand to display available README languages for a specified plugin path.
- Implemented functionality to read and list supported README languages in a tabular format.
- Enhanced error handling for plugin file reading and decoding processes.
2025-07-21 16:02:26 +08:00

103 lines
2.5 KiB
Go

package decoder
import (
"testing"
"github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
"github.com/stretchr/testify/assert"
)
type UnixPluginDecoder struct {
PluginDecoder
PluginDecoderHelper
}
func (d *UnixPluginDecoder) ReadFile(filename string) ([]byte, error) {
return []byte("test"), nil
}
func (d *UnixPluginDecoder) ReadDir(dirname string) ([]string, error) {
if dirname == "_assets" {
return []string{
"_assets/test.txt",
"_assets/test2.txt",
}, nil
} else if dirname == "readme" {
return []string{
"readme/README_zh_Hans.md",
}, nil
}
return nil, nil
}
func (d *UnixPluginDecoder) Close() error {
return nil
}
func (d *UnixPluginDecoder) Assets() (map[string][]byte, error) {
return d.PluginDecoderHelper.Assets(d, "/")
}
func (d *UnixPluginDecoder) CheckAssetsValid() error {
return nil
}
func (d *UnixPluginDecoder) Checksum() (string, error) {
return "", nil
}
func (d *UnixPluginDecoder) Manifest() (plugin_entities.PluginDeclaration, error) {
return plugin_entities.PluginDeclaration{}, nil
}
func (d *UnixPluginDecoder) UniqueIdentity() (plugin_entities.PluginUniqueIdentifier, error) {
return plugin_entities.PluginUniqueIdentifier(""), nil
}
func (d *UnixPluginDecoder) AvailableI18nReadme() (map[string]string, error) {
return d.PluginDecoderHelper.AvailableI18nReadme(d, "/")
}
type WindowsPluginDecoder struct {
UnixPluginDecoder
}
func (d *WindowsPluginDecoder) ReadDir(dirname string) ([]string, error) {
return []string{
"_assets\\test.txt",
"_assets\\test2.txt",
}, nil
}
func (d *WindowsPluginDecoder) Assets() (map[string][]byte, error) {
return d.PluginDecoderHelper.Assets(d, "\\")
}
func TestRemapAssets(t *testing.T) {
decoder := UnixPluginDecoder{}
remappedAssets, err := decoder.Assets()
if err != nil {
t.Fatalf("Failed to remap assets: %v", err)
}
assert.Equal(t, remappedAssets["test.txt"], []byte("test"))
assert.Equal(t, remappedAssets["test2.txt"], []byte("test"))
decoder1 := WindowsPluginDecoder{}
remappedAssets, err = decoder1.Assets()
if err != nil {
t.Fatalf("Failed to remap assets: %v", err)
}
assert.Equal(t, remappedAssets["test.txt"], []byte("test"))
assert.Equal(t, remappedAssets["test2.txt"], []byte("test"))
}
func TestAvailableI18nReadme(t *testing.T) {
decoder := UnixPluginDecoder{}
readmes, err := decoder.AvailableI18nReadme()
if err != nil {
t.Fatalf("Failed to get available i18n readme: %v", err)
}
assert.Equal(t, readmes["en_US"], "test")
assert.Equal(t, readmes["zh_Hans"], "test")
}