diff options
author | 2023-11-17 11:35:28 +0100 | |
---|---|---|
committer | 2023-11-17 11:35:28 +0100 | |
commit | fc02d3c6f7db5a7794448f31fd9d6d81d3d224eb (patch) | |
tree | f792f799abadf784e493933af597d8f2292ab776 /internal/typeutils | |
parent | [bugfix] process account delete side effects in serial, not in parallel (#2360) (diff) | |
download | gotosocial-fc02d3c6f7db5a7794448f31fd9d6d81d3d224eb.tar.xz |
[feature] Set/show instance language(s); show post language on frontend (#2362)
* update go text, include text/display
* [feature] Set instance langs, show post lang on frontend
* go fmt
* WebGet
* set language for whole article, don't use FA icon
* mention instance languages + other optional config vars
* little tweak
* put languages in config properly
* warn log language parse
* change some naming around
* tidy up validate a bit
* lint
* rename LanguageTmpl in template
Diffstat (limited to 'internal/typeutils')
-rw-r--r-- | internal/typeutils/converter_test.go | 2 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 28 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend_test.go | 10 |
3 files changed, 34 insertions, 6 deletions
diff --git a/internal/typeutils/converter_test.go b/internal/typeutils/converter_test.go index 122b98d4c..0195a6889 100644 --- a/internal/typeutils/converter_test.go +++ b/internal/typeutils/converter_test.go @@ -526,7 +526,7 @@ func (suite *TypeUtilsTestSuite) GetProcessor() *processing.Processor { mediaManager := testrig.NewTestMediaManager(&suite.state) federator := testrig.NewTestFederator(&suite.state, transportController, mediaManager) emailSender := testrig.NewEmailSender("../../web/template/", nil) - + processor := testrig.NewTestProcessor(&suite.state, federator, emailSender, mediaManager) testrig.StartWorkers(&suite.state, processor.Workers()) diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 1a2c321f5..8138ee7b4 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -30,6 +30,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/language" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/uris" @@ -656,7 +657,28 @@ func (c *Converter) StatusToWebStatus( s *gtsmodel.Status, requestingAccount *gtsmodel.Account, ) (*apimodel.Status, error) { - return c.statusToFrontend(ctx, s, requestingAccount) + webStatus, err := c.statusToFrontend(ctx, s, requestingAccount) + if err != nil { + return nil, err + } + + // Add additional information for template. + // Assume empty langs, hope for not empty language. + webStatus.LanguageTag = new(language.Language) + if lang := webStatus.Language; lang != nil { + langTag, err := language.Parse(*lang) + if err != nil { + log.Warnf( + ctx, + "error parsing %s as language tag: %v", + *lang, err, + ) + } else { + webStatus.LanguageTag = langTag + } + } + + return webStatus, nil } // statusToFrontend is a package internal function for @@ -873,7 +895,7 @@ func (c *Converter) InstanceToAPIV1Instance(ctx context.Context, i *gtsmodel.Ins ShortDescription: i.ShortDescription, Email: i.ContactEmail, Version: config.GetSoftwareVersion(), - Languages: []string{}, // todo: not supported yet + Languages: config.GetInstanceLanguages().TagStrs(), Registrations: config.GetAccountsRegistrationOpen(), ApprovalRequired: config.GetAccountsApprovalRequired(), InvitesEnabled: false, // todo: not supported yet @@ -982,7 +1004,7 @@ func (c *Converter) InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Ins SourceURL: instanceSourceURL, Description: i.Description, Usage: apimodel.InstanceV2Usage{}, // todo: not implemented - Languages: []string{}, // todo: not implemented + Languages: config.GetInstanceLanguages().TagStrs(), Rules: c.InstanceRulesToAPIRules(i.Rules), Terms: i.Terms, } diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go index d386c180e..ee8216e8f 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -712,7 +712,10 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() { "short_description": "\u003cp\u003eThis is the GoToSocial testrig. It doesn't federate or anything.\u003c/p\u003e\u003cp\u003eWhen the testrig is shut down, all data on it will be deleted.\u003c/p\u003e\u003cp\u003eDon't use this in production!\u003c/p\u003e", "email": "admin@example.org", "version": "0.0.0-testrig", - "languages": [], + "languages": [ + "nl", + "en-gb" + ], "registrations": true, "approval_required": true, "invites_enabled": false, @@ -826,7 +829,10 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() { "thumbnail": { "url": "http://localhost:8080/assets/logo.png" }, - "languages": [], + "languages": [ + "nl", + "en-gb" + ], "configuration": { "urls": { "streaming": "wss://localhost:8080" |