Skip to content

Commit eff68e0

Browse files
committed
fixes and admin only variant
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent b99c315 commit eff68e0

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

api/src/main/java/org/apache/cloudstack/error/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,22 @@ matched on by API clients that care about the specific error condition.
102102

103103
`error-messages.json` is a server-side concern; the UI has a separate, independent localization
104104
path built on the same `errortextkey`. `ui/src/utils/plugins.js`'s `localeErrorUtilPlugin`
105-
(`$toLocaleError(msg, key, params)`) looks up `key` (the `errortextkey`) in the current locale's
106-
i18n bundle (`ui/public/locales/<locale>.json`, e.g. `hi.json`, `fr_FR.json`: flat key/value
107-
maps, same ones used for every other UI string). If a matching entry exists, it's used instead of
108-
the server-rendered `errortext`, with `{{placeholder}}` tokens substituted from `errormetadata`;
109-
otherwise it falls back to `errortext` unchanged. See `ui/src/utils/plugins.js:230` for the call
110-
site (`plugins.js:627` for the implementation).
105+
(`$toLocaleError(msg, key, params)`, called from both `$pollJob`'s async job failure handling and
106+
`$notifyError`) looks up `key` (the `errortextkey`) in the current locale's i18n bundle
107+
(`ui/public/locales/<locale>.json`, e.g. `hi.json`, `fr_FR.json`: flat key/value maps, same ones
108+
used for every other UI string). If a matching entry exists, it's used instead of the
109+
server-rendered `errortext`, with `{{placeholder}}` tokens substituted from `errormetadata`;
110+
otherwise it falls back to `errortext` unchanged.
111+
112+
**Admin variant**: like the server, before trying the base key, `$toLocaleError` first tries
113+
`<key>.admin` when the current user is a root admin (`roletype === 'Admin'`), falling back to the
114+
base key if no such entry exists. Only this root-admin case is special-cased, matching
115+
`error-messages.json`'s own `.admin`-suffix behavior; there's no equivalent variant for resource
116+
admins, domain admins, or regular users.
111117

112118
Practically: to ship a UI-side translation for a specific error, add a key equal to its
113-
`errortextkey` to the relevant locale file (e.g. `ui/public/locales/hi.json` for Hindi). No
114-
server-side change is needed.
119+
`errortextkey` (optionally suffixed `.admin` for a root-admin-specific variant) to the relevant
120+
locale file (e.g. `ui/public/locales/hi.json` for Hindi). No server-side change is needed.
115121

116122
## Global settings
117123

ui/src/utils/plugins.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const pollJobPlugin = {
138138
if (action && action.label) {
139139
errMessage = i18n.global.t(action.label)
140140
}
141-
var desc = result.jobresult.errortext
141+
var desc = this.$toLocaleError(result.jobresult.errortext, result.jobresult.errortextkey, result.jobresult.errormetadata)
142142
if (name) {
143143
desc = `(${name}) ${desc}`
144144
}
@@ -628,7 +628,17 @@ export const localeErrorUtilPlugin = {
628628
if (!key) {
629629
return msg
630630
}
631-
let localeMsg = i18n.global.t(key)
631+
let localeMsg
632+
if (!key.endsWith('.admin') && store.getters.userInfo?.roletype === 'Admin') {
633+
const adminKey = key + '.admin'
634+
const adminMsg = i18n.global.t(adminKey)
635+
if (adminMsg && adminMsg !== adminKey) {
636+
localeMsg = adminMsg
637+
}
638+
}
639+
if (!localeMsg) {
640+
localeMsg = i18n.global.t(key)
641+
}
632642
if (!localeMsg || localeMsg === key) {
633643
return msg
634644
}

0 commit comments

Comments
 (0)