msgUtil.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package meta
  15. import (
  16. "os"
  17. "path"
  18. kconf "github.com/lf-edge/ekuiper/internal/conf"
  19. "gopkg.in/ini.v1"
  20. )
  21. var gUimsg map[string]*ini.File
  22. func getMsg(language, section, key string) string {
  23. language += ".ini"
  24. if conf, ok := gUimsg[language]; ok {
  25. s := conf.Section(section)
  26. if s != nil {
  27. return s.Key(key).String()
  28. }
  29. }
  30. return ""
  31. }
  32. func ReadUiMsgDir() error {
  33. gUimsg = make(map[string]*ini.File)
  34. confDir, err := kconf.GetConfLoc()
  35. if nil != err {
  36. return err
  37. }
  38. dir := path.Join(confDir, "multilingual")
  39. dirEntries, err := os.ReadDir(dir)
  40. if nil != err {
  41. return err
  42. }
  43. for _, entry := range dirEntries {
  44. fName := entry.Name()
  45. kconf.Log.Infof("uiMsg file : %s", fName)
  46. fPath := path.Join(dir, fName)
  47. if conf, err := ini.Load(fPath); nil != err {
  48. return err
  49. } else {
  50. gUimsg[fName] = conf
  51. }
  52. }
  53. return nil
  54. }