|
@@ -16,7 +16,7 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type LanguageFilev1 struct {
|
|
type LanguageFilev1 struct {
|
|
|
- SchemaVersion int `json:"schemaVersion" yaml:"schemaVersion"`
|
|
|
|
|
|
|
+ SchemaVersion yaml.Node `json:"schemaVersion" yaml:"schemaVersion"`
|
|
|
Translations map[string]string `json:"translations" yaml:"translations"`
|
|
Translations map[string]string `json:"translations" yaml:"translations"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -163,8 +163,9 @@ func loadLanguageFile(fullPath string) (map[string]string, error) {
|
|
|
return nil, fmt.Errorf("parsing language file %s: %w", fullPath, err)
|
|
return nil, fmt.Errorf("parsing language file %s: %w", fullPath, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if yamlData.SchemaVersion != 1 {
|
|
|
|
|
- return nil, fmt.Errorf("language file %s has schemaVersion %d, expected 1", fullPath, yamlData.SchemaVersion)
|
|
|
|
|
|
|
+ err = validateSchemaVersion(&yamlData.SchemaVersion)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, fmt.Errorf("language file %s: %w", fullPath, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if len(yamlData.Translations) == 0 {
|
|
if len(yamlData.Translations) == 0 {
|
|
@@ -174,6 +175,16 @@ func loadLanguageFile(fullPath string) (map[string]string, error) {
|
|
|
return yamlData.Translations, nil
|
|
return yamlData.Translations, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// validateSchemaVersion checks the raw YAML scalar, because decoding straight
|
|
|
|
|
+// into an int silently truncates values such as 1.5 to 1.
|
|
|
|
|
+func validateSchemaVersion(node *yaml.Node) error {
|
|
|
|
|
+ if node.Kind != yaml.ScalarNode || node.ShortTag() != "!!int" || node.Value != "1" {
|
|
|
|
|
+ return fmt.Errorf("schemaVersion is %q, expected 1", node.Value)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// getReferenceKeys returns the keys from the "en" translation as the reference set.
|
|
// getReferenceKeys returns the keys from the "en" translation as the reference set.
|
|
|
func getReferenceKeys(messages map[string]map[string]string) map[string]bool {
|
|
func getReferenceKeys(messages map[string]map[string]string) map[string]bool {
|
|
|
enTranslations, exists := messages["en"]
|
|
enTranslations, exists := messages["en"]
|