Skip to content

Commit

Permalink
a new option has been added to the file configuration (filename-templ…
Browse files Browse the repository at this point in the history
…ate)
  • Loading branch information
AleksNV committed Jun 12, 2021
1 parent 4bb5dc0 commit 015ee76
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
localeum.yml
localeum-cli
/locales

.DS_Store
.idea
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,34 @@ To download the latest translations, run the following command.
$ localeum-cli pull
```

### Configuration file options
Localeum CLI configuration files use the YAML.
The **localeum.yml** file must be in the root of the project.

Example:
```yaml
api-key: "{your API key}"
directory: "locales"
format: "json"
```

| Option | Default | Required |
|---|---|---|
| api-key | null | Yes |
| directory | null | Yes |
| format | null | Yes |
| filename-template | %lang% | No |

#### Format

Possible variants: json, json_nested, arb, csv.

#### Filename template

This template to create your own filename.
Possible replaces:

###### %lang%
Language

Example: intl_%lang% => intl_en.{ext}
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var initCmd = &cobra.Command{
return err
}

fmt.Print("Enter the file format for export (json, json_nested, csv, yaml): ")
fmt.Print("Enter the file format for export (json, json_nested, csv, arb): ")
if _, err := fmt.Fscan(os.Stdin, &Format); err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"strings"
"sync"
)

Expand Down Expand Up @@ -75,7 +76,13 @@ func fetchFile(lang string, wg *sync.WaitGroup) {
return
}

filename := viper.GetString(DirectoryFlag) + "/" + lang + formatToExtensionMapper(format)
fileStem := lang
filenameTemplate:= viper.GetString(FilenameTemplate)
if filenameTemplate != "" {
fileStem = strings.ReplaceAll(filenameTemplate, "%lang%", lang)
}

filename := viper.GetString(DirectoryFlag) + "/" + fileStem + formatToExtensionMapper(format)
file, err := os.Create(filename)
if err != nil {
fmt.Println(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ var (
ApiKey string
)

const Version = "1.0.5"
const Version = "1.0.7"
const ConfigFileName = "localeum.yml"

const ApiKeyFlag = "api-key"
const DirectoryFlag = "directory"
const FormatFlag = "format"
const FilenameTemplate = "filename-template"

var rootCmd = &cobra.Command{
Use: "localeum-cli",
Expand Down
Binary file removed localeum-cli
Binary file not shown.
5 changes: 3 additions & 2 deletions localeum.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
api-key: "bc5de44b32e69d177e7ae0dc867eda06"
api-key: "a01fe273ace36608f6c33786cc414ab7"
directory: "locales"
format: "csv"
format: "yaml"
filename-template: "intl_%lang%"

0 comments on commit 015ee76

Please sign in to comment.