-
Notifications
You must be signed in to change notification settings - Fork 45
Conversation
This tweaks the locale support in a couple of ways. First, we now locate locales in the root `assets/i18n` directory, resolved via `GetBundlePath`. This hardens the plugin against changes the server might make it how it unpacks the plugin, and simplifies the distribution of i18n resources for users. Secondly, we now register all locales found in the `assets/i18n` directory. This means that adding support for new locales simply requires dropping in the file without any need to modify the code or even recompile.
Perusing the code some more, I realize there are a bunch of Feel free to push back if the intent was to prevent other locales since it wouldn't really work! |
i18nDirectory, found := fileutils.FindDir(*p.ServerConfig.PluginSettings.Directory + "/" + manifest.Id + "/server/dist/i18n/") | ||
if !found { | ||
return fmt.Errorf("unable to find i18n directory") | ||
bundlePath, err := p.API.GetBundlePath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
if err := i18n.LoadTranslationFile(filepath.Join(i18nDirectory, filename)); err != nil { | ||
return err | ||
p.API.LogError("Failed to load translation file", "filename", filename, "err", err.Error()) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better continuing here and logging, nice.
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTranslationsPreInit(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for adding test coverage on this. I learned some things from your style.
I believe you are referring to funcs like e.g. func (p *Plugin) CreateOccurrences(request *ReminderRequest) error {
user, uErr := p.API.GetUserByUsername(request.Username)
if uErr != nil {
return uErr
}
_, locale := p.translation(user)
switch locale {
case "en":
return p.createOccurrencesEN(request)
default:
return p.createOccurrencesEN(request)
}
} The only reason this is done because of the differences in ordering of grammar between languages. I am hoping to start spanish soon. |
Tested locally and works great, thank you @lieut-data ! |
This tweaks the locale support in a couple of ways. First, we now locate locales in the root
assets/i18n
directory, resolved viaGetBundlePath
. This hardens the plugin against changes the server might make it how it unpacks the plugin, and simplifies the distribution of i18n resources for users.Secondly, we now register all locales found in the
assets/i18n
directory. This means that adding support for new locales simply requires dropping in the file without any need to modify the code or even recompile.Learned a bunch about the framework as part of making these changes, so thanks for the opportunity :)