|
@@ -1,15 +1,22 @@
|
|
|
package main
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "bytes"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "log"
|
|
|
|
|
|
|
+ "go/format"
|
|
|
|
|
+ "io/ioutil"
|
|
|
"os"
|
|
"os"
|
|
|
- "os/exec"
|
|
|
|
|
|
|
+ "path/filepath"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
+ "sync"
|
|
|
|
|
+ "text/template"
|
|
|
|
|
+ "time"
|
|
|
|
|
+
|
|
|
|
|
+ "gopkg.in/yaml.v2"
|
|
|
|
|
|
|
|
"golang.org/x/text/unicode/cldr"
|
|
"golang.org/x/text/unicode/cldr"
|
|
|
|
|
|
|
|
- "text/template"
|
|
|
|
|
|
|
+ i18n "github.com/go-playground/universal-translator"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// numbers:
|
|
// numbers:
|
|
@@ -29,1304 +36,904 @@ import (
|
|
|
// USD:
|
|
// USD:
|
|
|
// symbol: $
|
|
// symbol: $
|
|
|
|
|
|
|
|
-// type pluralInfo struct {
|
|
|
|
|
-// path string
|
|
|
|
|
-// locale string
|
|
|
|
|
-// plural string
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+type pluralInfo struct {
|
|
|
|
|
+ path string
|
|
|
|
|
+ locale string
|
|
|
|
|
+ plural string
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-// type translator struct {
|
|
|
|
|
-// locale string
|
|
|
|
|
|
|
+func main() {
|
|
|
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
|
|
+ //plurals
|
|
|
|
|
+ rules := "data/rules"
|
|
|
|
|
+ plurals := map[string]*pluralInfo{}
|
|
|
|
|
+ basePlurals := map[string]string{}
|
|
|
|
|
|
|
|
-const (
|
|
|
|
|
- locDir = "../../resources/locales/%s"
|
|
|
|
|
- locFilename = locDir + "/%s.go"
|
|
|
|
|
-)
|
|
|
|
|
|
|
+ err := filepath.Walk(rules, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
|
|
|
-var (
|
|
|
|
|
- prVarFuncs = map[string]string{
|
|
|
|
|
- "n": `n, err := locales.N(num)
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return locales.PluralRuleUnknown, &locales.ErrBadNumberValue{NumberValue:num, InnerError: err}
|
|
|
|
|
|
|
+ panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `,
|
|
|
|
|
- "i": `i, err := locales.I(num)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return locales.PluralRuleUnknown, &locales.ErrBadNumberValue{NumberValue:num, InnerError: err}
|
|
|
|
|
|
|
+ if info.IsDir() {
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `,
|
|
|
|
|
- "v": "v := locales.V(num)\n\n",
|
|
|
|
|
- "w": `w, err := locales.W(num)
|
|
|
|
|
|
|
+ in, err := ioutil.ReadFile(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return locales.PluralRuleUnknown, &locales.ErrBadNumberValue{NumberValue:num, InnerError: err}
|
|
|
|
|
|
|
+ panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `,
|
|
|
|
|
- "f": `f, err := locales.F(num)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return locales.PluralRuleUnknown, &locales.ErrBadNumberValue{NumberValue:num, InnerError: err}
|
|
|
|
|
|
|
+ var out yaml.MapSlice
|
|
|
|
|
+ if err = yaml.Unmarshal(in, &out); err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `,
|
|
|
|
|
- "t": `t, err := locales.T(num)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return locales.PluralRuleUnknown, &locales.ErrBadNumberValue{NumberValue:num, InnerError: err}
|
|
|
|
|
|
|
+ var plural string
|
|
|
|
|
+ for _, item := range out {
|
|
|
|
|
+ if item.Key == "plural" {
|
|
|
|
|
+ plural = item.Value.(string)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- `,
|
|
|
|
|
- }
|
|
|
|
|
-)
|
|
|
|
|
|
|
+ locale := strings.Replace(info.Name(), filepath.Ext(info.Name()), "", 1)
|
|
|
|
|
+ locale = strings.ToLower(strings.Replace(locale, "-", "_", -1))
|
|
|
|
|
|
|
|
-type translator struct {
|
|
|
|
|
- Locale string
|
|
|
|
|
- CardinalFunc string
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ plurals[locale] = &pluralInfo{
|
|
|
|
|
+ path: path,
|
|
|
|
|
+ locale: locale,
|
|
|
|
|
+ plural: plural,
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-var tmpl *template.Template
|
|
|
|
|
|
|
+ if plural == "" {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-func main() {
|
|
|
|
|
|
|
+ basePlurals[locale] = plural
|
|
|
|
|
|
|
|
- var err error
|
|
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // load template
|
|
|
|
|
- tmpl, err = template.ParseGlob("*.tmpl")
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- log.Fatal(err)
|
|
|
|
|
|
|
+ panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // load CLDR recourses
|
|
|
|
|
|
|
+ for _, p := range plurals {
|
|
|
|
|
+
|
|
|
|
|
+ if p.plural == "" {
|
|
|
|
|
+
|
|
|
|
|
+ var ok bool
|
|
|
|
|
+
|
|
|
|
|
+ fmt.Print("can't find plurals in ", p.path, " attempting to locate base language plural rules...")
|
|
|
|
|
+
|
|
|
|
|
+ base := strings.SplitN(p.locale, "_", 2)
|
|
|
|
|
+
|
|
|
|
|
+ p.plural, ok = basePlurals[base[0]]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ fmt.Println("Not Found")
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fmt.Println("Found")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // cldr
|
|
|
|
|
+
|
|
|
var decoder cldr.Decoder
|
|
var decoder cldr.Decoder
|
|
|
cldr, err := decoder.DecodePath("data/core")
|
|
cldr, err := decoder.DecodePath("data/core")
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // cardinalPlurals := map[string]
|
|
|
|
|
|
|
+ locs := map[string]string{}
|
|
|
|
|
+ numbers := map[string]i18n.Number{}
|
|
|
|
|
+ calendars := map[string]i18n.Calendar{}
|
|
|
|
|
+ locales := cldr.Locales()
|
|
|
|
|
+ for _, loc := range locales {
|
|
|
|
|
+
|
|
|
|
|
+ ldml := cldr.RawLDML(loc)
|
|
|
|
|
+ if ldml.Numbers == nil {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ var number i18n.Number
|
|
|
|
|
+
|
|
|
|
|
+ number.Currencies = make(i18n.CurrencyFormatValue)
|
|
|
|
|
|
|
|
- // for _, p := range ldr.Supplemental().Plurals {
|
|
|
|
|
|
|
+ if len(ldml.Numbers.Symbols) > 0 {
|
|
|
|
|
+ symbol := ldml.Numbers.Symbols[0]
|
|
|
|
|
+ if len(symbol.Decimal) > 0 {
|
|
|
|
|
+ number.Symbols.Decimal = symbol.Decimal[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(symbol.Group) > 0 {
|
|
|
|
|
+ number.Symbols.Group = symbol.Group[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(symbol.MinusSign) > 0 {
|
|
|
|
|
+ number.Symbols.Negative = symbol.MinusSign[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(symbol.PercentSign) > 0 {
|
|
|
|
|
+ number.Symbols.Percent = symbol.PercentSign[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(symbol.PerMille) > 0 {
|
|
|
|
|
+ number.Symbols.PerMille = symbol.PerMille[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(ldml.Numbers.DecimalFormats) > 0 && len(ldml.Numbers.DecimalFormats[0].DecimalFormatLength) > 0 {
|
|
|
|
|
+ number.Formats.Decimal = ldml.Numbers.DecimalFormats[0].DecimalFormatLength[0].DecimalFormat[0].Pattern[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // for _, pr := range p.PluralRules {
|
|
|
|
|
|
|
+ if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 {
|
|
|
|
|
|
|
|
- // fmt.Println(pr.Locales)
|
|
|
|
|
|
|
+ number.Formats.Currency = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data()
|
|
|
|
|
+ number.Formats.CurrencyAccounting = number.Formats.Currency
|
|
|
|
|
|
|
|
- // for _, rule := range pr.PluralRule {
|
|
|
|
|
- // fmt.Println(rule.Count, rule.Common.Data())
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 {
|
|
|
|
|
+ number.Formats.CurrencyAccounting = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if len(ldml.Numbers.PercentFormats) > 0 && len(ldml.Numbers.PercentFormats[0].PercentFormatLength) > 0 {
|
|
|
|
|
+ number.Formats.Percent = ldml.Numbers.PercentFormats[0].PercentFormatLength[0].PercentFormat[0].Pattern[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ if ldml.Numbers.Currencies != nil {
|
|
|
|
|
|
|
|
- for _, l := range cldr.Locales() {
|
|
|
|
|
|
|
+ for _, currency := range ldml.Numbers.Currencies.Currency {
|
|
|
|
|
|
|
|
- // // work on uk for the moment
|
|
|
|
|
- // if l != "uk" && l != "fil" && l != "gd" {
|
|
|
|
|
- // if l != "gd" {
|
|
|
|
|
- // continue
|
|
|
|
|
- // }
|
|
|
|
|
- fmt.Println(l)
|
|
|
|
|
|
|
+ var c i18n.Currency
|
|
|
|
|
+
|
|
|
|
|
+ c.Currency = currency.Type
|
|
|
|
|
+
|
|
|
|
|
+ if len(currency.DisplayName) > 0 {
|
|
|
|
|
+ c.DisplayName = currency.DisplayName[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- baseLocale := strings.SplitN(l, "_", 2)[0]
|
|
|
|
|
|
|
+ if len(currency.Symbol) > 0 {
|
|
|
|
|
+ c.Symbol = currency.Symbol[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- trans := &translator{
|
|
|
|
|
- Locale: l,
|
|
|
|
|
- CardinalFunc: parseCardinalPluralRuleFunc(cldr, baseLocale),
|
|
|
|
|
|
|
+ number.Currencies[c.Currency] = c
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ numbers[loc] = number
|
|
|
|
|
+ locs[loc] = strings.ToLower(strings.Replace(loc, "_", "", -1))
|
|
|
|
|
|
|
|
- // cardinalRules := getLocaleCardinalPluralRules(cldr, baseLocale)
|
|
|
|
|
- // fmt.Println("CardinalRules:", l, cardinalRules)
|
|
|
|
|
- // Start Plural Rules
|
|
|
|
|
|
|
+ if ldml.Dates != nil && ldml.Dates.Calendars != nil {
|
|
|
|
|
|
|
|
- // for _, p := range cldr.Supplemental().Plurals {
|
|
|
|
|
|
|
+ var calendar i18n.Calendar
|
|
|
|
|
+ ldmlCar := ldml.Dates.Calendars.Calendar[0]
|
|
|
|
|
|
|
|
- // for _, pr := range p.PluralRules {
|
|
|
|
|
|
|
+ for _, cal := range ldml.Dates.Calendars.Calendar {
|
|
|
|
|
+ if cal.Type == "gregorian" {
|
|
|
|
|
+ ldmlCar = cal
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // locales := strings.Split(pr.Locales, " ")
|
|
|
|
|
|
|
+ if ldmlCar.DateFormats != nil {
|
|
|
|
|
+ for _, datefmt := range ldmlCar.DateFormats.DateFormatLength {
|
|
|
|
|
+ switch datefmt.Type {
|
|
|
|
|
+ case "full":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Full = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Full = calendar.Formats.DateEra.BC.Full
|
|
|
|
|
+
|
|
|
|
|
+ case "long":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Long = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Long = calendar.Formats.DateEra.BC.Long
|
|
|
|
|
+
|
|
|
|
|
+ // Overrides TODO: Split Each Section into separate function, getting to big to maintain
|
|
|
|
|
+
|
|
|
|
|
+ case "medium":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Medium = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Medium = calendar.Formats.DateEra.BC.Medium
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Short = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Short = calendar.Formats.DateEra.BC.Short
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // for _, loc := range locales {
|
|
|
|
|
|
|
+ // Overrides TODO: Split Each Section into separate function, getting to big to maintain
|
|
|
|
|
+ switch loc {
|
|
|
|
|
+ case "th":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Full = "EEEEที่ d MMMM y GGGG"
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Full = "EEEEที่ d MMMM GGGG y"
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Long = "d MMMM y GG"
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Long = "d MMMM GG y"
|
|
|
|
|
+ case "en":
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Full = "EEEE, MMMM d, y GGGG"
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Long = "MMMM d, y GG"
|
|
|
|
|
+ // calendar.Formats.DateEra.BC.Medium = "MMM d, y GG"
|
|
|
|
|
+ // calendar.Formats.DateEra.BC.Short = "M/d/yy G"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // if loc == baseLocale {
|
|
|
|
|
|
|
+ if ldmlCar.TimeFormats != nil {
|
|
|
|
|
+ for _, datefmt := range ldmlCar.TimeFormats.TimeFormatLength {
|
|
|
|
|
+ switch datefmt.Type {
|
|
|
|
|
+ case "full":
|
|
|
|
|
+ calendar.Formats.Time.Full = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "long":
|
|
|
|
|
+ calendar.Formats.Time.Long = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "medium":
|
|
|
|
|
+ calendar.Formats.Time.Medium = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.Formats.Time.Short = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ldmlCar.DateTimeFormats != nil {
|
|
|
|
|
+ for _, datefmt := range ldmlCar.DateTimeFormats.DateTimeFormatLength {
|
|
|
|
|
+ switch datefmt.Type {
|
|
|
|
|
+ case "full":
|
|
|
|
|
+ calendar.Formats.DateTime.Full = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "long":
|
|
|
|
|
+ calendar.Formats.DateTime.Long = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "medium":
|
|
|
|
|
+ calendar.Formats.DateTime.Medium = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.Formats.DateTime.Short = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ldmlCar.Months != nil {
|
|
|
|
|
+
|
|
|
|
|
+ for _, monthctx := range ldmlCar.Months.MonthContext {
|
|
|
|
|
+
|
|
|
|
|
+ for _, months := range monthctx.MonthWidth {
|
|
|
|
|
+
|
|
|
|
|
+ i18nMonth := make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
+
|
|
|
|
|
+ for _, m := range months.Month {
|
|
|
|
|
+ switch m.Type {
|
|
|
|
|
+ case "1":
|
|
|
|
|
+ i18nMonth[time.January] = m.Data()
|
|
|
|
|
+ case "2":
|
|
|
|
|
+ i18nMonth[time.February] = m.Data()
|
|
|
|
|
+ case "3":
|
|
|
|
|
+ i18nMonth[time.March] = m.Data()
|
|
|
|
|
+ case "4":
|
|
|
|
|
+ i18nMonth[time.April] = m.Data()
|
|
|
|
|
+ case "5":
|
|
|
|
|
+ i18nMonth[time.May] = m.Data()
|
|
|
|
|
+ case "6":
|
|
|
|
|
+ i18nMonth[time.June] = m.Data()
|
|
|
|
|
+ case "7":
|
|
|
|
|
+ i18nMonth[time.July] = m.Data()
|
|
|
|
|
+ case "8":
|
|
|
|
|
+ i18nMonth[time.August] = m.Data()
|
|
|
|
|
+ case "9":
|
|
|
|
|
+ i18nMonth[time.September] = m.Data()
|
|
|
|
|
+ case "10":
|
|
|
|
|
+ i18nMonth[time.October] = m.Data()
|
|
|
|
|
+ case "11":
|
|
|
|
|
+ i18nMonth[time.November] = m.Data()
|
|
|
|
|
+ case "12":
|
|
|
|
|
+ i18nMonth[time.December] = m.Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ switch months.Type {
|
|
|
|
|
+ case "abbreviated":
|
|
|
|
|
+ calendar.FormatNames.Months.Abbreviated = i18nMonth
|
|
|
|
|
+ case "narrow":
|
|
|
|
|
+ calendar.FormatNames.Months.Narrow = i18nMonth
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.FormatNames.Months.Short = i18nMonth
|
|
|
|
|
+ case "wide":
|
|
|
|
|
+ calendar.FormatNames.Months.Wide = i18nMonth
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ldmlCar.Days != nil {
|
|
|
|
|
+ for _, dayctx := range ldmlCar.Days.DayContext {
|
|
|
|
|
+
|
|
|
|
|
+ for _, days := range dayctx.DayWidth {
|
|
|
|
|
+
|
|
|
|
|
+ i18nDay := make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
+
|
|
|
|
|
+ for _, d := range days.Day {
|
|
|
|
|
+
|
|
|
|
|
+ switch d.Type {
|
|
|
|
|
+ case "sun":
|
|
|
|
|
+ i18nDay[time.Sunday] = d.Data()
|
|
|
|
|
+ case "mon":
|
|
|
|
|
+ i18nDay[time.Monday] = d.Data()
|
|
|
|
|
+ case "tue":
|
|
|
|
|
+ i18nDay[time.Tuesday] = d.Data()
|
|
|
|
|
+ case "wed":
|
|
|
|
|
+ i18nDay[time.Wednesday] = d.Data()
|
|
|
|
|
+ case "thu":
|
|
|
|
|
+ i18nDay[time.Thursday] = d.Data()
|
|
|
|
|
+ case "fri":
|
|
|
|
|
+ i18nDay[time.Friday] = d.Data()
|
|
|
|
|
+ case "sat":
|
|
|
|
|
+ i18nDay[time.Saturday] = d.Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch days.Type {
|
|
|
|
|
+ case "abbreviated":
|
|
|
|
|
+ calendar.FormatNames.Days.Abbreviated = i18nDay
|
|
|
|
|
+ case "narrow":
|
|
|
|
|
+ calendar.FormatNames.Days.Narrow = i18nDay
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.FormatNames.Days.Short = i18nDay
|
|
|
|
|
+ case "wide":
|
|
|
|
|
+ calendar.FormatNames.Days.Wide = i18nDay
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.DayPeriods != nil {
|
|
|
|
|
+
|
|
|
|
|
+ for _, ctx := range ldmlCar.DayPeriods.DayPeriodContext {
|
|
|
|
|
+
|
|
|
|
|
+ for _, width := range ctx.DayPeriodWidth {
|
|
|
|
|
|
|
|
- // // plural rule found
|
|
|
|
|
- // fmt.Println("Locale Plural Rules Found:", loc, baseLocale, l)
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // // fmt.Println(pr.Locales)
|
|
|
|
|
|
|
+ // var i18nPeriod i18n.CalendarPeriodFormatNameValue
|
|
|
|
|
+ i18nPeriod := make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
|
|
|
- // // for _, rule := range pr.PluralRule {
|
|
|
|
|
- // // fmt.Println(rule.Count, rule.Common.Data())
|
|
|
|
|
- // // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ for _, d := range width.DayPeriod {
|
|
|
|
|
|
|
|
- // End Plural Rules
|
|
|
|
|
|
|
+ if _, ok := i18nPeriod[d.Type]; !ok {
|
|
|
|
|
+ i18nPeriod[d.Type] = d.Data()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch width.Type {
|
|
|
|
|
+ case "abbreviated":
|
|
|
|
|
+ calendar.FormatNames.Periods.Abbreviated = i18nPeriod
|
|
|
|
|
+ case "narrow":
|
|
|
|
|
+ calendar.FormatNames.Periods.Narrow = i18nPeriod
|
|
|
|
|
+ case "short":
|
|
|
|
|
+ calendar.FormatNames.Periods.Short = i18nPeriod
|
|
|
|
|
+ case "wide":
|
|
|
|
|
+ calendar.FormatNames.Periods.Wide = i18nPeriod
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // var empty i18n.CalendarPeriodFormatNameValue
|
|
|
|
|
+ // if calendar.FormatNames.Periods.Abbreviated == empty {
|
|
|
|
|
+ // calendar.FormatNames.Periods.Abbreviated = calendar.FormatNames.Periods.Wide
|
|
|
|
|
+ // }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras != nil {
|
|
|
|
|
+
|
|
|
|
|
+ var eras i18n.Eras
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras.EraNames != nil && len(ldmlCar.Eras.EraNames.Era) > 0 {
|
|
|
|
|
+ eras.BC.Full = ldmlCar.Eras.EraNames.Era[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras.EraAbbr != nil && len(ldmlCar.Eras.EraAbbr.Era) > 0 {
|
|
|
|
|
+ eras.BC.Abbrev = ldmlCar.Eras.EraAbbr.Era[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras.EraNarrow != nil && len(ldmlCar.Eras.EraNarrow.Era) > 0 {
|
|
|
|
|
+ eras.BC.Narrow = ldmlCar.Eras.EraNarrow.Era[0].Data()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if err = os.MkdirAll(fmt.Sprintf(locDir, l), 0777); err != nil {
|
|
|
|
|
- log.Fatal(err)
|
|
|
|
|
|
|
+ if ldmlCar.Eras.EraNames != nil && len(ldmlCar.Eras.EraNames.Era) > 2 {
|
|
|
|
|
+ eras.AD.Full = ldmlCar.Eras.EraNames.Era[2].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras.EraAbbr != nil && len(ldmlCar.Eras.EraAbbr.Era) > 2 {
|
|
|
|
|
+ eras.AD.Abbrev = ldmlCar.Eras.EraAbbr.Era[2].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ldmlCar.Eras.EraNarrow != nil && len(ldmlCar.Eras.EraNarrow.Era) > 2 {
|
|
|
|
|
+ eras.AD.Narrow = ldmlCar.Eras.EraNarrow.Era[2].Data()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ calendar.FormatNames.Eras = eras
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ calendars[loc] = calendar
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- filename := fmt.Sprintf(locFilename, l, l)
|
|
|
|
|
|
|
+ for locale := range locs {
|
|
|
|
|
|
|
|
- output, err := os.Create(filename)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- log.Fatal(err)
|
|
|
|
|
|
|
+ if !strings.Contains(locale, "_") {
|
|
|
|
|
+ continue
|
|
|
}
|
|
}
|
|
|
- defer output.Close()
|
|
|
|
|
|
|
|
|
|
- if err := tmpl.ExecuteTemplate(output, "translator", trans); err != nil {
|
|
|
|
|
- log.Fatal(err)
|
|
|
|
|
|
|
+ calendar := calendars[locale]
|
|
|
|
|
+
|
|
|
|
|
+ bString := strings.SplitN(locale, "_", 2)
|
|
|
|
|
+ base := bString[0]
|
|
|
|
|
+
|
|
|
|
|
+ baseCal := calendars[base]
|
|
|
|
|
+
|
|
|
|
|
+ // copy base calendar objects
|
|
|
|
|
+
|
|
|
|
|
+ // Dates
|
|
|
|
|
+ if calendar.Formats.DateEra.AD.Full == "" {
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Full = baseCal.Formats.DateEra.BC.Full
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Full = baseCal.Formats.DateEra.AD.Full
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- output.Close()
|
|
|
|
|
|
|
+ if calendar.Formats.DateEra.AD.Long == "" {
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Long = baseCal.Formats.DateEra.BC.Long
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Long = baseCal.Formats.DateEra.AD.Long
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // after file written run gofmt on file to ensure best formatting
|
|
|
|
|
- cmd := exec.Command("gofmt", "-s", "-w", filename)
|
|
|
|
|
- if err = cmd.Run(); err != nil {
|
|
|
|
|
- log.Panic(err)
|
|
|
|
|
|
|
+ if calendar.Formats.DateEra.AD.Medium == "" {
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Medium = baseCal.Formats.DateEra.BC.Medium
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Medium = baseCal.Formats.DateEra.AD.Medium
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-// TODO: cleanup function logic perhaps write a lexer... but it's working right now, and
|
|
|
|
|
-// I'm already farther down the rabbit hole than I'd like and so pulling the chute here.
|
|
|
|
|
-func parseCardinalPluralRuleFunc(current *cldr.CLDR, baseLocale string) (results string) {
|
|
|
|
|
-
|
|
|
|
|
- var prCardinal *struct {
|
|
|
|
|
- cldr.Common
|
|
|
|
|
- Locales string "xml:\"locales,attr\""
|
|
|
|
|
- PluralRule []*struct {
|
|
|
|
|
- cldr.Common
|
|
|
|
|
- Count string "xml:\"count,attr\""
|
|
|
|
|
- } "xml:\"pluralRule\""
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if calendar.Formats.DateEra.AD.Short == "" {
|
|
|
|
|
+ calendar.Formats.DateEra.BC.Short = baseCal.Formats.DateEra.BC.Short
|
|
|
|
|
+ calendar.Formats.DateEra.AD.Short = baseCal.Formats.DateEra.AD.Short
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // times
|
|
|
|
|
+ if calendar.Formats.Time.Full == "" {
|
|
|
|
|
+ calendar.Formats.Time.Full = baseCal.Formats.Time.Full
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, p := range current.Supplemental().Plurals {
|
|
|
|
|
|
|
+ if calendar.Formats.Time.Long == "" {
|
|
|
|
|
+ calendar.Formats.Time.Long = baseCal.Formats.Time.Long
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, pr := range p.PluralRules {
|
|
|
|
|
|
|
+ if calendar.Formats.Time.Medium == "" {
|
|
|
|
|
+ calendar.Formats.Time.Medium = baseCal.Formats.Time.Medium
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- locs := strings.Split(pr.Locales, " ")
|
|
|
|
|
|
|
+ if calendar.Formats.Time.Short == "" {
|
|
|
|
|
+ calendar.Formats.Time.Short = baseCal.Formats.Time.Short
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, loc := range locs {
|
|
|
|
|
|
|
+ // date & times
|
|
|
|
|
+ if calendar.Formats.DateTime.Full == "" {
|
|
|
|
|
+ calendar.Formats.DateTime.Full = baseCal.Formats.DateTime.Full
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if loc == baseLocale {
|
|
|
|
|
- prCardinal = pr
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if calendar.Formats.DateTime.Long == "" {
|
|
|
|
|
+ calendar.Formats.DateTime.Long = baseCal.Formats.DateTime.Long
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.Formats.DateTime.Medium == "" {
|
|
|
|
|
+ calendar.Formats.DateTime.Medium = baseCal.Formats.DateTime.Medium
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.Formats.DateTime.Short == "" {
|
|
|
|
|
+ calendar.Formats.DateTime.Short = baseCal.Formats.DateTime.Short
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // months
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.FormatNames.Months.Abbreviated == nil {
|
|
|
|
|
+ calendar.FormatNames.Months.Abbreviated = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.FormatNames.Months.Narrow == nil {
|
|
|
|
|
+ calendar.FormatNames.Months.Narrow = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.FormatNames.Months.Short == nil {
|
|
|
|
|
+ calendar.FormatNames.Months.Short = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.FormatNames.Months.Wide == nil {
|
|
|
|
|
+ calendar.FormatNames.Months.Wide = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Months.Abbreviated {
|
|
|
|
|
+
|
|
|
|
|
+ val, ok := calendar.FormatNames.Months.Abbreviated[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Months.Abbreviated[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Months.Abbreviated[k] = v
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // no plural rules for locale
|
|
|
|
|
- if prCardinal == nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Months.Narrow {
|
|
|
|
|
|
|
|
- vals := make(map[string]struct{})
|
|
|
|
|
- first := true
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Months.Narrow[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Months.Narrow[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // pre parse for variables
|
|
|
|
|
- for _, rule := range prCardinal.PluralRule {
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Months.Narrow[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- data := strings.Replace(strings.Replace(strings.Replace(strings.TrimSpace(strings.SplitN(rule.Common.Data(), "@", 2)[0]), " = ", " == ", -1), " or ", " || ", -1), " and ", " && ", -1)
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Months.Short {
|
|
|
|
|
|
|
|
- if len(data) == 0 {
|
|
|
|
|
- if len(prCardinal.PluralRule) == 1 {
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Months.Short[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Months.Short[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- results = "return locales." + pluralStringToString(rule.Count) + ", nil"
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Months.Short[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Months.Wide {
|
|
|
|
|
|
|
|
- results += "\n\nreturn locales." + pluralStringToString(rule.Count) + ", nil"
|
|
|
|
|
- // results += "else {\nreturn locales." + locales.PluralStringToString(rule.Count) + ", nil\n}"
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Months.Wide[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Months.Wide[k] = v
|
|
|
|
|
+ continue
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Months.Wide[k] = v
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "n") {
|
|
|
|
|
- vals[prVarFuncs["n"]] = struct{}{}
|
|
|
|
|
|
|
+ // days
|
|
|
|
|
+
|
|
|
|
|
+ if calendar.FormatNames.Days.Abbreviated == nil {
|
|
|
|
|
+ calendar.FormatNames.Days.Abbreviated = make(i18n.CalendarDayFormatNameValue)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "i") {
|
|
|
|
|
- vals[prVarFuncs["i"]] = struct{}{}
|
|
|
|
|
|
|
+ if calendar.FormatNames.Days.Narrow == nil {
|
|
|
|
|
+ calendar.FormatNames.Days.Narrow = make(i18n.CalendarDayFormatNameValue)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "v") {
|
|
|
|
|
- vals[prVarFuncs["v"]] = struct{}{}
|
|
|
|
|
|
|
+ if calendar.FormatNames.Days.Short == nil {
|
|
|
|
|
+ calendar.FormatNames.Days.Short = make(i18n.CalendarDayFormatNameValue)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "w") {
|
|
|
|
|
- vals[prVarFuncs["w"]] = struct{}{}
|
|
|
|
|
|
|
+ if calendar.FormatNames.Days.Wide == nil {
|
|
|
|
|
+ calendar.FormatNames.Days.Wide = make(i18n.CalendarDayFormatNameValue)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "f") {
|
|
|
|
|
- vals[prVarFuncs["f"]] = struct{}{}
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Days.Abbreviated {
|
|
|
|
|
+
|
|
|
|
|
+ val, ok := calendar.FormatNames.Days.Abbreviated[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Days.Abbreviated[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Days.Abbreviated[k] = v
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if strings.Contains(data, "t") {
|
|
|
|
|
- vals[prVarFuncs["t"]] = struct{}{}
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Days.Narrow {
|
|
|
|
|
+
|
|
|
|
|
+ val, ok := calendar.FormatNames.Days.Narrow[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Days.Narrow[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Days.Narrow[k] = v
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // fmt.Println(rule.Count, data)
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Days.Short {
|
|
|
|
|
+
|
|
|
|
|
+ val, ok := calendar.FormatNames.Days.Short[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Days.Short[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if first {
|
|
|
|
|
- results += "if "
|
|
|
|
|
- first = false
|
|
|
|
|
- } else {
|
|
|
|
|
- results += "else if "
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Days.Short[k] = v
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- stmt := ""
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Days.Wide {
|
|
|
|
|
|
|
|
- // real work here
|
|
|
|
|
- //
|
|
|
|
|
- // split by 'or' then by 'and' allowing to better
|
|
|
|
|
- // determine bracketing for formula
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Days.Wide[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Days.Wide[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- ors := strings.Split(data, "||")
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Days.Wide[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, or := range ors {
|
|
|
|
|
|
|
+ // periods
|
|
|
|
|
+ if calendar.FormatNames.Periods.Abbreviated == nil {
|
|
|
|
|
+ calendar.FormatNames.Periods.Abbreviated = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- stmt += "("
|
|
|
|
|
|
|
+ if calendar.FormatNames.Periods.Narrow == nil {
|
|
|
|
|
+ calendar.FormatNames.Periods.Narrow = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- ands := strings.Split(strings.TrimSpace(or), "&&")
|
|
|
|
|
|
|
+ if calendar.FormatNames.Periods.Short == nil {
|
|
|
|
|
+ calendar.FormatNames.Periods.Short = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for _, and := range ands {
|
|
|
|
|
|
|
+ if calendar.FormatNames.Periods.Wide == nil {
|
|
|
|
|
+ calendar.FormatNames.Periods.Wide = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- inArg := false
|
|
|
|
|
- pre := ""
|
|
|
|
|
- lft := ""
|
|
|
|
|
- preOperator := ""
|
|
|
|
|
- args := strings.Split(strings.TrimSpace(and), " ")
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Periods.Abbreviated {
|
|
|
|
|
|
|
|
- for _, a := range args {
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Periods.Abbreviated[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Periods.Abbreviated[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if inArg {
|
|
|
|
|
- // check to see if is a value range 2..9
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Periods.Abbreviated[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- multiRange := strings.Count(a, "..") > 1
|
|
|
|
|
- cargs := strings.Split(strings.TrimSpace(a), ",")
|
|
|
|
|
- hasBracket := len(cargs) > 1
|
|
|
|
|
- bracketAdded := false
|
|
|
|
|
- lastWasRange := false
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Periods.Narrow {
|
|
|
|
|
|
|
|
- for _, carg := range cargs {
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Periods.Narrow[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Periods.Narrow[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Periods.Narrow[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if rng := strings.Split(carg, ".."); len(rng) > 1 {
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Periods.Short {
|
|
|
|
|
|
|
|
- if multiRange {
|
|
|
|
|
- pre += " ("
|
|
|
|
|
- } else {
|
|
|
|
|
- pre += " "
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Periods.Short[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Periods.Short[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- switch preOperator {
|
|
|
|
|
- case "==":
|
|
|
|
|
- pre += lft + " >= " + rng[0] + " && " + lft + "<=" + rng[1]
|
|
|
|
|
- case "!=":
|
|
|
|
|
- pre += lft + " < " + rng[0] + " && " + lft + " > " + rng[1]
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Periods.Short[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if multiRange {
|
|
|
|
|
- pre += ") || "
|
|
|
|
|
- } else {
|
|
|
|
|
- pre += " || "
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ for k, v := range baseCal.FormatNames.Periods.Wide {
|
|
|
|
|
|
|
|
- lastWasRange = true
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val, ok := calendar.FormatNames.Periods.Wide[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ calendar.FormatNames.Periods.Wide[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if lastWasRange {
|
|
|
|
|
- pre = strings.TrimRight(pre, " || ") + " && "
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if val == "" {
|
|
|
|
|
+ calendar.FormatNames.Periods.Wide[k] = v
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- lastWasRange = false
|
|
|
|
|
|
|
+ calendars[locale] = calendar
|
|
|
|
|
|
|
|
- if hasBracket && !bracketAdded {
|
|
|
|
|
- pre += "("
|
|
|
|
|
- bracketAdded = true
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ number := numbers[locale]
|
|
|
|
|
+ baseNum := numbers[base]
|
|
|
|
|
|
|
|
- // single comma separated values
|
|
|
|
|
- switch preOperator {
|
|
|
|
|
- case "==":
|
|
|
|
|
- pre += " " + lft + preOperator + carg + " || "
|
|
|
|
|
- case "!=":
|
|
|
|
|
- pre += " " + lft + preOperator + carg + " && "
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // symbols
|
|
|
|
|
+ if number.Symbols.Decimal == "" {
|
|
|
|
|
+ number.Symbols.Decimal = baseNum.Symbols.Decimal
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if number.Symbols.Group == "" {
|
|
|
|
|
+ number.Symbols.Group = baseNum.Symbols.Group
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- pre = strings.TrimRight(pre, " || ")
|
|
|
|
|
- pre = strings.TrimRight(pre, " && ")
|
|
|
|
|
- pre = strings.TrimRight(pre, " || ")
|
|
|
|
|
|
|
+ if number.Symbols.Negative == "" {
|
|
|
|
|
+ number.Symbols.Negative = baseNum.Symbols.Negative
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if hasBracket && bracketAdded {
|
|
|
|
|
- pre += ")"
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if number.Symbols.Percent == "" {
|
|
|
|
|
+ number.Symbols.Percent = baseNum.Symbols.Percent
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if number.Symbols.PerMille == "" {
|
|
|
|
|
+ number.Symbols.PerMille = baseNum.Symbols.PerMille
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if strings.Contains(a, "=") || a == ">" || a == "<" {
|
|
|
|
|
- inArg = true
|
|
|
|
|
- preOperator = a
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // formats
|
|
|
|
|
+ if number.Formats.Decimal == "" {
|
|
|
|
|
+ number.Formats.Decimal = baseNum.Formats.Decimal
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- lft += a
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if number.Formats.Currency == "" {
|
|
|
|
|
+ number.Formats.Currency = baseNum.Formats.Currency
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- stmt += pre + " && "
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if number.Formats.CurrencyAccounting == "" {
|
|
|
|
|
+ number.Formats.CurrencyAccounting = baseNum.Formats.CurrencyAccounting
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- stmt = strings.TrimRight(stmt, " && ") + ") || "
|
|
|
|
|
|
|
+ if number.Formats.Percent == "" {
|
|
|
|
|
+ number.Formats.Percent = baseNum.Formats.Percent
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- stmt = strings.TrimRight(stmt, " || ")
|
|
|
|
|
|
|
+ // currency
|
|
|
|
|
+ for k, v := range baseNum.Currencies {
|
|
|
|
|
|
|
|
- results += stmt
|
|
|
|
|
|
|
+ val, ok := number.Currencies[k]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ // number.Currencies[k] = v
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- results += " {\n"
|
|
|
|
|
|
|
+ if val.Currency == "" {
|
|
|
|
|
+ val.Currency = v.Currency
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // return plural rule here
|
|
|
|
|
- results += "return locales." + pluralStringToString(rule.Count) + ", nil\n"
|
|
|
|
|
|
|
+ if val.DisplayName == "" {
|
|
|
|
|
+ val.DisplayName = v.DisplayName
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- results += "}"
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if val.Symbol == "" {
|
|
|
|
|
+ val.Symbol = v.Symbol
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- pre := "\n"
|
|
|
|
|
|
|
+ number.Currencies[k] = val
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for k := range vals {
|
|
|
|
|
- pre += k
|
|
|
|
|
|
|
+ numbers[locale] = number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pre += "\n"
|
|
|
|
|
|
|
+ var wg sync.WaitGroup
|
|
|
|
|
+ wg.Add(len(numbers))
|
|
|
|
|
+ for locale, number := range numbers {
|
|
|
|
|
+ go func(locale string, number i18n.Number) {
|
|
|
|
|
|
|
|
- if len(results) == 0 {
|
|
|
|
|
- results = "return locales.PluralRuleUnknown,nil"
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ localeLowercase := strings.ToLower(locale)
|
|
|
|
|
|
|
|
- results = pre + results
|
|
|
|
|
|
|
+ defer func() { wg.Done() }()
|
|
|
|
|
+ path := "../../resources/locales/" + locale
|
|
|
|
|
|
|
|
- return
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ if _, err := os.Stat(path); err != nil {
|
|
|
|
|
+ if err = os.MkdirAll(path, 0777); err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-func pluralStringToString(pr string) string {
|
|
|
|
|
-
|
|
|
|
|
- pr = strings.TrimSpace(pr)
|
|
|
|
|
-
|
|
|
|
|
- switch pr {
|
|
|
|
|
- case "zero":
|
|
|
|
|
- return "PluralRuleZero"
|
|
|
|
|
- case "one":
|
|
|
|
|
- return "PluralRuleOne"
|
|
|
|
|
- case "two":
|
|
|
|
|
- return "PluralRuleTwo"
|
|
|
|
|
- case "few":
|
|
|
|
|
- return "PluralRuleFew"
|
|
|
|
|
- case "many":
|
|
|
|
|
- return "PluralRuleMany"
|
|
|
|
|
- case "other":
|
|
|
|
|
- return "PluralRuleOther"
|
|
|
|
|
- default:
|
|
|
|
|
- return "PluralRuleUnknown"
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ path += "/"
|
|
|
|
|
|
|
|
-// //plurals
|
|
|
|
|
-// rules := "data/rules"
|
|
|
|
|
-// plurals := map[string]*pluralInfo{}
|
|
|
|
|
-// basePlurals := map[string]string{}
|
|
|
|
|
|
|
+ mainFile, err := os.Create(path + "main.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer mainFile.Close()
|
|
|
|
|
+
|
|
|
|
|
+ calendar := calendars[locale]
|
|
|
|
|
+
|
|
|
|
|
+ mainCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
+ import "github.com/go-playground/universal-translator"
|
|
|
|
|
+
|
|
|
|
|
+ var locale = &ut.Locale{
|
|
|
|
|
+ Locale: %q,
|
|
|
|
|
+ Number: ut.Number{
|
|
|
|
|
+ Symbols: symbols,
|
|
|
|
|
+ Formats: formats,
|
|
|
|
|
+ Currencies: currencies,
|
|
|
|
|
+ },
|
|
|
|
|
+ Calendar: calendar,
|
|
|
|
|
+ PluralRule: pluralRule,
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// err := filepath.Walk(rules, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
-
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if info.IsDir() {
|
|
|
|
|
-// return nil
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// in, err := ioutil.ReadFile(path)
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// var out yaml.MapSlice
|
|
|
|
|
-// if err = yaml.Unmarshal(in, &out); err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// var plural string
|
|
|
|
|
-// for _, item := range out {
|
|
|
|
|
-// if item.Key == "plural" {
|
|
|
|
|
-// plural = item.Value.(string)
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// locale := strings.Replace(info.Name(), filepath.Ext(info.Name()), "", 1)
|
|
|
|
|
-// locale = strings.ToLower(strings.Replace(locale, "-", "_", -1))
|
|
|
|
|
-
|
|
|
|
|
-// plurals[locale] = &pluralInfo{
|
|
|
|
|
-// path: path,
|
|
|
|
|
-// locale: locale,
|
|
|
|
|
-// plural: plural,
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if plural == "" {
|
|
|
|
|
-// return nil
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// basePlurals[locale] = plural
|
|
|
|
|
-
|
|
|
|
|
-// return nil
|
|
|
|
|
-// })
|
|
|
|
|
-
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for _, p := range plurals {
|
|
|
|
|
-
|
|
|
|
|
-// if p.plural == "" {
|
|
|
|
|
-
|
|
|
|
|
-// var ok bool
|
|
|
|
|
-
|
|
|
|
|
-// fmt.Print("can't find plurals in ", p.path, " attempting to locate base language plural rules...")
|
|
|
|
|
-
|
|
|
|
|
-// base := strings.SplitN(p.locale, "_", 2)
|
|
|
|
|
-
|
|
|
|
|
-// p.plural, ok = basePlurals[base[0]]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// fmt.Println("Not Found")
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// fmt.Println("Found")
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// cldr
|
|
|
|
|
-
|
|
|
|
|
-// var decoder cldr.Decoder
|
|
|
|
|
-// cldr, err := decoder.DecodePath("data/core")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// locs := map[string]string{}
|
|
|
|
|
-// numbers := map[string]i18n.Number{}
|
|
|
|
|
-// calendars := map[string]i18n.Calendar{}
|
|
|
|
|
-// locales := cldr.Locales()
|
|
|
|
|
-// for _, loc := range locales {
|
|
|
|
|
-
|
|
|
|
|
-// ldml := cldr.RawLDML(loc)
|
|
|
|
|
-// if ldml.Numbers == nil {
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-// var number i18n.Number
|
|
|
|
|
-
|
|
|
|
|
-// number.Currencies = make(i18n.CurrencyFormatValue)
|
|
|
|
|
-
|
|
|
|
|
-// if len(ldml.Numbers.Symbols) > 0 {
|
|
|
|
|
-// symbol := ldml.Numbers.Symbols[0]
|
|
|
|
|
-// if len(symbol.Decimal) > 0 {
|
|
|
|
|
-// number.Symbols.Decimal = symbol.Decimal[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(symbol.Group) > 0 {
|
|
|
|
|
-// number.Symbols.Group = symbol.Group[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(symbol.MinusSign) > 0 {
|
|
|
|
|
-// number.Symbols.Negative = symbol.MinusSign[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(symbol.PercentSign) > 0 {
|
|
|
|
|
-// number.Symbols.Percent = symbol.PercentSign[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(symbol.PerMille) > 0 {
|
|
|
|
|
-// number.Symbols.PerMille = symbol.PerMille[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(ldml.Numbers.DecimalFormats) > 0 && len(ldml.Numbers.DecimalFormats[0].DecimalFormatLength) > 0 {
|
|
|
|
|
-// number.Formats.Decimal = ldml.Numbers.DecimalFormats[0].DecimalFormatLength[0].DecimalFormat[0].Pattern[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if len(ldml.Numbers.CurrencyFormats) > 0 && len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength) > 0 {
|
|
|
|
|
-
|
|
|
|
|
-// number.Formats.Currency = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[0].Pattern[0].Data()
|
|
|
|
|
-// number.Formats.CurrencyAccounting = number.Formats.Currency
|
|
|
|
|
-
|
|
|
|
|
-// if len(ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat) > 1 {
|
|
|
|
|
-// number.Formats.CurrencyAccounting = ldml.Numbers.CurrencyFormats[0].CurrencyFormatLength[0].CurrencyFormat[1].Pattern[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if len(ldml.Numbers.PercentFormats) > 0 && len(ldml.Numbers.PercentFormats[0].PercentFormatLength) > 0 {
|
|
|
|
|
-// number.Formats.Percent = ldml.Numbers.PercentFormats[0].PercentFormatLength[0].PercentFormat[0].Pattern[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// if ldml.Numbers.Currencies != nil {
|
|
|
|
|
-
|
|
|
|
|
-// for _, currency := range ldml.Numbers.Currencies.Currency {
|
|
|
|
|
-
|
|
|
|
|
-// var c i18n.Currency
|
|
|
|
|
-
|
|
|
|
|
-// c.Currency = currency.Type
|
|
|
|
|
-
|
|
|
|
|
-// if len(currency.DisplayName) > 0 {
|
|
|
|
|
-// c.DisplayName = currency.DisplayName[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if len(currency.Symbol) > 0 {
|
|
|
|
|
-// c.Symbol = currency.Symbol[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// number.Currencies[c.Currency] = c
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// numbers[loc] = number
|
|
|
|
|
-// locs[loc] = strings.ToLower(strings.Replace(loc, "_", "", -1))
|
|
|
|
|
-
|
|
|
|
|
-// if ldml.Dates != nil && ldml.Dates.Calendars != nil {
|
|
|
|
|
-
|
|
|
|
|
-// var calendar i18n.Calendar
|
|
|
|
|
-// ldmlCar := ldml.Dates.Calendars.Calendar[0]
|
|
|
|
|
-
|
|
|
|
|
-// for _, cal := range ldml.Dates.Calendars.Calendar {
|
|
|
|
|
-// if cal.Type == "gregorian" {
|
|
|
|
|
-// ldmlCar = cal
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.DateFormats != nil {
|
|
|
|
|
-// for _, datefmt := range ldmlCar.DateFormats.DateFormatLength {
|
|
|
|
|
-// switch datefmt.Type {
|
|
|
|
|
-// case "full":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Full = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Full = calendar.Formats.DateEra.BC.Full
|
|
|
|
|
-
|
|
|
|
|
-// case "long":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Long = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Long = calendar.Formats.DateEra.BC.Long
|
|
|
|
|
-
|
|
|
|
|
-// // Overrides TODO: Split Each Section into separate function, getting to big to maintain
|
|
|
|
|
-
|
|
|
|
|
-// case "medium":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Medium = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Medium = calendar.Formats.DateEra.BC.Medium
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Short = datefmt.DateFormat[0].Pattern[0].Data()
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Short = calendar.Formats.DateEra.BC.Short
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // Overrides TODO: Split Each Section into separate function, getting to big to maintain
|
|
|
|
|
-// switch loc {
|
|
|
|
|
-// case "th":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Full = "EEEEที่ d MMMM y GGGG"
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Full = "EEEEที่ d MMMM GGGG y"
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Long = "d MMMM y GG"
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Long = "d MMMM GG y"
|
|
|
|
|
-// case "en":
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Full = "EEEE, MMMM d, y GGGG"
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Long = "MMMM d, y GG"
|
|
|
|
|
-// // calendar.Formats.DateEra.BC.Medium = "MMM d, y GG"
|
|
|
|
|
-// // calendar.Formats.DateEra.BC.Short = "M/d/yy G"
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.TimeFormats != nil {
|
|
|
|
|
-// for _, datefmt := range ldmlCar.TimeFormats.TimeFormatLength {
|
|
|
|
|
-// switch datefmt.Type {
|
|
|
|
|
-// case "full":
|
|
|
|
|
-// calendar.Formats.Time.Full = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "long":
|
|
|
|
|
-// calendar.Formats.Time.Long = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "medium":
|
|
|
|
|
-// calendar.Formats.Time.Medium = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.Formats.Time.Short = datefmt.TimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if ldmlCar.DateTimeFormats != nil {
|
|
|
|
|
-// for _, datefmt := range ldmlCar.DateTimeFormats.DateTimeFormatLength {
|
|
|
|
|
-// switch datefmt.Type {
|
|
|
|
|
-// case "full":
|
|
|
|
|
-// calendar.Formats.DateTime.Full = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "long":
|
|
|
|
|
-// calendar.Formats.DateTime.Long = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "medium":
|
|
|
|
|
-// calendar.Formats.DateTime.Medium = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.Formats.DateTime.Short = datefmt.DateTimeFormat[0].Pattern[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if ldmlCar.Months != nil {
|
|
|
|
|
-
|
|
|
|
|
-// for _, monthctx := range ldmlCar.Months.MonthContext {
|
|
|
|
|
-
|
|
|
|
|
-// for _, months := range monthctx.MonthWidth {
|
|
|
|
|
-
|
|
|
|
|
-// i18nMonth := make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
-
|
|
|
|
|
-// for _, m := range months.Month {
|
|
|
|
|
-// switch m.Type {
|
|
|
|
|
-// case "1":
|
|
|
|
|
-// i18nMonth[time.January] = m.Data()
|
|
|
|
|
-// case "2":
|
|
|
|
|
-// i18nMonth[time.February] = m.Data()
|
|
|
|
|
-// case "3":
|
|
|
|
|
-// i18nMonth[time.March] = m.Data()
|
|
|
|
|
-// case "4":
|
|
|
|
|
-// i18nMonth[time.April] = m.Data()
|
|
|
|
|
-// case "5":
|
|
|
|
|
-// i18nMonth[time.May] = m.Data()
|
|
|
|
|
-// case "6":
|
|
|
|
|
-// i18nMonth[time.June] = m.Data()
|
|
|
|
|
-// case "7":
|
|
|
|
|
-// i18nMonth[time.July] = m.Data()
|
|
|
|
|
-// case "8":
|
|
|
|
|
-// i18nMonth[time.August] = m.Data()
|
|
|
|
|
-// case "9":
|
|
|
|
|
-// i18nMonth[time.September] = m.Data()
|
|
|
|
|
-// case "10":
|
|
|
|
|
-// i18nMonth[time.October] = m.Data()
|
|
|
|
|
-// case "11":
|
|
|
|
|
-// i18nMonth[time.November] = m.Data()
|
|
|
|
|
-// case "12":
|
|
|
|
|
-// i18nMonth[time.December] = m.Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// switch months.Type {
|
|
|
|
|
-// case "abbreviated":
|
|
|
|
|
-// calendar.FormatNames.Months.Abbreviated = i18nMonth
|
|
|
|
|
-// case "narrow":
|
|
|
|
|
-// calendar.FormatNames.Months.Narrow = i18nMonth
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.FormatNames.Months.Short = i18nMonth
|
|
|
|
|
-// case "wide":
|
|
|
|
|
-// calendar.FormatNames.Months.Wide = i18nMonth
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if ldmlCar.Days != nil {
|
|
|
|
|
-// for _, dayctx := range ldmlCar.Days.DayContext {
|
|
|
|
|
-
|
|
|
|
|
-// for _, days := range dayctx.DayWidth {
|
|
|
|
|
-
|
|
|
|
|
-// i18nDay := make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
-
|
|
|
|
|
-// for _, d := range days.Day {
|
|
|
|
|
-
|
|
|
|
|
-// switch d.Type {
|
|
|
|
|
-// case "sun":
|
|
|
|
|
-// i18nDay[time.Sunday] = d.Data()
|
|
|
|
|
-// case "mon":
|
|
|
|
|
-// i18nDay[time.Monday] = d.Data()
|
|
|
|
|
-// case "tue":
|
|
|
|
|
-// i18nDay[time.Tuesday] = d.Data()
|
|
|
|
|
-// case "wed":
|
|
|
|
|
-// i18nDay[time.Wednesday] = d.Data()
|
|
|
|
|
-// case "thu":
|
|
|
|
|
-// i18nDay[time.Thursday] = d.Data()
|
|
|
|
|
-// case "fri":
|
|
|
|
|
-// i18nDay[time.Friday] = d.Data()
|
|
|
|
|
-// case "sat":
|
|
|
|
|
-// i18nDay[time.Saturday] = d.Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// switch days.Type {
|
|
|
|
|
-// case "abbreviated":
|
|
|
|
|
-// calendar.FormatNames.Days.Abbreviated = i18nDay
|
|
|
|
|
-// case "narrow":
|
|
|
|
|
-// calendar.FormatNames.Days.Narrow = i18nDay
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.FormatNames.Days.Short = i18nDay
|
|
|
|
|
-// case "wide":
|
|
|
|
|
-// calendar.FormatNames.Days.Wide = i18nDay
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.DayPeriods != nil {
|
|
|
|
|
-
|
|
|
|
|
-// for _, ctx := range ldmlCar.DayPeriods.DayPeriodContext {
|
|
|
|
|
-
|
|
|
|
|
-// for _, width := range ctx.DayPeriodWidth {
|
|
|
|
|
-
|
|
|
|
|
-// // var i18nPeriod i18n.CalendarPeriodFormatNameValue
|
|
|
|
|
-// i18nPeriod := make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
-
|
|
|
|
|
-// for _, d := range width.DayPeriod {
|
|
|
|
|
-
|
|
|
|
|
-// if _, ok := i18nPeriod[d.Type]; !ok {
|
|
|
|
|
-// i18nPeriod[d.Type] = d.Data()
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// switch width.Type {
|
|
|
|
|
-// case "abbreviated":
|
|
|
|
|
-// calendar.FormatNames.Periods.Abbreviated = i18nPeriod
|
|
|
|
|
-// case "narrow":
|
|
|
|
|
-// calendar.FormatNames.Periods.Narrow = i18nPeriod
|
|
|
|
|
-// case "short":
|
|
|
|
|
-// calendar.FormatNames.Periods.Short = i18nPeriod
|
|
|
|
|
-// case "wide":
|
|
|
|
|
-// calendar.FormatNames.Periods.Wide = i18nPeriod
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// // var empty i18n.CalendarPeriodFormatNameValue
|
|
|
|
|
-// // if calendar.FormatNames.Periods.Abbreviated == empty {
|
|
|
|
|
-// // calendar.FormatNames.Periods.Abbreviated = calendar.FormatNames.Periods.Wide
|
|
|
|
|
-// // }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras != nil {
|
|
|
|
|
-
|
|
|
|
|
-// var eras i18n.Eras
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraNames != nil && len(ldmlCar.Eras.EraNames.Era) > 0 {
|
|
|
|
|
-// eras.BC.Full = ldmlCar.Eras.EraNames.Era[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraAbbr != nil && len(ldmlCar.Eras.EraAbbr.Era) > 0 {
|
|
|
|
|
-// eras.BC.Abbrev = ldmlCar.Eras.EraAbbr.Era[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraNarrow != nil && len(ldmlCar.Eras.EraNarrow.Era) > 0 {
|
|
|
|
|
-// eras.BC.Narrow = ldmlCar.Eras.EraNarrow.Era[0].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraNames != nil && len(ldmlCar.Eras.EraNames.Era) > 2 {
|
|
|
|
|
-// eras.AD.Full = ldmlCar.Eras.EraNames.Era[2].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraAbbr != nil && len(ldmlCar.Eras.EraAbbr.Era) > 2 {
|
|
|
|
|
-// eras.AD.Abbrev = ldmlCar.Eras.EraAbbr.Era[2].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if ldmlCar.Eras.EraNarrow != nil && len(ldmlCar.Eras.EraNarrow.Era) > 2 {
|
|
|
|
|
-// eras.AD.Narrow = ldmlCar.Eras.EraNarrow.Era[2].Data()
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// calendar.FormatNames.Eras = eras
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// calendars[loc] = calendar
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for locale := range locs {
|
|
|
|
|
-
|
|
|
|
|
-// if !strings.Contains(locale, "_") {
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// calendar := calendars[locale]
|
|
|
|
|
-
|
|
|
|
|
-// bString := strings.SplitN(locale, "_", 2)
|
|
|
|
|
-// base := bString[0]
|
|
|
|
|
-
|
|
|
|
|
-// baseCal := calendars[base]
|
|
|
|
|
-
|
|
|
|
|
-// // copy base calendar objects
|
|
|
|
|
-
|
|
|
|
|
-// // Dates
|
|
|
|
|
-// if calendar.Formats.DateEra.AD.Full == "" {
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Full = baseCal.Formats.DateEra.BC.Full
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Full = baseCal.Formats.DateEra.AD.Full
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.Formats.DateEra.AD.Long == "" {
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Long = baseCal.Formats.DateEra.BC.Long
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Long = baseCal.Formats.DateEra.AD.Long
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.Formats.DateEra.AD.Medium == "" {
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Medium = baseCal.Formats.DateEra.BC.Medium
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Medium = baseCal.Formats.DateEra.AD.Medium
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ func init() {
|
|
|
|
|
+ ut.RegisterLocale(locale)
|
|
|
|
|
+ }
|
|
|
|
|
+ `, locale, locale)))
|
|
|
|
|
|
|
|
-// if calendar.Formats.DateEra.AD.Short == "" {
|
|
|
|
|
-// calendar.Formats.DateEra.BC.Short = baseCal.Formats.DateEra.BC.Short
|
|
|
|
|
-// calendar.Formats.DateEra.AD.Short = baseCal.Formats.DateEra.AD.Short
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // times
|
|
|
|
|
-// if calendar.Formats.Time.Full == "" {
|
|
|
|
|
-// calendar.Formats.Time.Full = baseCal.Formats.Time.Full
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.Formats.Time.Long == "" {
|
|
|
|
|
-// calendar.Formats.Time.Long = baseCal.Formats.Time.Long
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.Formats.Time.Medium == "" {
|
|
|
|
|
-// calendar.Formats.Time.Medium = baseCal.Formats.Time.Medium
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.Formats.Time.Short == "" {
|
|
|
|
|
-// calendar.Formats.Time.Short = baseCal.Formats.Time.Short
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // date & times
|
|
|
|
|
-// if calendar.Formats.DateTime.Full == "" {
|
|
|
|
|
-// calendar.Formats.DateTime.Full = baseCal.Formats.DateTime.Full
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// if calendar.Formats.DateTime.Long == "" {
|
|
|
|
|
-// calendar.Formats.DateTime.Long = baseCal.Formats.DateTime.Long
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ fmt.Fprintf(mainFile, "%s", mainCodes)
|
|
|
|
|
|
|
|
-// if calendar.Formats.DateTime.Medium == "" {
|
|
|
|
|
-// calendar.Formats.DateTime.Medium = baseCal.Formats.DateTime.Medium
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ numberFile, err := os.Create(path + "number.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer numberFile.Close()
|
|
|
|
|
+
|
|
|
|
|
+ numberCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
+ import "github.com/go-playground/universal-translator"
|
|
|
|
|
+ var (
|
|
|
|
|
+ symbols = %#v
|
|
|
|
|
+ formats = %#v
|
|
|
|
|
+ )
|
|
|
|
|
+ `, locale, number.Symbols, number.Formats)))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Fprintf(numberFile, "%s", numberCodes)
|
|
|
|
|
|
|
|
-// if calendar.Formats.DateTime.Short == "" {
|
|
|
|
|
-// calendar.Formats.DateTime.Short = baseCal.Formats.DateTime.Short
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ currencyFile, err := os.Create(path + "currency.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer currencyFile.Close()
|
|
|
|
|
+
|
|
|
|
|
+ currencyCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
+ import "github.com/go-playground/universal-translator"
|
|
|
|
|
+ var currencies = %# v
|
|
|
|
|
+ `, locale, number.Currencies)))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Fprintf(currencyFile, "%s", currencyCodes)
|
|
|
|
|
|
|
|
-// // months
|
|
|
|
|
|
|
+ calendarFile, err := os.Create(path + "calendar.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer calendarFile.Close()
|
|
|
|
|
+
|
|
|
|
|
+ calendarCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
+ import "github.com/go-playground/universal-translator"
|
|
|
|
|
+ var calendar = %#v
|
|
|
|
|
+ `, locale, calendar)))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Fprintf(calendarFile, "%s", calendarCodes)
|
|
|
|
|
|
|
|
-// if calendar.FormatNames.Months.Abbreviated == nil {
|
|
|
|
|
-// calendar.FormatNames.Months.Abbreviated = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ var ok bool
|
|
|
|
|
+ pluralCode := "1"
|
|
|
|
|
|
|
|
-// if calendar.FormatNames.Months.Narrow == nil {
|
|
|
|
|
-// calendar.FormatNames.Months.Narrow = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ pInfo, ok := plurals[localeLowercase]
|
|
|
|
|
+ if ok && pInfo.plural != "" {
|
|
|
|
|
+ pluralCode = pInfo.plural
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// if calendar.FormatNames.Months.Short == nil {
|
|
|
|
|
-// calendar.FormatNames.Months.Short = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ pluralFile, err := os.Create(path + "plural.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer pluralFile.Close()
|
|
|
|
|
|
|
|
-// if calendar.FormatNames.Months.Wide == nil {
|
|
|
|
|
-// calendar.FormatNames.Months.Wide = make(i18n.CalendarMonthFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ pluralCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Months.Abbreviated {
|
|
|
|
|
|
|
+ var pluralRule = %q
|
|
|
|
|
+ `, locale, pluralCode)))
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Fprintf(pluralFile, "%s", pluralCodes)
|
|
|
|
|
+ }(locale, number)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-// val, ok := calendar.FormatNames.Months.Abbreviated[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Months.Abbreviated[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ wg.Wait()
|
|
|
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Months.Abbreviated[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ localesFile, err := os.Create("../../resources/locales/all.go")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ defer localesFile.Close()
|
|
|
|
|
+
|
|
|
|
|
+ tmpl, err := template.New("").Parse(`package locales
|
|
|
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Months.Narrow {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Months.Narrow[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Months.Narrow[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Months.Narrow[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Months.Short {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Months.Short[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Months.Short[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Months.Short[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Months.Wide {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Months.Wide[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Months.Wide[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Months.Wide[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // days
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Days.Abbreviated == nil {
|
|
|
|
|
-// calendar.FormatNames.Days.Abbreviated = make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Days.Narrow == nil {
|
|
|
|
|
-// calendar.FormatNames.Days.Narrow = make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Days.Short == nil {
|
|
|
|
|
-// calendar.FormatNames.Days.Short = make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Days.Wide == nil {
|
|
|
|
|
-// calendar.FormatNames.Days.Wide = make(i18n.CalendarDayFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Days.Abbreviated {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Days.Abbreviated[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Days.Abbreviated[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Days.Abbreviated[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Days.Narrow {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Days.Narrow[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Days.Narrow[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Days.Narrow[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Days.Short {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Days.Short[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Days.Short[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Days.Short[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Days.Wide {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Days.Wide[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Days.Wide[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Days.Wide[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // periods
|
|
|
|
|
-// if calendar.FormatNames.Periods.Abbreviated == nil {
|
|
|
|
|
-// calendar.FormatNames.Periods.Abbreviated = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Periods.Narrow == nil {
|
|
|
|
|
-// calendar.FormatNames.Periods.Narrow = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Periods.Short == nil {
|
|
|
|
|
-// calendar.FormatNames.Periods.Short = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if calendar.FormatNames.Periods.Wide == nil {
|
|
|
|
|
-// calendar.FormatNames.Periods.Wide = make(i18n.CalendarPeriodFormatNameValue)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Periods.Abbreviated {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Periods.Abbreviated[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Periods.Abbreviated[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Periods.Abbreviated[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Periods.Narrow {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Periods.Narrow[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Periods.Narrow[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Periods.Narrow[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Periods.Short {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Periods.Short[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Periods.Short[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Periods.Short[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// for k, v := range baseCal.FormatNames.Periods.Wide {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := calendar.FormatNames.Periods.Wide[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// calendar.FormatNames.Periods.Wide[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val == "" {
|
|
|
|
|
-// calendar.FormatNames.Periods.Wide[k] = v
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ // Imports for all locales
|
|
|
|
|
+ import (
|
|
|
|
|
+ {{range $locale, $_ := .}}// Locale "{{$locale}}" import that automatically registers itslef with the universal-translator package
|
|
|
|
|
+ _ "github.com/go-playground/universal-translator/resources/locales/{{$locale}}"
|
|
|
|
|
+ {{end}})
|
|
|
|
|
+ `)
|
|
|
|
|
|
|
|
-// calendars[locale] = calendar
|
|
|
|
|
-
|
|
|
|
|
-// number := numbers[locale]
|
|
|
|
|
-// baseNum := numbers[base]
|
|
|
|
|
-
|
|
|
|
|
-// // symbols
|
|
|
|
|
-// if number.Symbols.Decimal == "" {
|
|
|
|
|
-// number.Symbols.Decimal = baseNum.Symbols.Decimal
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Symbols.Group == "" {
|
|
|
|
|
-// number.Symbols.Group = baseNum.Symbols.Group
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Symbols.Negative == "" {
|
|
|
|
|
-// number.Symbols.Negative = baseNum.Symbols.Negative
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Symbols.Percent == "" {
|
|
|
|
|
-// number.Symbols.Percent = baseNum.Symbols.Percent
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Symbols.PerMille == "" {
|
|
|
|
|
-// number.Symbols.PerMille = baseNum.Symbols.PerMille
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // formats
|
|
|
|
|
-// if number.Formats.Decimal == "" {
|
|
|
|
|
-// number.Formats.Decimal = baseNum.Formats.Decimal
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Formats.Currency == "" {
|
|
|
|
|
-// number.Formats.Currency = baseNum.Formats.Currency
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Formats.CurrencyAccounting == "" {
|
|
|
|
|
-// number.Formats.CurrencyAccounting = baseNum.Formats.CurrencyAccounting
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if number.Formats.Percent == "" {
|
|
|
|
|
-// number.Formats.Percent = baseNum.Formats.Percent
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // currency
|
|
|
|
|
-// for k, v := range baseNum.Currencies {
|
|
|
|
|
-
|
|
|
|
|
-// val, ok := number.Currencies[k]
|
|
|
|
|
-// if !ok {
|
|
|
|
|
-// // number.Currencies[k] = v
|
|
|
|
|
-// continue
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val.Currency == "" {
|
|
|
|
|
-// val.Currency = v.Currency
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val.DisplayName == "" {
|
|
|
|
|
-// val.DisplayName = v.DisplayName
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if val.Symbol == "" {
|
|
|
|
|
-// val.Symbol = v.Symbol
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// number.Currencies[k] = val
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// numbers[locale] = number
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// var wg sync.WaitGroup
|
|
|
|
|
-// wg.Add(len(numbers))
|
|
|
|
|
-// for locale, number := range numbers {
|
|
|
|
|
-// go func(locale string, number i18n.Number) {
|
|
|
|
|
-
|
|
|
|
|
-// localeLowercase := strings.ToLower(locale)
|
|
|
|
|
-
|
|
|
|
|
-// defer func() { wg.Done() }()
|
|
|
|
|
-// path := "../../resources/locales/" + locale
|
|
|
|
|
-
|
|
|
|
|
-// if _, err := os.Stat(path); err != nil {
|
|
|
|
|
-// if err = os.MkdirAll(path, 0777); err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// path += "/"
|
|
|
|
|
-
|
|
|
|
|
-// mainFile, err := os.Create(path + "main.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer mainFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// calendar := calendars[locale]
|
|
|
|
|
-
|
|
|
|
|
-// mainCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
-// import "github.com/go-playground/universal-translator"
|
|
|
|
|
-
|
|
|
|
|
-// var locale = &ut.Locale{
|
|
|
|
|
-// Locale: %q,
|
|
|
|
|
-// Number: ut.Number{
|
|
|
|
|
-// Symbols: symbols,
|
|
|
|
|
-// Formats: formats,
|
|
|
|
|
-// Currencies: currencies,
|
|
|
|
|
-// },
|
|
|
|
|
-// Calendar: calendar,
|
|
|
|
|
-// PluralRule: pluralRule,
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// func init() {
|
|
|
|
|
-// ut.RegisterLocale(locale)
|
|
|
|
|
-// }
|
|
|
|
|
-// `, locale, locale)))
|
|
|
|
|
-
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// fmt.Fprintf(mainFile, "%s", mainCodes)
|
|
|
|
|
-
|
|
|
|
|
-// numberFile, err := os.Create(path + "number.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer numberFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// numberCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
-// import "github.com/go-playground/universal-translator"
|
|
|
|
|
-// var (
|
|
|
|
|
-// symbols = %#v
|
|
|
|
|
-// formats = %#v
|
|
|
|
|
-// )
|
|
|
|
|
-// `, locale, number.Symbols, number.Formats)))
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// fmt.Fprintf(numberFile, "%s", numberCodes)
|
|
|
|
|
-
|
|
|
|
|
-// currencyFile, err := os.Create(path + "currency.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer currencyFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// currencyCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
-// import "github.com/go-playground/universal-translator"
|
|
|
|
|
-// var currencies = %# v
|
|
|
|
|
-// `, locale, number.Currencies)))
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// fmt.Fprintf(currencyFile, "%s", currencyCodes)
|
|
|
|
|
-
|
|
|
|
|
-// calendarFile, err := os.Create(path + "calendar.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer calendarFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// calendarCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
-// import "github.com/go-playground/universal-translator"
|
|
|
|
|
-// var calendar = %#v
|
|
|
|
|
-// `, locale, calendar)))
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// fmt.Fprintf(calendarFile, "%s", calendarCodes)
|
|
|
|
|
-
|
|
|
|
|
-// var ok bool
|
|
|
|
|
-// pluralCode := "1"
|
|
|
|
|
-
|
|
|
|
|
-// pInfo, ok := plurals[localeLowercase]
|
|
|
|
|
-// if ok && pInfo.plural != "" {
|
|
|
|
|
-// pluralCode = pInfo.plural
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// pluralFile, err := os.Create(path + "plural.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer pluralFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// pluralCodes, err := format.Source([]byte(fmt.Sprintf(`package %s
|
|
|
|
|
-
|
|
|
|
|
-// var pluralRule = %q
|
|
|
|
|
-// `, locale, pluralCode)))
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// fmt.Fprintf(pluralFile, "%s", pluralCodes)
|
|
|
|
|
-// }(locale, number)
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// wg.Wait()
|
|
|
|
|
-
|
|
|
|
|
-// localesFile, err := os.Create("../../resources/locales/all.go")
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// defer localesFile.Close()
|
|
|
|
|
-
|
|
|
|
|
-// tmpl, err := template.New("").Parse(`package locales
|
|
|
|
|
-
|
|
|
|
|
-// // Imports for all locales
|
|
|
|
|
-// import (
|
|
|
|
|
-// {{range $locale, $_ := .}}// Locale "{{$locale}}" import that automatically registers itslef with the universal-translator package
|
|
|
|
|
-// _ "github.com/go-playground/universal-translator/resources/locales/{{$locale}}"
|
|
|
|
|
-// {{end}})
|
|
|
|
|
-// `)
|
|
|
|
|
-
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// var buf bytes.Buffer
|
|
|
|
|
-// if err := tmpl.Execute(&buf, locs); err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// allCodes, err := format.Source(buf.Bytes())
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// _, err = localesFile.Write(allCodes)
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// panic(err)
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ var buf bytes.Buffer
|
|
|
|
|
+ if err := tmpl.Execute(&buf, locs); err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ allCodes, err := format.Source(buf.Bytes())
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+ _, err = localesFile.Write(allCodes)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ panic(err)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|