-
-
Notifications
You must be signed in to change notification settings - Fork 367
/
i18n_test.go
48 lines (42 loc) · 1.32 KB
/
i18n_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package i18n
import (
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
)
func TestSimpleTranslation(t *testing.T) {
catalog := NewDefaultMessageCatalog([]*DefaultLocaleBundle{
{
LangTag: "en",
Messages: []*DefaultMessage{
{
ID: "badRequestMethod",
FormattedMessage: "HTTP method is '%s', expected 'POST'.",
},
{
ID: "badRequestBody",
FormattedMessage: "Unable to parse HTTP body, make sure to send a properly formatted form request body.",
},
},
},
{
LangTag: "es",
Messages: []*DefaultMessage{
{
ID: "badRequestMethod",
FormattedMessage: "El método HTTP es '%s', esperado 'POST'.",
},
{
ID: "badRequestBody",
FormattedMessage: "No se puede analizar el cuerpo HTTP, asegúrese de enviar un cuerpo de solicitud de formulario con el formato adecuado.",
},
},
},
})
msg := GetMessage(catalog, "badRequestMethod", language.Spanish, "GET")
assert.Equal(t, msg, "El método HTTP es 'GET', esperado 'POST'.")
msg = GetMessage(catalog, "badRequestBody", language.English, "GET")
assert.Equal(t, msg, "Unable to parse HTTP body, make sure to send a properly formatted form request body.")
}