forked from goinggo/beego-mgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goi18n.go
78 lines (59 loc) · 2.25 KB
/
goi18n.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"flag"
"fmt"
"os"
)
func usage() {
fmt.Printf(`goi18n formats and merges translation files.
Usage:
goi18n [options] [files...]
Translation files:
A translation file contains the strings and translations for a single locale (language + country).
Translation file names must have a suffix of a supported format (e.g. .json) and
contain a valid locale identifier (e.g. ar-EG, en-US, fr-FR, etc.).
For each locale represented by at least one input translation file, goi18n will produce 2 output files:
xx-XX.all.format
This file contains all strings for the locale (translated and untranslated).
xx-XX.untranslated.format
This file contains the strings that have not been translated for this locale.
The translations for the strings in this file will be extracted from the source locale.
Get these strings translated! After they are translated, merge them back into
xx-XX.all.format using goi18n.
goi18n will merge multiple translation files for the same locale.
Duplicate translations will be merged into the existing translation.
Non-empty fields in the duplicate translation will overwrite those fields in the existing translation.
Empty fields in the duplicate translation are ignored.
To produce translation files for a new locale, create an empty translation file with the
appropriate name and pass it in to goi18n.
Options:
-sourceLocale localeId
The id of the locale that strings are initially written in (e.g. xx-XX)
Default: en-US
-outdir directory
goi18n will write the output translation files to this directory.
Default: .
-format format
goi18n will encode the output translation files in this format.
Supported formats: json
Default: json
`)
os.Exit(1)
}
func main() {
flag.Usage = usage
sourceLocale := flag.String("sourceLocale", "en-US", "")
outdir := flag.String("outdir", ".", "")
format := flag.String("format", "json", "")
flag.Parse()
mc := &mergeCommand{
translationFiles: flag.Args(),
sourceLocaleID: *sourceLocale,
outdir: *outdir,
format: *format,
}
if err := mc.execute(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}