2018-09-22 03:53:29 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package locale // import "miniflux.app/locale"
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestAllLanguagesHaveCatalog(t *testing.T) {
|
|
|
|
for language := range AvailableLanguages() {
|
|
|
|
if _, found := translations[language]; !found {
|
2018-09-23 00:04:55 +02:00
|
|
|
t.Fatalf(`This language do not have a catalog: %q`, language)
|
2018-09-22 03:53:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAllKeysHaveValue(t *testing.T) {
|
|
|
|
for language := range AvailableLanguages() {
|
2018-09-23 00:04:55 +02:00
|
|
|
messages, err := parseTranslationDict(translations[language])
|
2018-09-22 03:53:29 +02:00
|
|
|
if err != nil {
|
2018-09-23 00:04:55 +02:00
|
|
|
t.Fatalf(`Parsing error for language %q`, language)
|
2018-09-22 03:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(messages) == 0 {
|
|
|
|
t.Fatalf(`The language %q doesn't have any messages`, language)
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range messages {
|
|
|
|
switch value := v.(type) {
|
|
|
|
case string:
|
|
|
|
if value == "" {
|
2021-01-04 06:20:21 +01:00
|
|
|
t.Errorf(`The key %q for the language %q have an empty string as value`, k, language)
|
2018-09-22 03:53:29 +02:00
|
|
|
}
|
|
|
|
case []string:
|
|
|
|
if len(value) == 0 {
|
2021-01-04 06:20:21 +01:00
|
|
|
t.Errorf(`The key %q for the language %q have an empty list as value`, k, language)
|
2018-09-22 03:53:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMissingTranslations(t *testing.T) {
|
|
|
|
refLang := "en_US"
|
2018-09-23 00:04:55 +02:00
|
|
|
references, err := parseTranslationDict(translations[refLang])
|
2018-09-22 03:53:29 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(`Unable to parse reference language`)
|
|
|
|
}
|
|
|
|
|
|
|
|
for language := range AvailableLanguages() {
|
|
|
|
if language == refLang {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-09-23 00:04:55 +02:00
|
|
|
messages, err := parseTranslationDict(translations[language])
|
2018-09-22 03:53:29 +02:00
|
|
|
if err != nil {
|
2018-09-23 00:04:55 +02:00
|
|
|
t.Fatalf(`Parsing error for language %q`, language)
|
2018-09-22 03:53:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for key := range references {
|
|
|
|
if _, found := messages[key]; !found {
|
|
|
|
t.Fatalf(`Translation key %q not found in language %q`, key, language)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|