ReplaceI18nFilesLocal replace i18n files
(i18nDir string)
| 37 | |
| 38 | // ReplaceI18nFilesLocal replace i18n files |
| 39 | func ReplaceI18nFilesLocal(i18nDir string) error { |
| 40 | i18nList, err := i18n.I18n.ReadDir(".") |
| 41 | if err != nil { |
| 42 | fmt.Println(err.Error()) |
| 43 | return err |
| 44 | } |
| 45 | fmt.Printf("[i18n] find i18n bundle %d\n", len(i18nList)) |
| 46 | for _, item := range i18nList { |
| 47 | path := filepath.Join(i18nDir, item.Name()) |
| 48 | content, err := i18n.I18n.ReadFile(item.Name()) |
| 49 | if err != nil { |
| 50 | continue |
| 51 | } |
| 52 | exist := dir.CheckFileExist(path) |
| 53 | if exist { |
| 54 | fmt.Printf("[i18n] install %s file exist, try to replace it\n", item.Name()) |
| 55 | if err = os.Remove(path); err != nil { |
| 56 | fmt.Println(err) |
| 57 | } |
| 58 | } |
| 59 | fmt.Printf("[i18n] install %s bundle...\n", item.Name()) |
| 60 | err = writer.WriteFile(path, string(content)) |
| 61 | if err != nil { |
| 62 | fmt.Printf("[i18n] install %s bundle fail: %s\n", item.Name(), err.Error()) |
| 63 | } else { |
| 64 | fmt.Printf("[i18n] install %s bundle success\n", item.Name()) |
| 65 | } |
| 66 | } |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | // MergeI18nFilesLocal merge i18n files |
| 71 | func MergeI18nFilesLocal(originalI18nDir, targetI18nDir string) (err error) { |
no test coverage detected