1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Add unit test to ensure each translation has the correct number of plurals

This commit is contained in:
Frédéric Guillot 2024-02-29 20:20:29 -08:00
parent 347740dce1
commit 1b5edfc00a
8 changed files with 129 additions and 93 deletions

View file

@ -53,11 +53,11 @@ func TestAllKeysHaveValue(t *testing.T) {
switch value := v.(type) {
case string:
if value == "" {
t.Errorf(`The key %q for the language %q have an empty string as value`, k, language)
t.Errorf(`The key %q for the language %q has an empty string as value`, k, language)
}
case []string:
case []any:
if len(value) == 0 {
t.Errorf(`The key %q for the language %q have an empty list as value`, k, language)
t.Errorf(`The key %q for the language %q has an empty list as value`, k, language)
}
}
}
@ -88,3 +88,20 @@ func TestMissingTranslations(t *testing.T) {
}
}
}
func TestTranslationFilePluralForms(t *testing.T) {
for language := range AvailableLanguages() {
messages, err := loadTranslationFile(language)
if err != nil {
t.Fatalf(`Unable to load translation messages for language %q`, language)
}
for k, v := range messages {
if value, ok := v.([]any); ok {
if len(value) != numberOfPluralFormsPerLanguage[language] {
t.Errorf(`The key %q for the language %q does not have the expected number of plurals, got %d instead of %d`, k, language, len(value), numberOfPluralFormsPerLanguage[language])
}
}
}
}
}