Address review feedback on portal i18n
Swallow locale mutation rejections after the toast, close the mobile drawer on locale change, escape SEO paths, share the IAM locale list with SEO, and finish dropping /trust leftovers. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -1,2 +1,22 @@
|
||||
-- Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
-- SOFTWARE.
|
||||
|
||||
ALTER TABLE identities
|
||||
ADD COLUMN locale TEXT NULL;
|
||||
|
||||
@@ -68,9 +68,9 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// Short URL locale tags accepted for Identity.locale (must stay in sync with
|
||||
// the compliance-portal URL_LOCALES list).
|
||||
var supportedIdentityLocales = []string{
|
||||
// SupportedIdentityLocales are short URL locale tags accepted for
|
||||
// Identity.locale. Keep in sync with the compliance-portal URL_LOCALES list.
|
||||
var SupportedIdentityLocales = []string{
|
||||
"en", "fr", "de", "es", "id", "it", "ja", "ko", "pl", "pt", "tr", "uk", "zh",
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (req UpdateLocaleRequest) Validate() error {
|
||||
"locale",
|
||||
validator.NotEmpty(),
|
||||
validator.MaxLen(8),
|
||||
validator.OneOfSlice(supportedIdentityLocales),
|
||||
validator.OneOfSlice(SupportedIdentityLocales),
|
||||
)
|
||||
|
||||
return v.Error()
|
||||
|
||||
@@ -22,14 +22,11 @@ package complianceportal_v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Short locale tags used in compliance-portal URL paths. Keep in sync with the
|
||||
// frontend URL_LOCALES list and iam.supportedIdentityLocales.
|
||||
var compliancePortalLocales = []string{
|
||||
"en", "fr", "de", "es", "id", "it", "ja", "ko", "pl", "pt", "tr", "uk", "zh",
|
||||
}
|
||||
"go.probo.inc/probo/pkg/iam"
|
||||
)
|
||||
|
||||
const defaultCompliancePortalLocale = "en"
|
||||
|
||||
@@ -47,8 +44,9 @@ func SEOFromRequest(r *http.Request, pageBaseURL string) (htmlLang, canonical st
|
||||
htmlLang = locale
|
||||
canonical = localizedPageURL(pageBaseURL, locale, rest)
|
||||
|
||||
hreflang = make([]HreflangLink, 0, len(compliancePortalLocales)+1)
|
||||
for _, loc := range compliancePortalLocales {
|
||||
locales := iam.SupportedIdentityLocales
|
||||
hreflang = make([]HreflangLink, 0, len(locales)+1)
|
||||
for _, loc := range locales {
|
||||
hreflang = append(hreflang, HreflangLink{
|
||||
Lang: loc,
|
||||
Href: localizedPageURL(pageBaseURL, loc, rest),
|
||||
@@ -81,7 +79,7 @@ func splitLocaleFromAppPath(appPath string) (locale, rest string) {
|
||||
}
|
||||
|
||||
func isCompliancePortalLocale(value string) bool {
|
||||
for _, locale := range compliancePortalLocales {
|
||||
for _, locale := range iam.SupportedIdentityLocales {
|
||||
if locale == value {
|
||||
return true
|
||||
}
|
||||
@@ -91,11 +89,22 @@ func isCompliancePortalLocale(value string) bool {
|
||||
|
||||
func localizedPageURL(pageBaseURL, locale, rest string) string {
|
||||
base := strings.TrimRight(pageBaseURL, "/")
|
||||
if rest == "/" || rest == "" {
|
||||
return base + "/" + locale
|
||||
segments := []string{locale}
|
||||
if rest != "/" && rest != "" {
|
||||
trimmed := strings.Trim(rest, "/")
|
||||
if trimmed != "" {
|
||||
segments = append(segments, strings.Split(trimmed, "/")...)
|
||||
}
|
||||
}
|
||||
if !strings.HasPrefix(rest, "/") {
|
||||
rest = "/" + rest
|
||||
|
||||
escaped := make([]string, len(segments))
|
||||
for i, segment := range segments {
|
||||
escaped[i] = url.PathEscape(segment)
|
||||
}
|
||||
return base + "/" + locale + rest
|
||||
|
||||
joined, err := url.JoinPath(base, escaped...)
|
||||
if err != nil {
|
||||
return base + "/" + strings.Join(escaped, "/")
|
||||
}
|
||||
return joined
|
||||
}
|
||||
|
||||
@@ -60,3 +60,20 @@ func TestSEOFromRequest(t *testing.T) {
|
||||
assert.Equal(t, "https://acme.probopage.localhost/en/documents", enHref)
|
||||
assert.Equal(t, enHref, xDefault)
|
||||
}
|
||||
|
||||
func TestSEOFromRequest_EscapesPathSegments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
req, err := http.NewRequest(
|
||||
http.MethodGet,
|
||||
"https://acme.probopage.localhost/en/docs/foo%20bar",
|
||||
nil,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, canonical, _ := complianceportal_v1.SEOFromRequest(
|
||||
req,
|
||||
"https://acme.probopage.localhost",
|
||||
)
|
||||
assert.Equal(t, "https://acme.probopage.localhost/en/docs/foo%20bar", canonical)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user