Skip to content

Commit 38fee5a

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #853 from SoftLayer/i18nUpdates-2
Upgrading from github.com/nicksnyder/go-i18n/v1 to github.com/nicksnyder/go-i18n/v2
2 parents a87d160 + 7ff73f1 commit 38fee5a

61 files changed

Lines changed: 77866 additions & 1377 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.secrets.baseline

Lines changed: 2 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"exclude": {
3-
"files": "(.*test.*)|(vendor)|(go.sum)|^.secrets.baseline$",
3+
"files": "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-04-18T01:39:58Z",
6+
"generated_at": "2024-05-23T21:29:26Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -65,16 +65,6 @@
6565
}
6666
],
6767
"results": {
68-
"bin/buildAndDeploy.py": [
69-
{
70-
"hashed_secret": "82e725817f214b04e55d8136779d09dde4195560",
71-
"is_secret": false,
72-
"is_verified": false,
73-
"line_number": 327,
74-
"type": "Hex High Entropy String",
75-
"verified_result": null
76-
}
77-
],
7868
"cliChecker/cliOutput.txt": [
7969
{
8070
"hashed_secret": "59b189070af751d4e93a749ccffb4ccfd2de7ab5",
@@ -307,154 +297,6 @@
307297
"verified_result": null
308298
}
309299
],
310-
"plugin/i18n/resources/de_DE.all.json": [
311-
{
312-
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
313-
"is_secret": false,
314-
"is_verified": false,
315-
"line_number": 148,
316-
"type": "Secret Keyword",
317-
"verified_result": null
318-
},
319-
{
320-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
321-
"is_secret": false,
322-
"is_verified": false,
323-
"line_number": 5115,
324-
"type": "Secret Keyword",
325-
"verified_result": null
326-
},
327-
{
328-
"hashed_secret": "7d44c33cf9a82ab9bd5300d266784504e9772177",
329-
"is_secret": false,
330-
"is_verified": false,
331-
"line_number": 5116,
332-
"type": "Secret Keyword",
333-
"verified_result": null
334-
}
335-
],
336-
"plugin/i18n/resources/en_US.all.json": [
337-
{
338-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
339-
"is_secret": false,
340-
"is_verified": false,
341-
"line_number": 5120,
342-
"type": "Secret Keyword",
343-
"verified_result": null
344-
}
345-
],
346-
"plugin/i18n/resources/es_ES.all.json": [
347-
{
348-
"hashed_secret": "3efd4c0fe185135dd2c584b9698f506803cfaf81",
349-
"is_secret": false,
350-
"is_verified": false,
351-
"line_number": 148,
352-
"type": "Secret Keyword",
353-
"verified_result": null
354-
},
355-
{
356-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
357-
"is_secret": false,
358-
"is_verified": false,
359-
"line_number": 5115,
360-
"type": "Secret Keyword",
361-
"verified_result": null
362-
},
363-
{
364-
"hashed_secret": "8927bd748f26a7258a01e318a7e1e7585458a228",
365-
"is_secret": false,
366-
"is_verified": false,
367-
"line_number": 5116,
368-
"type": "Secret Keyword",
369-
"verified_result": null
370-
}
371-
],
372-
"plugin/i18n/resources/fr_FR.all.json": [
373-
{
374-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
375-
"is_secret": false,
376-
"is_verified": false,
377-
"line_number": 5115,
378-
"type": "Secret Keyword",
379-
"verified_result": null
380-
}
381-
],
382-
"plugin/i18n/resources/it_IT.all.json": [
383-
{
384-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
385-
"is_secret": false,
386-
"is_verified": false,
387-
"line_number": 5115,
388-
"type": "Secret Keyword",
389-
"verified_result": null
390-
}
391-
],
392-
"plugin/i18n/resources/ja_JP.all.json": [
393-
{
394-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
395-
"is_secret": false,
396-
"is_verified": false,
397-
"line_number": 5115,
398-
"type": "Secret Keyword",
399-
"verified_result": null
400-
},
401-
{
402-
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
403-
"is_secret": false,
404-
"is_verified": false,
405-
"line_number": 5116,
406-
"type": "Secret Keyword",
407-
"verified_result": null
408-
}
409-
],
410-
"plugin/i18n/resources/ko_KR.all.json": [
411-
{
412-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
413-
"is_secret": false,
414-
"is_verified": false,
415-
"line_number": 5115,
416-
"type": "Secret Keyword",
417-
"verified_result": null
418-
},
419-
{
420-
"hashed_secret": "d3ac7a4ef1a838b4134f2f6e7f3c0d249d74b674",
421-
"is_secret": false,
422-
"is_verified": false,
423-
"line_number": 5116,
424-
"type": "Secret Keyword",
425-
"verified_result": null
426-
}
427-
],
428-
"plugin/i18n/resources/pt_BR.all.json": [
429-
{
430-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
431-
"is_secret": false,
432-
"is_verified": false,
433-
"line_number": 5115,
434-
"type": "Secret Keyword",
435-
"verified_result": null
436-
}
437-
],
438-
"plugin/i18n/resources/zh_Hans.all.json": [
439-
{
440-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
441-
"is_secret": false,
442-
"is_verified": false,
443-
"line_number": 5115,
444-
"type": "Secret Keyword",
445-
"verified_result": null
446-
}
447-
],
448-
"plugin/i18n/resources/zh_Hant.all.json": [
449-
{
450-
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",
451-
"is_secret": false,
452-
"is_verified": false,
453-
"line_number": 5115,
454-
"type": "Secret Keyword",
455-
"verified_result": null
456-
}
457-
],
458300
"plugin/managers/ipsec.go": [
459301
{
460302
"hashed_secret": "bbccdf2efb33b52e6c9d0a14dd70b2d415fbea6e",

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ install:
1616
- sudo pip3 install --upgrade "git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets"
1717
- curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin
1818
before_script:
19-
- bash bin/catch-i18n-mismatch.sh
20-
- bash bin/generate-i18n-resources.sh
2119
- go vet $(go list ./... | grep -v "fixtures" | grep -v "vendor")
2220
- go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")
2321
- detect-secrets scan --update .secrets.baseline

README.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,47 @@ cobraCmd.AddCommand(NewActionNameCommand(sl).Command)
337337

338338
## i18n stuff
339339

340-
anything with `T("some string here")` uses the internationalization system. Definitions are located in `plugin\i18n\en_US.all.json` for english.
341-
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.
340+
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.
342341

343-
[i18n4go](https://github.com/maximilien/i18n4go) is used to make sure all strings being transalted have translations. To test run this command.
342+
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.
344343

345-
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).
344+
```json
345+
{
346+
"words you want translated" : {
347+
"other": "words you want translated"
348+
}
349+
}
350+
```
351+
352+
The changes are this for future reference:
346353

347-
This command will build the Mac (arm64) version. Replace GOOS and GOARCH with the OS/Architecture you need to build for.
348354
```
349-
~/go/src/github.ibm.com/softlayer/softlayer-cli/i18n4go (master)
350-
$> GOOS=darwin GOARCH=arm64 go build -o i18n4go_mac -ldflags "-s -w" i18n4go/i18n4go.go
351-
$> GOOS=linux GOARCH=amd64 go build -o out/i18n4go ./i18n4go/i18n4go.go
355+
~/go/src/github.com/allmightyspiff/go-i18n (Tfunctions)
356+
$> git diff goi18n/marshal.go
357+
diff --git a/goi18n/marshal.go b/goi18n/marshal.go
358+
index a6cc762..a256f2b 100644
359+
--- a/goi18n/marshal.go
360+
+++ b/goi18n/marshal.go
361+
@@ -28,7 +28,9 @@ func marshalValue(messageTemplates map[string]*i18n.MessageTemplate, sourceLangu
362+
for id, template := range messageTemplates {
363+
if other := template.PluralTemplates[plural.Other]; sourceLanguage && len(template.PluralTemplates) == 1 &&
364+
other != nil && template.Description == "" && template.LeftDelim == "" && template.RightDelim == "" {
365+
- v[id] = other.Src
366+
+ m := map[string]string{}
367+
+ m["other"] = other.Src
368+
+ v[id] = m
369+
} else {
370+
m := map[string]string{}
371+
if template.Description != "" {
372+
```
373+
374+
To generate the en-US.json file, just run
375+
376+
```bash
377+
python bin/buildAndDeploy.py i18n
352378
```
353-
[go-bindata](https://github.com/jteeuwen/go-bindata) takes the json files, and turns them into a go binary.
354379

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

356382
### Basic Patterns and Tips
357383

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

398+
*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.
399+
372400
### Useful Scripts
373401

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

500528

501529
## TODO
502-
Automate build with https://github.ibm.com/coligo/cli/tree/main/script
530+
Automate build with https://github.ibm.com/coligo/cli/tree/main/script
531+
532+
533+
## Detect Secrets
534+
Make sure to add the pre-commit hook by running `pre-commit install`
535+
536+
To run a scan do:
537+
```bash
538+
detect-secrets scan --update .secrets.baseline
539+
```
540+
541+
If we need to update the excluded files (these are saved in the .secrets.baseline file) do this:
542+
```bash
543+
detect-secrets -v scan --update .secrets.baseline --exclude-files "plugin/i18n/v1Resources/|plugin/i18n/v2Resources/|(.*test.*)|(vendor)|(go.sum)|bin/"
544+
```

bin/build-all

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)