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.
- 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.
- Go 1.16 or higher
-
Clone the Repository:
git clone https://github.com/codermuss/musale.git cd musale go build -o musale go install
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.
{
"Hello": "Hello, World!",
"Errors": {
"MigrationInstance": "Cannot create new migrate instance"
}
}
musale --json=en.json --output=localizations.go --package=localizationkeys
package localizationkeys
// DO NOT EDIT: This file is automatically generated by the musale CLI tool.
const (
Hello = "Hello"
Errors_MigrationInstance = "Errors.MigrationInstance"
)
{
"Menu": {
"File": {
"Open": "Open File",
"Close": "Close File"
},
"Edit": {
"Undo": "Undo Action"
}
}
}
musale --json=en.json --output=localizations.go --package=localizationkeys
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"
)