Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulgrammer/i18n-gt
i18n JSON translator with google translator API
https://github.com/paulgrammer/i18n-gt
i18n i18n-js i18n-react i18n-tool i18next i18next-backend json json-schema nlp nmt translation
Last synced: 7 days ago
JSON representation
i18n JSON translator with google translator API
- Host: GitHub
- URL: https://github.com/paulgrammer/i18n-gt
- Owner: paulgrammer
- Created: 2023-05-08T09:32:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-08T19:38:02.000Z (over 1 year ago)
- Last Synced: 2024-06-21T06:30:21.225Z (7 months ago)
- Topics: i18n, i18n-js, i18n-react, i18n-tool, i18next, i18next-backend, json, json-schema, nlp, nmt, translation
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Command-Line Program for Translating i18n json using Google Cloud Translation API
This is a simple command-line program written in Go that uses the Google Cloud Translation API to translate i18n json with text from one language to another. The program takes in a JSON file containing text to be translated, source language, target language and output JSON file path as required command-line arguments.
### Usage
To use the program, you'll need to have a Google Cloud service account and API key. You can create one by following the instructions in the [Google Cloud documentation](https://cloud.google.com/translate/docs/setup).
Once you have your credentials, you can run the program using the following command:
```
export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"
``````
i18n-gt -input -source -target -output
```where `` is the path to the input JSON file, `` is the code for the source language (e.g. "en" for English), `` is the code for the target language, `` is the path to the output JSON file
### Input JSON FormatThe input JSON file should contain an object, with property and value
Here's an example input JSON file:
```JSON
{
"title": "Welcome!",
"pages": {
"title": "Pages",
"profile": {
"title": "Profile page",
"login": {
"pasword": "password"
}
}
}
}
```### Output JSON Format
The output JSON file will contain translated object
Here's an example output JSON file:
```JSON
{
"pages": {
"profile": {
"login": {
"pasword": "hasło"
},
"title": "Strona profilowa"
},
"title": "Strony"
},
"title": "Powitanie!"
}
```### Dependencies
The program uses the following Go packages:
- `cloud.google.com/go/translate`: The Google Cloud Translation API Go client library
- `golang.org/x/text/language`: The Go standard library package for language code parsing
- `google.golang.org/api/option`: The Google Cloud API option libraryYou can install these packages using the `go get` command:
```
go get cloud.google.com/go/translate
go get golang.org/x/text/language
go get google.golang.org/api/option
```To build the program for multiple platforms, run the following command:
```sh
make build
```This will compile the program and generate a binary file in the `build/` directory.
To run the program in development mode, run the following command:
```sh
make dev
```This will run the program with the `input.json` and `account.json` files provided and generate the `output.json` file.
## Build Targets
The `Makefile` provides the following build targets:
- `build-linux-amd64`: Build the program for Linux x64
- `build-linux-arm`: Build the program for Linux ARM
- `build-darwin-amd64`: Build the program for macOS x64
- `build-windows-amd64`: Build the program for Windows x64
- `build`: Build the program for all platforms
- `clean`: Clean up generated binary filesHere's an example of how to build the program for a specific platform:
```sh
make build-linux-amd64
```This will compile the program for Linux x64 and generate a binary file in the `build/` directory.
## TODO
- [ ] Set up GitHub release workflow to automate binary file creation and release management.
### License
This program is licensed under the MIT license. See the [LICENSE](https://opensource.org/licenses/MIT) file for details.