Пример #1
0
func selectFormat(data *WizardData) {
	auth := phraseapp.AuthCredentials{Token: data.AccessToken}
	phraseapp.RegisterAuthCredentials(&auth, nil)
	formats, err := phraseapp.FormatsList(1, 25)
	if err != nil {
		panic(err.Error())
	}

	for counter, format := range formats {
		fmt.Printf("%2d. %s - %s, File-Extension: %s\n", counter+1, format.ApiName, format.Name, format.Extension)
	}

	var id string
	mainFormatDefault := ""
	if data.MainFormat != "" {
		mainFormatDefault = fmt.Sprintf(" [Press enter for default: %s]", data.MainFormat)
	}
	fmt.Printf("Select the format you want to use for language files you download from PhraseApp%s: ", mainFormatDefault)
	fmt.Scanln(&id)
	if id == "" && data.MainFormat != "" {
		data.Format = data.MainFormat
		DisplayWizard(data, next(data), "")
		return
	}
	number, err := strconv.Atoi(id)
	if err != nil || number < 1 || number > len(formats)+1 {
		DisplayWizard(data, "selectFormat", fmt.Sprintf("Argument Error: Please select a format from the list by specifying its position in the list."))
		return
	}
	data.Format = formats[number-1].ApiName
	DisplayWizard(data, next(data), "")
}
Пример #2
0
func defaultFilePath(fileFormat string) (string, error) {
	formats, err := phraseapp.FormatsList(1, 30)
	if err != nil {
		return "", err
	}
	for _, format := range formats {
		if format.ApiName == fileFormat {
			return format.DefaultFile, nil
		}
	}
	return "", nil
}