msgUtil.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. kconf "github.com/lf-edge/ekuiper/internal/conf"
  17. "gopkg.in/ini.v1"
  18. "io/ioutil"
  19. "path"
  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. infos, err := ioutil.ReadDir(dir)
  40. if nil != err {
  41. return err
  42. }
  43. for _, info := range infos {
  44. fName := info.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. }