Skip to content

CLI for generating json localization keys to Go code

License

Notifications You must be signed in to change notification settings

codermuss/musale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

musale

musale

musale is a CLI tool for generating localization keys as Go constants from a JSON file. This tool helps streamline the process of using localization keys in Go projects, ensuring consistency and ease of use.

Features

  • Reads a JSON file containing localization keys and values.
  • Generates a Go file with constants representing the localization keys.
  • Handles nested JSON structures and converts them into flat constants.
  • Allows customization of the output file and package name.

Installation

Prerequisites

  • Go 1.16 or higher

Steps

  1. Clone the Repository:

    git clone https://github.com/codermuss/musale.git
    cd musale
    go build -o musale
    go install

Usage

musale --json=<input-json-file> --output=<output-go-file>
•	--json or -j: Path to the JSON file containing localization keys (default: en.json).
•	--output or -o: Path to the output Go file (default: localizations.g.go).
•	--package or -p: (Optional) The package name to use in the generated Go file.

Example

{
  "Hello": "Hello, World!",
  "Errors": {
    "MigrationInstance": "Cannot create new migrate instance"
  }
}
   musale --json=en.json --output=localizations.go --package=localizationkeys

Output

package localizationkeys

// DO NOT EDIT: This file is automatically generated by the musale CLI tool.

const (
	Hello                    = "Hello"
	Errors_MigrationInstance = "Errors.MigrationInstance"
)

Handling Nested JSON

{
  "Menu": {
    "File": {
      "Open": "Open File",
      "Close": "Close File"
    },
    "Edit": {
      "Undo": "Undo Action"
    }
  }
}
   musale --json=en.json --output=localizations.go --package=localizationkeys

Output

package localizationkeys

// DO NOT EDIT: This file is automatically generated by the musale CLI tool.

const (
	Menu_File_Open  = "Menu.File.Open"
	Menu_File_Close = "Menu.File.Close"
	Menu_Edit_Undo  = "Menu.Edit.Undo"
)

About

CLI for generating json localization keys to Go code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages