Skip to content

Commit

Permalink
Merge pull request #33 from lazygophers/luoxin
Browse files Browse the repository at this point in the history
i18n
  • Loading branch information
Luoxin authored Aug 23, 2024
2 parents 4fe9c5a + eb79eec commit e458aa8
Show file tree
Hide file tree
Showing 155 changed files with 1,282 additions and 55 deletions.
26 changes: 25 additions & 1 deletion cli/i18n/tran.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var allLanguage = candy.Map([]string{
"zh-cn",
"zh-tw",
"zh-chs",
"zh-hans",
"zh-hk",
"zh-mo",
"zh-sg",
Expand Down Expand Up @@ -252,7 +253,24 @@ var tranCmd = &cobra.Command{
dstLocalize,
filepath.Join(
filepath.Dir(filepath.Dir(c.SrcFile)),
"i18n.gen.go"),
"i18n_const.gen.go"),
)
if err != nil {
log.Errorf("err:%v", err)
return err
}
} else if state.Config.I18n.GenerateField {
dstLocalize, err := i18n.LoadLocalize(c.SrcFile, c.Localizer)
if err != nil {
log.Errorf("err:%v", err)
return err
}

err = codegen.GenerateI18nField(
dstLocalize,
filepath.Join(
filepath.Dir(filepath.Dir(c.SrcFile)),
"i18n_field.gen.go"),
)
if err != nil {
log.Errorf("err:%v", err)
Expand All @@ -268,6 +286,11 @@ func mergeTranCmdFlags(cmd *cobra.Command) {
if cmd.Flag("generate-const").Changed {
state.Config.I18n.GenerateConst = utils.GetBool("generate-const", cmd)
}

if cmd.Flag("generate-field").Changed {
state.Config.I18n.GenerateField = utils.GetBool("generate-field", cmd)
}

if cmd.Flag("translator").Changed {
state.Config.I18n.Translator = utils.GetString("translator", cmd)
}
Expand Down Expand Up @@ -297,6 +320,7 @@ func initTran() {
tranCmd.Flags().StringSliceP("languages", "l", state.Config.I18n.Languages, state.Localize(state.I18nTagCliI18nTranFlagsLanguages))

tranCmd.Flags().Bool("generate-const", state.Config.I18n.GenerateConst, state.Localize(state.I18nTagCliI18nTranFlagsGenerateConst))
tranCmd.Flags().Bool("generate-field", state.Config.I18n.GenerateField, state.Localize(state.I18nTagCliI18nTranFlagsGenerateField))
tranCmd.Flags().String("translator", state.Config.I18n.Translator, state.Localize(state.I18nTagCliI18nTranFlagsTranslatorUsage, map[string]any{
"Type": map[i18n.TransacteType]string{
i18n.TransacteTypeGoogleFree: state.Localize(state.I18nTagCliI18nTranFlagsTranslatorGoogleFree),
Expand Down
Loading

0 comments on commit e458aa8

Please sign in to comment.