github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/engine/builder/i18n/po.go (about)

     1  package i18n
     2  
     3  import (
     4  	"github.com/metux/go-metabuild/engine/builder/base"
     5  	"github.com/metux/go-metabuild/spec"
     6  	"github.com/metux/go-metabuild/spec/target"
     7  	"github.com/metux/go-metabuild/util/fileutil"
     8  )
     9  
    10  type I18nPo struct {
    11  	base.BaseBuilder
    12  }
    13  
    14  const (
    15  	SuffixPo = ".po"
    16  	SuffixMo = ".mo"
    17  )
    18  
    19  func (b I18nPo) JobRun() error {
    20  	srcdir := b.RequiredEntryStr(target.KeySourceDir)
    21  	catdir := b.RequiredEntryStr(target.KeyI18nCategory)
    22  	perm := b.InstallPerm()
    23  	installdir := b.InstallDir()
    24  	fn := b.RequiredEntryStr(target.KeyI18nDomain) + SuffixMo
    25  	prog := b.BuilderCmd()
    26  
    27  	for _, l := range b.FeaturedStrList(target.KeyI18nLinguas) {
    28  		subdir := fileutil.MkPath(l, catdir)
    29  		outfile := fileutil.MkPath(b.BuildConf.BuildTempDir("po/"+subdir), fn)
    30  		infile := fileutil.MkPath(srcdir, l+SuffixPo)
    31  
    32  		b.ExecAbort(append(prog, "-o", outfile, infile), "")
    33  		b.InstallPkgFile(outfile, fileutil.MkPath(installdir, subdir), perm)
    34  	}
    35  	return nil
    36  }
    37  
    38  func MakeI18nPo(o spec.TargetObject, id string) I18nPo {
    39  	return I18nPo{base.BaseBuilder{o, id}}
    40  }