mirror of
https://github.com/TecharoHQ/anubis.git
synced 2025-08-03 01:38:14 -04:00
feat(localization): Add option for forcing a language (#742)
* Add forcesLanguage option * Change comments for forced language option * Add changes to CHANGELOG.md --------- Signed-off-by: Xe Iaso <me@xeiaso.net> Co-authored-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
c981c23f7e
commit
0e43138324
@ -32,3 +32,7 @@ const APIPrefix = "/.within.website/x/cmd/anubis/api/"
|
|||||||
// DefaultDifficulty is the default "difficulty" (number of leading zeroes)
|
// DefaultDifficulty is the default "difficulty" (number of leading zeroes)
|
||||||
// that must be met by the client in order to pass the challenge.
|
// that must be met by the client in order to pass the challenge.
|
||||||
const DefaultDifficulty = 4
|
const DefaultDifficulty = 4
|
||||||
|
|
||||||
|
// ForcedLanguage is the language being used instead of the one of the request's Accept-Language header
|
||||||
|
// if being set.
|
||||||
|
var ForcedLanguage = ""
|
||||||
|
@ -50,6 +50,7 @@ var (
|
|||||||
cookieExpiration = flag.Duration("cookie-expiration-time", anubis.CookieDefaultExpirationTime, "The amount of time the authorization cookie is valid for")
|
cookieExpiration = flag.Duration("cookie-expiration-time", anubis.CookieDefaultExpirationTime, "The amount of time the authorization cookie is valid for")
|
||||||
cookiePrefix = flag.String("cookie-prefix", "techaro.lol-anubis", "prefix for browser cookies created by Anubis")
|
cookiePrefix = flag.String("cookie-prefix", "techaro.lol-anubis", "prefix for browser cookies created by Anubis")
|
||||||
cookiePartitioned = flag.Bool("cookie-partitioned", false, "if true, sets the partitioned flag on Anubis cookies, enabling CHIPS support")
|
cookiePartitioned = flag.Bool("cookie-partitioned", false, "if true, sets the partitioned flag on Anubis cookies, enabling CHIPS support")
|
||||||
|
forcedLanguage = flag.String("forced-language", "", "if set, this language is being used instead of the one from the request's Accept-Language header")
|
||||||
hs512Secret = flag.String("hs512-secret", "", "secret used to sign JWTs, uses ed25519 if not set")
|
hs512Secret = flag.String("hs512-secret", "", "secret used to sign JWTs, uses ed25519 if not set")
|
||||||
cookieSecure = flag.Bool("cookie-secure", true, "if true, sets the secure flag on Anubis cookies")
|
cookieSecure = flag.Bool("cookie-secure", true, "if true, sets the secure flag on Anubis cookies")
|
||||||
ed25519PrivateKeyHex = flag.String("ed25519-private-key-hex", "", "private key used to sign JWTs, if not set a random one will be assigned")
|
ed25519PrivateKeyHex = flag.String("ed25519-private-key-hex", "", "private key used to sign JWTs, if not set a random one will be assigned")
|
||||||
@ -378,6 +379,7 @@ func main() {
|
|||||||
|
|
||||||
anubis.CookieName = *cookiePrefix + "-auth"
|
anubis.CookieName = *cookiePrefix + "-auth"
|
||||||
anubis.TestCookieName = *cookiePrefix + "-cookie-verification"
|
anubis.TestCookieName = *cookiePrefix + "-cookie-verification"
|
||||||
|
anubis.ForcedLanguage = *forcedLanguage
|
||||||
|
|
||||||
// If OpenGraph configuration values are not set in the config file, use the
|
// If OpenGraph configuration values are not set in the config file, use the
|
||||||
// values from flags / envvars.
|
// values from flags / envvars.
|
||||||
|
@ -13,13 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
<!-- This changes the project to: -->
|
<!-- This changes the project to: -->
|
||||||
- Add `COOKIE_SECURE` option to set the cookie [Secure flag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies#block_access_to_your_cookies)
|
- Add `COOKIE_SECURE` option to set the cookie [Secure flag](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies#block_access_to_your_cookies)
|
||||||
- Sets cookie defaults to use [SameSite: None](https://web.dev/articles/samesite-cookies-explained)
|
- Sets cookie defaults to use [SameSite: None](https://web.dev/articles/samesite-cookies-explained)
|
||||||
|
|
||||||
- Determine the `BIND_NETWORK`/`--bind-network` value from the bind address ([#677](https://github.com/TecharoHQ/anubis/issues/677)).
|
- Determine the `BIND_NETWORK`/`--bind-network` value from the bind address ([#677](https://github.com/TecharoHQ/anubis/issues/677)).
|
||||||
- Implement localization system. Find locale files in lib/localization/locales/.
|
- Implement localization system. Find locale files in lib/localization/locales/.
|
||||||
- Implement a [development container](https://containers.dev/) manifest to make contributions easier.
|
- Implement a [development container](https://containers.dev/) manifest to make contributions easier.
|
||||||
- Fix dynamic cookie domains functionality ([#731](https://github.com/TecharoHQ/anubis/pull/731)).
|
- Fix dynamic cookie domains functionality ([#731](https://github.com/TecharoHQ/anubis/pull/731))
|
||||||
- Add option for custom cookie prefix ([#732](https://github.com/TecharoHQ/anubis/pull/732)).
|
- Add option for custom cookie prefix ([#732](https://github.com/TecharoHQ/anubis/pull/732))
|
||||||
- Remove the "Success" interstitial after a proof of work challenge is concluded.
|
- Remove the "Success" interstitial after a proof of work challenge is concluded.
|
||||||
|
- Add option for forcing a specific language ([#742](https://github.com/TecharoHQ/anubis/pull/742))
|
||||||
|
|
||||||
## v1.20.0: Thancred Waters
|
## v1.20.0: Thancred Waters
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package localization
|
|||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/TecharoHQ/anubis"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -93,8 +94,13 @@ func (sl *SimpleLocalizer) T(messageID string) string {
|
|||||||
return sl.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: messageID})
|
return sl.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: messageID})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLocalizer creates a localizer based on the request's Accept-Language header
|
// GetLocalizer creates a localizer based on the request's Accept-Language header or forcedLanguage option
|
||||||
func GetLocalizer(r *http.Request) *SimpleLocalizer {
|
func GetLocalizer(r *http.Request) *SimpleLocalizer {
|
||||||
localizer := NewLocalizationService().GetLocalizerFromRequest(r)
|
var localizer *i18n.Localizer
|
||||||
|
if anubis.ForcedLanguage == "" {
|
||||||
|
localizer = NewLocalizationService().GetLocalizerFromRequest(r)
|
||||||
|
} else {
|
||||||
|
localizer = NewLocalizationService().GetLocalizer(anubis.ForcedLanguage)
|
||||||
|
}
|
||||||
return &SimpleLocalizer{Localizer: localizer}
|
return &SimpleLocalizer{Localizer: localizer}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user