Skip to content

Commit a5520e1

Browse files
authored
chore(i18n): combine cryostat-web i18n strings into plugin__cryostat-plugin namespace (#41)
1 parent 8492d0e commit a5520e1

10 files changed

+140
-95
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
.devcontainer/dev.env
1111
integration-tests/videos
1212
integration-tests/screenshots
13+
14+
locales/en/plugin__cryostat-plugin.json

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Additional parameters can be specified if desired. Consult the chart [values](ch
199199
Install the chart using the name of the plugin as the Helm release name into a new namespace or an existing namespace as specified by the `plugin_console-plugin-template` parameter and providing the location of the image within the `plugin.image` parameter by using the following command:
200200

201201
```shell
202-
helm upgrade -i my-plugin charts/openshift-console-plugin -n plugin__console-plugin-template --create-namespace --set plugin.image=my-plugin-image-location
202+
helm upgrade -i my-plugin charts/openshift-console-plugin -n plugin__cryostat-plugin --create-namespace --set plugin.image=my-plugin-image-location
203203
```
204204

205205
NOTE: When deploying on OpenShift 4.10, it is recommended to add the parameter `--set plugin.securityContext.enabled=false` which will omit configurations related to Pod Security.
@@ -211,19 +211,19 @@ NOTE: When defining i18n namespace, adhere `plugin__<name-of-the-plugin>` format
211211
The plugin template demonstrates how you can translate messages in with [react-i18next](https://react.i18next.com/). The i18n namespace must match
212212
the name of the `ConsolePlugin` resource with the `plugin__` prefix to avoid
213213
naming conflicts. For example, the plugin template uses the
214-
`plugin__console-plugin-template` namespace. You can use the `useTranslation` hook
214+
`plugin__cryostat-plugin` namespace. You can use the `useTranslation` hook
215215
with this namespace as follows:
216216

217217
```tsx
218218
conster Header: React.FC = () => {
219-
const { t } = useTranslation('plugin__console-plugin-template');
219+
const { t } = useTranslation('plugin__cryostat-plugin');
220220
return <h1>{t('Hello, World!')}</h1>;
221221
};
222222
```
223223

224224
For labels in `console-extensions.json`, you can use the format
225-
`%plugin__console-plugin-template~My Label%`. Console will replace the value with
226-
the message for the current language from the `plugin__console-plugin-template`
225+
`%plugin__cryostat-plugin~My Label%`. Console will replace the value with
226+
the message for the current language from the `plugin__cryostat-plugin`
227227
namespace. For example:
228228

229229
```json
@@ -232,7 +232,7 @@ namespace. For example:
232232
"properties": {
233233
"id": "admin-demo-section",
234234
"perspective": "admin",
235-
"name": "%plugin__console-plugin-template~Plugin Template%"
235+
"name": "%plugin__cryostat-plugin~Plugin Template%"
236236
}
237237
}
238238
```

console-extensions.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@
8585
"id": "cryostat-section",
8686
"insertAfter": "home",
8787
"perspective": "admin",
88-
"name": "%plugin__console-plugin-template~Cryostat%"
88+
"name": "%plugin__cryostat-plugin~Cryostat%"
8989
}
9090
},
9191
{
9292
"type": "console.navigation/href",
9393
"properties": {
9494
"id": "example",
95-
"name": "%plugin__console-plugin-template~Plugin Example%",
95+
"name": "%plugin__cryostat-plugin~Navigation.Plugin_Example%",
9696
"href": "/cryostat/example",
9797
"perspective": "admin",
9898
"section": "cryostat-section"
@@ -103,14 +103,14 @@
103103
"properties": {
104104
"id": "pf-separator",
105105
"section": "cryostat-section",
106-
"insertAfter": "%plugin__console-plugin-template~Plugin Example%"
106+
"insertAfter": "%plugin__cryostat-plugin~Navigation.Plugin_Example%"
107107
}
108108
},
109109
{
110110
"type": "console.navigation/href",
111111
"properties": {
112112
"id": "about",
113-
"name": "%plugin__console-plugin-template~About%",
113+
"name": "%plugin__cryostat-plugin~Navigation.About%",
114114
"href": "/cryostat/about",
115115
"perspective": "admin",
116116
"section": "cryostat-section"
@@ -120,7 +120,7 @@
120120
"type": "console.navigation/href",
121121
"properties": {
122122
"id": "settings",
123-
"name": "%plugin__console-plugin-template~Settings%",
123+
"name": "%plugin__cryostat-plugin~Navigation.Settings%",
124124
"href": "/cryostat/settings",
125125
"perspective": "admin",
126126
"section": "cryostat-section"
@@ -130,7 +130,7 @@
130130
"type": "console.navigation/href",
131131
"properties": {
132132
"id": "dashboard",
133-
"name": "%plugin__console-plugin-template~Dashboard%",
133+
"name": "%plugin__cryostat-plugin~Navigation.Dashboard%",
134134
"href": "/cryostat/dashboard",
135135
"perspective": "admin",
136136
"section": "cryostat-section"
@@ -140,7 +140,7 @@
140140
"type": "console.navigation/href",
141141
"properties": {
142142
"id": "topology",
143-
"name": "%plugin__console-plugin-template~Topology%",
143+
"name": "%plugin__cryostat-plugin~Navigation.Topology%",
144144
"href": "/cryostat/topology",
145145
"perspective": "admin",
146146
"section": "cryostat-section"
@@ -158,7 +158,7 @@
158158
"type": "console.navigation/href",
159159
"properties": {
160160
"id": "rules",
161-
"name": "%plugin__console-plugin-template~Automated Rules%",
161+
"name": "%plugin__cryostat-plugin~Navigation.Automated_Rules%",
162162
"href": "/cryostat/rules",
163163
"perspective": "admin",
164164
"section": "cryostat-section"
@@ -168,7 +168,7 @@
168168
"type": "console.navigation/href",
169169
"properties": {
170170
"id": "recordings",
171-
"name": "%plugin__console-plugin-template~Recordings%",
171+
"name": "%plugin__cryostat-plugin~Navigation.Recordings%",
172172
"href": "/cryostat/recordings",
173173
"perspective": "admin",
174174
"section": "cryostat-section"
@@ -178,7 +178,7 @@
178178
"type": "console.navigation/href",
179179
"properties": {
180180
"id": "archives",
181-
"name": "%plugin__console-plugin-template~Archives%",
181+
"name": "%plugin__cryostat-plugin~Navigation.Archives%",
182182
"href": "/cryostat/archives",
183183
"perspective": "admin",
184184
"section": "cryostat-section"
@@ -188,7 +188,7 @@
188188
"type": "console.navigation/href",
189189
"properties": {
190190
"id": "events",
191-
"name": "%plugin__console-plugin-template~Events%",
191+
"name": "%plugin__cryostat-plugin~Navigation.Events%",
192192
"href": "/cryostat/events",
193193
"perspective": "admin",
194194
"section": "cryostat-section"
@@ -198,7 +198,7 @@
198198
"type": "console.navigation/href",
199199
"properties": {
200200
"id": "security",
201-
"name": "%plugin__console-plugin-template~Security%",
201+
"name": "%plugin__cryostat-plugin~Navigation.Security%",
202202
"href": "/cryostat/security",
203203
"perspective": "admin",
204204
"section": "cryostat-section"

locales/en/plugin__console-plugin-template.json renamed to locales/en/common.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@
88
"Plugin Example": "Plugin Example",
99
"Success!": "Success!",
1010
"This is a custom page contributed by the console plugin template. The extension that adds the page is declared in console-extensions.json in the project root along with the corresponding nav item. Update console-extensions.json to change or add extensions. Code references in console-extensions.json must have a corresponding property": "This is a custom page contributed by the console plugin template. The extension that adds the page is declared in console-extensions.json in the project root along with the corresponding nav item. Update console-extensions.json to change or add extensions. Code references in console-extensions.json must have a corresponding property",
11-
"Your plugin is working.": "Your plugin is working."
11+
"Your plugin is working.": "Your plugin is working.",
12+
"Navigation.Plugin_Example": "Plugin Example",
13+
"Navigation.About": "About",
14+
"Navigation.Settings": "Settings",
15+
"Navigation.Dashboard": "Dashboard",
16+
"Navigation.Topology": "Topology",
17+
"Navigation.Automated_Rules": "Automated Rules",
18+
"Navigation.Recordings": "Recordings",
19+
"Navigation.Archives": "Archives",
20+
"Navigation.Events": "Events",
21+
"Navigation.Security": "Security"
1222
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "console-plugin-template",
2+
"name": "cryostat-openshift-console-plugin",
33
"version": "0.0.1",
44
"description": "Template project for OpenShift Console plugins",
55
"private": true,
66
"license": "Apache-2.0",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/openshift/console-plugin-template.git"
9+
"url": "https://github.com/cryostatio/cryostat-openshift-console-plugin.git"
1010
},
1111
"scripts": {
1212
"clean": "rm -rf dist",
@@ -53,6 +53,7 @@
5353
"eslint-plugin-cypress": "^2.12.1",
5454
"eslint-plugin-prettier": "^4.0.0",
5555
"eslint-plugin-react": "^7.37.3",
56+
"flat": "5.0.2",
5657
"humanize-duration": "^3.32.1",
5758
"i18next-browser-languagedetector": "^8.0.0",
5859
"i18next-parser": "^3.11.0",

src/cryostat-web

Submodule cryostat-web updated 114 files

src/openshift/pages/ExamplePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ALL_NS = '#ALL_NS#';
3030
const LOCALSTORAGE_KEY = 'cryostat-plugin';
3131

3232
export default function ExamplePage() {
33-
const { t } = useTranslation('plugin__console-plugin-template');
33+
const { t } = useTranslation('plugin__cryostat-plugin');
3434
const services = React.useContext(ServiceContext);
3535
const [subs] = React.useState([] as Subscription[]);
3636

start-console.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
CONSOLE_IMAGE=${CONSOLE_IMAGE:="quay.io/openshift/origin-console:latest"}
5+
CONSOLE_IMAGE=${CONSOLE_IMAGE:="quay.io/openshift/origin-console:4.17"} # temp(OCPBUGS-45523): 4.18+ repeats CSP violation toasts in dev mode
66
CONSOLE_PORT=${CONSOLE_PORT:=9000}
77
CONSOLE_IMAGE_PLATFORM=${CONSOLE_IMAGE_PLATFORM:="linux/amd64"}
88

webpack.config.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { EnvironmentPlugin } from 'webpack';
66
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
77
import { ConsoleRemotePlugin } from '@openshift-console/dynamic-plugin-sdk-webpack';
88
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
9-
10-
const CopyWebpackPlugin = require('copy-webpack-plugin');
9+
import { flatten } from 'flat';
10+
import CopyWebpackPlugin from 'copy-webpack-plugin';
11+
import fs from 'fs';
1112

1213
const isProd = process.env.NODE_ENV === 'production';
1314

@@ -88,6 +89,7 @@ const config: Configuration = {
8889
new EnvironmentPlugin({
8990
CRYOSTAT_AUTHORITY: 'http://localhost:8181',
9091
PREVIEW: process.env.PREVIEW || 'false',
92+
I18N_NAMESPACE: 'plugin__cryostat-plugin',
9193
}),
9294
new CopyWebpackPlugin({
9395
patterns: [{ from: path.resolve(__dirname, 'locales'), to: 'locales' }],
@@ -100,4 +102,33 @@ const config: Configuration = {
100102
},
101103
};
102104

105+
// Given a list of paths to locale files, combine them into /en/plugin__cryostat-plugin.json
106+
// TODO: accommodate multiple languages when supported by cryostat-web
107+
function combineLocaleFiles(files: string[]) {
108+
let combined = {};
109+
files.forEach((file) => {
110+
try {
111+
const json = JSON.parse(fs.readFileSync(file).toString());
112+
combined = { ...combined, ...json };
113+
} catch {
114+
console.error(`Could not find locale file: ${file}`);
115+
}
116+
});
117+
combined = flatten(combined);
118+
try {
119+
fs.writeFileSync(
120+
'./locales/en/plugin__cryostat-plugin.json',
121+
JSON.stringify(combined, null, 2),
122+
);
123+
} catch (e) {
124+
console.error('Could not write plugin__cryostat-plugin.json', e);
125+
}
126+
}
127+
128+
combineLocaleFiles([
129+
'./locales/en/common.json',
130+
'./src/cryostat-web/locales/en/common.json',
131+
'./src/cryostat-web/locales/en/public.json',
132+
]);
133+
103134
export default config;

0 commit comments

Comments
 (0)