Skip to content

Commit 17eba3f

Browse files
Merge branch 'i18nUpdates-2' of github.ibm.com:SoftLayer/softlayer-cli into i18nUpdates-2
2 parents c37574c + 53e902a commit 17eba3f

31 files changed

Lines changed: 77666 additions & 24 deletions

bin/i18nUpdater.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!python
2+
3+
import os
4+
import click
5+
import json
6+
7+
8+
i18n_files = [
9+
'en_US',
10+
'de_DE',
11+
'es_ES',
12+
'fr_FR',
13+
'it_IT',
14+
'ja_JP',
15+
'ko_KR',
16+
'pt_BR',
17+
'zh_Hans',
18+
'zh_Hant',
19+
]
20+
21+
22+
23+
24+
def reformat(filename: str):
25+
plugin_dir = os.path.join(os.getcwd(), 'plugin')
26+
i18n_path = os.path.join(plugin_dir, 'i18n', 'v1Resources', f"{filename}.json")
27+
new_i18n = os.path.join(plugin_dir, 'i18n', 'v2Resources', f"active.{filename}.json")
28+
original = get_source_data(i18n_path)
29+
reformatted = {}
30+
for key in original:
31+
translation = original[key].get('translation', '')
32+
if translation == '':
33+
translation = key
34+
reformatted[key] = {"other": translation}
35+
with open(new_i18n, 'w', encoding="utf8", newline='\n') as f:
36+
json.dump(reformatted, f, sort_keys=True, separators=(',', ': ',), ensure_ascii=False, indent=2)
37+
f.close()
38+
39+
def get_source_data(file_name: str) -> dict:
40+
"""Reads from the i18n files and returns a formatted dict"""
41+
source_i18n = {}
42+
with open(file_name, encoding="utf8") as f:
43+
data = json.load(f)
44+
for i in data:
45+
source_i18n[i.get('id')] = i
46+
f.close()
47+
return source_i18n
48+
49+
@click.command()
50+
def cli():
51+
cwd = os.getcwd()
52+
if not cwd.endswith('softlayer-cli'):
53+
raise Exception(f"Working Directory should be softlayer-cli, is currently {self.cwd}")
54+
for file in i18n_files:
55+
click.echo(f"Working on {file}")
56+
reformat(file)
57+
58+
59+
if __name__ == '__main__':
60+
cli()

plugin/commands/account/hook_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func NewHookCreateCommand(sl *metadata.SoftlayerCommand) *HookCreateCommand {
3535
},
3636
}
3737

38-
cobraCmd.Flags().StringVarP(&thisCmd.Name, "name", "N", "", T("The name of the hook."+" "+T("[required]")))
39-
cobraCmd.Flags().StringVarP(&thisCmd.Uri, "uri", "U", "", T("The endpoint that the script will be downloaded."+" "+T("[required]")))
38+
cobraCmd.Flags().StringVarP(&thisCmd.Name, "name", "N", "", T("The name of the hook.") + " " +T("[required]"))
39+
cobraCmd.Flags().StringVarP(&thisCmd.Uri, "uri", "U", "", T("The endpoint that the script will be downloaded.") + " " +T("[required]"))
4040

4141
//#nosec G104 -- This is a false positive
4242
cobraCmd.MarkFlagRequired("name")

plugin/commands/cdn/edit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (cmd *EditCommand) Run(args []string) error {
7575
if cmd.Cache != "" {
7676
allowCache := []string{"include-all", "ignore-all", "include-specified", "ignore-specified"}
7777
if !utils.WordInList(allowCache, cmd.Cache) {
78-
return slErr.NewInvalidUsageError(T("Option cache just accept: " + utils.ArrayStringToString(allowCache)))
78+
return slErr.NewInvalidUsageError(T("Option cache just accept: ") + utils.ArrayStringToString(allowCache))
7979
}
8080
if cmd.Cache == "include-specified" || cmd.Cache == "ignore-specified" {
8181
if cmd.CacheDescription == "" {
@@ -93,7 +93,7 @@ func (cmd *EditCommand) Run(args []string) error {
9393
if cmd.PerformanceConfiguration != "" {
9494
allowPerformanceConfiguration := []string{"General web delivery", "Large file optimization", "Video on demand optimization"}
9595
if !utils.WordInList(allowPerformanceConfiguration, cmd.PerformanceConfiguration) {
96-
return slErr.NewInvalidUsageError(T("Option performance-configuration just accept: " + utils.ArrayStringToString(allowPerformanceConfiguration)))
96+
return slErr.NewInvalidUsageError(T("Option performance-configuration just accept: ") + utils.ArrayStringToString(allowPerformanceConfiguration))
9797
}
9898
}
9999

plugin/commands/hardware/notifications_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (cmd *NotificationsAddCommand) Run(args []string) error {
5656
UserCustomerNotification, err := cmd.HardwareManager.CreateUserCustomerNotification(hardwareId, userId)
5757
if err != nil {
5858
userIdMap := map[string]interface{}{"userID": userId}
59-
cmd.UI.Failed(T("Failed to create User Customer Notification with user ID: {{.userID}}."+"\n"+err.Error(), userIdMap))
59+
cmd.UI.Failed(T("Failed to create User Customer Notification with user ID: {{.userID}}."), userIdMap)
6060
} else {
6161
printTable = true
6262
table.Add(

plugin/commands/meta/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewMetaCommand(sl *metadata.SoftlayerCommand) *MetaCommand {
3030
cobraCmd := &cobra.Command{
3131
Use: "metadata " + T("ARGUMENT"),
3232
Short: T("Find details about the machine making these API calls."),
33-
Long: T("ARGUMENT Choices: " + strings.Join(validOptions, ", ")),
33+
Long: T("ARGUMENT Choices: ") + strings.Join(validOptions, ", "),
3434
Args: cobra.MatchAll(metadata.OneArgs, cobra.OnlyValidArgs),
3535
ValidArgs: validOptions,
3636
RunE: func(cmd *cobra.Command, args []string) error {

plugin/commands/user/edit_notifications.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (cmd *EditNotificationsCommand) Run(args []string) error {
6767

6868
allNotifications, err := cmd.UserManager.GetAllNotifications("mask[id,name]")
6969
if err != nil {
70-
return slErr.NewAPIError(T("Failed to update notifications: "+printNotifications(notificationsInput)+"\n"), err.Error(), 2)
70+
return slErr.NewAPIError(T("Failed to update notifications: ") + printNotifications(notificationsInput), err.Error(), 2)
7171
}
7272

7373
if len(cmd.Disable) != 0 {
@@ -91,11 +91,12 @@ func (cmd *EditNotificationsCommand) Run(args []string) error {
9191

9292
if len(succesNotifications) > 0 {
9393
cmd.UI.Ok()
94-
cmd.UI.Print(T("Notifications updated successfully: " + printNotifications(succesNotifications)))
94+
cmd.UI.Print(T("Notifications updated successfully: ") + printNotifications(succesNotifications))
9595
}
9696

9797
if len(failedNotifications) > 0 {
98-
cmd.UI.Print(T("Notifications updated unsuccessfully: " + printNotifications(failedNotifications) + ". Review if already set or if the name is correct."))
98+
cmd.UI.Print(T("Notifications updated unsuccessfully: ") + printNotifications(failedNotifications))
99+
cmd.UI.Print(T("Review if already set or if the name is correct."))
99100
}
100101

101102
return nil

plugin/commands/user/vpn_manual.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,22 @@ func (cmd *VpnManualCommand) Run(args []string) error {
5555
}
5656

5757
vpnManualConfig := false
58-
action := "disable"
5958
if cmd.Enable {
6059
vpnManualConfig = true
61-
action = "enable"
6260
}
6361

6462
userTemplate := datatypes.User_Customer{
6563
VpnManualConfig: sl.Bool(vpnManualConfig),
6664
}
6765

68-
mapValue := map[string]interface{}{"action": T(action)}
6966

7067
success, err := cmd.UserManager.EditUser(userTemplate, userID)
7168
if err != nil {
72-
return errors.NewInvalidUsageError(T("Failed to {{.action}} user vpn subnets manual config", mapValue))
69+
return errors.NewInvalidUsageError(T("Failed to update user vpn subnets manual config"))
7370
}
7471
if success {
7572
cmd.UI.Ok()
76-
cmd.UI.Print(T("Successfully {{.action}} user vpn subnets manual config", mapValue))
73+
cmd.UI.Print(T("Successfully updated user vpn subnets manual config"))
7774
}
7875
return nil
7976
}

plugin/commands/virtual/notifications_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (cmd *NotificationsAddCommand) Run(args []string) error {
5656
UserCustomerNotification, err := cmd.VirtualServerManager.CreateUserCustomerNotification(virtualServerId, userId)
5757
if err != nil {
5858
userIdMap := map[string]interface{}{"userID": userId}
59-
cmd.UI.Failed(T("Failed to create User Customer Notification with user ID: {{.userID}}."+"\n"+err.Error(), userIdMap))
59+
cmd.UI.Failed(T("Failed to create User Customer Notification with user ID: {{.userID}}", userIdMap), err.Error(), 2)
6060
} else {
6161
printTable = true
6262
table.Add(

plugin/i18n/.DS_Store

6 KB
Binary file not shown.

plugin/i18n/i18n.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
"embed"
66
"strings"
77
"golang.org/x/text/language"
8-
"encoding/json"
8+
// "encoding/json"
99
"fmt"
1010
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/configuration/core_config"
1111
"github.com/Xuanwo/go-locale"
1212
goi18n "github.com/nicksnyder/go-i18n/v2/i18n"
1313
// "github.ibm.com/SoftLayer/softlayer-cli/plugin/resources"
1414
)
1515

16-
//go:embed resources/*.json
16+
//go:embed v2Resources/active.*.json
1717
var LocaleFS embed.FS
1818

1919
const (
@@ -33,7 +33,7 @@ var SUPPORTED_LOCALES = []string{
3333
"zh_Hant",
3434
}
3535

36-
var resourcePath = filepath.Join("plugin", "i18n", "resources")
36+
var resourcePath = filepath.Join("plugin", "i18n", "v2Resources")
3737
var localizer = Init()
3838

3939

@@ -95,10 +95,10 @@ func Init() *goi18n.Localizer {
9595
func InitWithLocale(locale string) *goi18n.Localizer {
9696

9797
bundle := goi18n.NewBundle(language.English)
98-
bundle.RegisterUnmarshalFunc("json", json.Unmarshal)
99-
bundle.LoadMessageFileFS(LocaleFS, "resources/en_US.json")
98+
// bundle.RegisterUnmarshalFunc("json", json.Unmarshal)
99+
bundle.LoadMessageFileFS(LocaleFS, "v2Resources/active.en_US.json")
100100
if locale != "en_US" {
101-
bundle.LoadMessageFileFS(LocaleFS, fmt.Sprintf("resources/%s.json", locale))
101+
bundle.LoadMessageFileFS(LocaleFS, fmt.Sprintf("v2Resources/active.%s.json", locale))
102102
}
103103
loc := goi18n.NewLocalizer(bundle, locale)
104104
return loc

0 commit comments

Comments
 (0)