Skip to content

Commit

Permalink
Merge pull request #853 from SoftLayer/i18nUpdates-2
Browse files Browse the repository at this point in the history
Upgrading from github.com/nicksnyder/go-i18n/v1 to github.com/nicksnyder/go-i18n/v2
  • Loading branch information
allmightyspiff authored and GitHub Enterprise committed Jun 6, 2024
2 parents a87d160 + 7ff73f1 commit 38fee5a
Show file tree
Hide file tree
Showing 61 changed files with 77,866 additions and 1,377 deletions.
162 changes: 2 additions & 160 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"exclude": {
"files": "(.*test.*)|(vendor)|(go.sum)|^.secrets.baseline$",
"files": "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/|^.secrets.baseline$",
"lines": null
},
"generated_at": "2024-04-18T01:39:58Z",
"generated_at": "2024-05-23T21:29:26Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -65,16 +65,6 @@
}
],
"results": {
"bin/buildAndDeploy.py": [
{
"hashed_secret": "82e725817f214b04e55d8136779d09dde4195560",
"is_secret": false,
"is_verified": false,
"line_number": 327,
"type": "Hex High Entropy String",
"verified_result": null
}
],
"cliChecker/cliOutput.txt": [
{
"hashed_secret": "59b189070af751d4e93a749ccffb4ccfd2de7ab5",
Expand Down Expand Up @@ -307,154 +297,6 @@
"verified_result": null
}
],
"plugin/i18n/resources/de_DE.all.json": [
{
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
"is_secret": false,
"is_verified": false,
"line_number": 148,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "7d44c33cf9a82ab9bd5300d266784504e9772177",
"is_secret": false,
"is_verified": false,
"line_number": 5116,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/en_US.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5120,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/es_ES.all.json": [
{
"hashed_secret": "3efd4c0fe185135dd2c584b9698f506803cfaf81",
"is_secret": false,
"is_verified": false,
"line_number": 148,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "8927bd748f26a7258a01e318a7e1e7585458a228",
"is_secret": false,
"is_verified": false,
"line_number": 5116,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/fr_FR.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/it_IT.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/ja_JP.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
"is_secret": false,
"is_verified": false,
"line_number": 5116,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/ko_KR.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
},
{
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
"is_secret": false,
"is_verified": false,
"line_number": 5116,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/pt_BR.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/zh_Hans.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/i18n/resources/zh_Hant.all.json": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
"is_secret": false,
"is_verified": false,
"line_number": 5115,
"type": "Secret Keyword",
"verified_result": null
}
],
"plugin/managers/ipsec.go": [
{
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ install:
- sudo pip3 install --upgrade "git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets"
- curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin
before_script:
- bash bin/catch-i18n-mismatch.sh
- bash bin/generate-i18n-resources.sh
- go vet $(go list ./... | grep -v "fixtures" | grep -v "vendor")
- go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")
- detect-secrets scan --update .secrets.baseline
Expand Down
62 changes: 52 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,47 @@ cobraCmd.AddCommand(NewActionNameCommand(sl).Command)

## i18n stuff

anything with `T("some string here")` uses the internationalization system. Definitions are located in `plugin\i18n\en_US.all.json` for english.
The string passed into the `T()` function serves as the ID when looking these up. So the ID Will need to be present in all i18n files, it will also need a translation string.
anything with `T("some string here")` uses the internationalization system. Specifically we use the [goi18n/v2](https://github.com/nicksnyder/go-i18n) library for most work here.

[i18n4go](https://github.com/maximilien/i18n4go) is used to make sure all strings being transalted have translations. To test run this command.
Currently we use a custom version of [goi18n](https://github.com/allmightyspiff/go-i18n/tree/Tfunctions) which can parse `T()` functions like we use (an artiface of migrating from v1 to v2). The custom binary (`bin/goi18n2*`) has some code that forces the .json file it generates to be like the following, because otherwise the translations don't get loaded properly.

For i18n4go, we specifically use v0.2.4 for now, so we have a prebuilt binary in `./bin/i18n4go`. If that binary needs to be rebuilt, use the SoftLayer fork at https://github.com/softlayer/i18n4go (which is set to the version we need, along with some updates since that version had a bug with --help).
```json
{
"words you want translated" : {
"other": "words you want translated"
}
}
```

The changes are this for future reference:

This command will build the Mac (arm64) version. Replace GOOS and GOARCH with the OS/Architecture you need to build for.
```
~/go/src/github.ibm.com/softlayer/softlayer-cli/i18n4go (master)
$> GOOS=darwin GOARCH=arm64 go build -o i18n4go_mac -ldflags "-s -w" i18n4go/i18n4go.go
$> GOOS=linux GOARCH=amd64 go build -o out/i18n4go ./i18n4go/i18n4go.go
~/go/src/github.com/allmightyspiff/go-i18n (Tfunctions)
$> git diff goi18n/marshal.go
diff --git a/goi18n/marshal.go b/goi18n/marshal.go
index a6cc762..a256f2b 100644
--- a/goi18n/marshal.go
+++ b/goi18n/marshal.go
@@ -28,7 +28,9 @@ func marshalValue(messageTemplates map[string]*i18n.MessageTemplate, sourceLangu
for id, template := range messageTemplates {
if other := template.PluralTemplates[plural.Other]; sourceLanguage && len(template.PluralTemplates) == 1 &&
other != nil && template.Description == "" && template.LeftDelim == "" && template.RightDelim == "" {
- v[id] = other.Src
+ m := map[string]string{}
+ m["other"] = other.Src
+ v[id] = m
} else {
m := map[string]string{}
if template.Description != "" {
```

To generate the en-US.json file, just run

```bash
python bin/buildAndDeploy.py i18n
```
[go-bindata](https://github.com/jteeuwen/go-bindata) takes the json files, and turns them into a go binary.

The `plugin/i18n/v2Resources/active.*.json` files are all compiled into the binary automatically.

### Basic Patterns and Tips

Expand All @@ -369,6 +395,8 @@ subs := map[string]interface{}{"CMDTYPE": "block"}
T("This is some output for a {{.CMDTYPE}} command", subs)
```

*NOTICE* goi18n/v2 has some newer features that can make this a bit easier to deal with, but I'm not sure they are currently supported, so procede with caution in you make use of them.

### Useful Scripts

#### `./bin/buildAndDeploy.py i18n`
Expand Down Expand Up @@ -499,4 +527,18 @@ drwxr-xr-x 4 chris staff 128B Nov 30 13:01 output


## TODO
Automate build with https://github.ibm.com/coligo/cli/tree/main/script
Automate build with https://github.ibm.com/coligo/cli/tree/main/script


## Detect Secrets
Make sure to add the pre-commit hook by running `pre-commit install`

To run a scan do:
```bash
detect-secrets scan --update .secrets.baseline
```

If we need to update the excluded files (these are saved in the .secrets.baseline file) do this:
```bash
detect-secrets -v scan --update .secrets.baseline --exclude-files "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/"
```
50 changes: 0 additions & 50 deletions bin/build-all

This file was deleted.

Loading

0 comments on commit 38fee5a

Please sign in to comment.