File: main.go

package info (click to toggle)
golang-github-chai2010-gettext-go 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,304 kB
  • sloc: makefile: 29
file content (58 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2020 ChaiShushan <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// $ go run . ../..
// $ go run . ../../examples/hi

// The xgettext-go program extracts translatable strings from Go packages.
package main

import (
	"flag"
	"fmt"
	"log"

	"github.com/chai2010/gettext-go/po"
)

var (
	flagPotFile = flag.String("pot-file", "output.pot", "set output pot file path")
	flagHelp    = flag.Bool("h", false, "show help info")
)

func init() {
	log.SetFlags(log.Lshortfile)

	flag.Usage = func() {
		fmt.Println("usage: xgettext-go [flags] pkgpath")
		fmt.Println("       xgettext-go -pot-file=output.pot pkgpath")
		fmt.Println("       xgettext-go -h")
		fmt.Println()

		flag.PrintDefaults()
		fmt.Println()

		fmt.Println("See https://github.com/chai2010/gettext-go")
	}
}

func main() {
	flag.Parse()

	if flag.NArg() == 0 || *flagHelp {
		flag.Usage()
		return
	}

	pkg := LoadPackage(flag.Arg(0))
	potFile := pkg.GenPotFile()

	if err := potFile.Save(*flagPotFile); err != nil {
		log.Fatal(err)
	}

	if _, err := po.LoadFile(*flagPotFile); err != nil {
		log.Println(err)
	}
}