Use goembed for translations.

pull/11691/head
Andriy Dzikh 2021-06-17 11:27:44 -07:00
parent 92258d06d0
commit 770d348e30
2 changed files with 26 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import (
"golang.org/x/text/language"
"k8s.io/klog/v2"
"k8s.io/minikube/translations"
)
var (
@ -70,13 +71,13 @@ func DetermineLocale() {
// Load translations for preferred language into memory.
p := preferredLanguage.String()
translationFile := path.Join("translations", fmt.Sprintf("%s.json", p))
t, err := Asset(translationFile)
t, err := translations.Translations.ReadFile(translationFile)
if err != nil {
// Attempt to find a more broad locale, e.g. fr instead of fr-FR.
if strings.Contains(p, "-") {
p = strings.Split(p, "-")[0]
translationFile := path.Join("translations", fmt.Sprintf("%s.json", p))
t, err = Asset(translationFile)
t, err = translations.Translations.ReadFile(translationFile)
if err != nil {
klog.V(1).Infof("Failed to load translation file for %s: %v", p, err)
return

View File

@ -0,0 +1,23 @@
/*
Copyright 2021 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package translations
import "embed"
// Translations contains all translation JSON files.
//go:embed *.json
var Translations embed.FS