Add more test cases and refresh tests for pot generation

Ensure that the .po reflects latest translations (some were missing)
Add more translations to reflect the new fixed use cases.
This commit is contained in:
Didier Roche 2023-07-26 11:23:25 +02:00
parent 7f9fe4dccc
commit b65bc5e2b1
No known key found for this signature in database
GPG key ID: 98B24A9CE4AC208E
5 changed files with 103 additions and 18 deletions

View file

@ -7,22 +7,80 @@ msgstr ""
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:23
#. gotext.Get
#: fixtures/main.go:35
#: fixtures/main.go:37
msgid "My text on 'domain-name' domain"
msgstr ""
#: fixtures/main.go:38
#. l.GetN
#: fixtures/main.go:75
msgid "Singular"
msgid_plural "Plural"
msgstr[0] ""
msgstr[1] ""
#: fixtures/main.go:40
#. l.GetN
#: fixtures/main.go:77
msgid "SingularVar"
msgid_plural "PluralVar"
msgstr[0] ""
msgstr[1] ""
#: fixtures/main.go:44
msgid "alias call"
msgstr ""
#: fixtures/main.go:104
msgid "inside dummy"
msgstr ""
#: fixtures/pkg/pkg.go:15
msgid "inside sub package"
msgstr ""
#: fixtures/main.go:51
msgid ""
"multi\n"
"line\n"
"string\n"
msgstr ""
#: fixtures/main.go:54
msgid ""
"multi\n"
"line\n"
"string\n"
"ending with\n"
"EOL\n"
msgstr ""
#: fixtures/main.go:59
msgid ""
"multline\n"
"ending with EOL\n"
msgstr ""
#: fixtures/main.go:50
msgid "raw string with\nmultiple\nEOL"
msgstr ""
#: fixtures/main.go:48
msgid "string ending with EOL\n"
msgstr ""
#: fixtures/main.go:49
msgid ""
"string with\n"
"multiple\n"
"EOL\n"
msgstr ""
#: fixtures/main.go:47
msgid "string with backquotes"
msgstr ""
#: fixtures/main.go:91
msgid "translate package"
msgstr ""
#: fixtures/main.go:92
msgid "translate sub package"
msgstr ""

View file

@ -7,8 +7,11 @@ msgstr ""
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:26
#. gotext.GetD
#: fixtures/main.go:61
msgid "Another text on a different domain"
msgstr ""
#: fixtures/main.go:78
msgctxt "ctx"
msgid "string"
msgstr ""

View file

@ -7,16 +7,13 @@ msgstr ""
"Language: \n"
"X-Generator: xgotext\n"
#: fixtures/main.go:35
#. l.GetD
#: fixtures/main.go:71
msgid "Translate this"
msgstr ""
#: fixtures/main.go:43
#. l.GetNDC
#: fixtures/main.go:79
msgctxt "NDC-CTX"
msgid "ndc"
msgid_plural "ndcs"
msgstr[0] ""
msgstr[1] ""
msgstr[1] ""

View file

@ -43,6 +43,21 @@ func main() {
// same with alias package name
fmt.Println(alias.Get("alias call"))
// Special strings
fmt.Println(gotext.Get(`string with backquotes`))
fmt.Println(gotext.Get("string ending with EOL\n"))
fmt.Println(gotext.Get("string with\nmultiple\nEOL"))
fmt.Println(gotext.Get(`raw string with\nmultiple\nEOL`))
fmt.Println(gotext.Get(`multi
line
string`))
fmt.Println(gotext.Get(`multi
line
string
ending with
EOL`))
fmt.Println(gotext.Get("multline\nending with EOL\n"))
// Translate text from a different domain without reconfigure
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))

View file

@ -1,10 +1,11 @@
package pkg_tree
import (
"github.com/leonelquinteros/gotext/cli/xgotext/parser"
"os"
"path/filepath"
"testing"
"github.com/leonelquinteros/gotext/cli/xgotext/parser"
)
func TestParsePkgTree(t *testing.T) {
@ -23,7 +24,18 @@ func TestParsePkgTree(t *testing.T) {
t.Error(err)
}
translations := []string{"\"inside sub package\"", "\"My text on 'domain-name' domain\"", "\"alias call\"", "\"Singular\"", "\"SingularVar\"", "\"translate package\"", "\"translate sub package\"", "\"inside dummy\""}
translations := []string{"inside sub package", "My text on 'domain-name' domain", "alias call", "Singular", "SingularVar", "translate package", "translate sub package", "inside dummy",
`string with backquotes`, "string ending with EOL\n", "string with\nmultiple\nEOL", `raw string with\nmultiple\nEOL`,
`multi
line
string`,
`multi
line
string
ending with
EOL`,
"multline\nending with EOL\n",
}
if len(translations) != len(data.Domains[defaultDomain].Translations) {
t.Error("translations count mismatch")