MCPcopy Index your code
hub / github.com/apache/answer / InstallI18nBundle

Function InstallI18nBundle

internal/cli/install.go:77–118  ·  view source on GitHub ↗
(replace bool)

Source from the content-addressed store, hash-verified

75}
76
77func InstallI18nBundle(replace bool) {
78 fmt.Println("[i18n] try to install i18n bundle...")
79 // if SKIP_REPLACE_I18N is set, skip replace i18n bundles
80 if len(os.Getenv("SKIP_REPLACE_I18N")) > 0 {
81 replace = false
82 }
83 if err := dir.CreateDirIfNotExist(path.I18nPath); err != nil {
84 fmt.Println(err.Error())
85 return
86 }
87
88 i18nList, err := i18n.I18n.ReadDir(".")
89 if err != nil {
90 fmt.Println(err.Error())
91 return
92 }
93 fmt.Printf("[i18n] find i18n bundle %d\n", len(i18nList))
94 for _, item := range i18nList {
95 path := filepath.Join(path.I18nPath, item.Name())
96 content, err := i18n.I18n.ReadFile(item.Name())
97 if err != nil {
98 continue
99 }
100 exist := dir.CheckFileExist(path)
101 if exist && !replace {
102 continue
103 }
104 if exist {
105 fmt.Printf("[i18n] install %s file exist, try to replace it\n", item.Name())
106 if err = os.Remove(path); err != nil {
107 fmt.Println(err)
108 }
109 }
110 fmt.Printf("[i18n] install %s bundle...\n", item.Name())
111 err = writer.WriteFile(path, string(content))
112 if err != nil {
113 fmt.Printf("[i18n] install %s bundle fail: %s\n", item.Name(), err.Error())
114 } else {
115 fmt.Printf("[i18n] install %s bundle success\n", item.Name())
116 }
117 }
118}

Callers 2

command.goFile · 0.92

Calls 3

CreateDirIfNotExistFunction · 0.92
CheckFileExistFunction · 0.92
WriteFileFunction · 0.92

Tested by

no test coverage detected