From fc02d3c6f7db5a7794448f31fd9d6d81d3d224eb Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:35:28 +0100 Subject: [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 --- internal/typeutils/internaltofrontend.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'internal/typeutils/internaltofrontend.go') 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, } -- cgit v1.2.3