Skip to content

Commit 53e902a

Browse files
Migrating to v2 go-i18n message format
1 parent bd2e304 commit 53e902a

33 files changed

Lines changed: 77676 additions & 491 deletions

bin/buildAndDeploy.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717

1818
i18n_files = [
19-
'en_US.all.json',
20-
'de_DE.all.json',
21-
'es_ES.all.json',
22-
'fr_FR.all.json',
23-
'it_IT.all.json',
24-
'ja_JP.all.json',
25-
'ko_KR.all.json',
26-
'pt_BR.all.json',
27-
'zh_Hans.all.json',
28-
'zh_Hant.all.json',
19+
'en_US.json',
20+
'de_DE.json',
21+
'es_ES.json',
22+
'fr_FR.json',
23+
'it_IT.json',
24+
'ja_JP.json',
25+
'ko_KR.json',
26+
'pt_BR.json',
27+
'zh_Hans.json',
28+
'zh_Hant.json',
2929
]
3030

3131
def isWindows() -> bool:

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.

0 commit comments

Comments
 (0)